Will fortran 'matmul' use MKL if I include the library?

I am writing some code right now and I have a placeholder with matmul which seems to work very well, but I would like to use the LAPACK dgemm implementation. I'm using gfortran right now and getting very good speeds with matmul , but I wonder if I can get better.

Current call:

 C = transpose(matmul( transpose(A), B)) 

where A , B and C are non-square double precision matrices. I can easily write a wrapper for dgemm with the current dgemm LAPACK implementation, but I like that I can do it all as a function (instead of worrying about call for a frock coat and dealing with transpose ).

I am wondering if I compile with ifort and enable MKL , will this matmul change to MKL dgemm for me without a shell?

+7
fortran intel lapack
source share
1 answer

You do not want all MATMUL to be dgemm, this is not beneficial for very small matrices.

Gfortran does what you want

-fexternal-Blas This option causes gfortran to generate calls to BLAS functions for some matrix operations, such as MATMUL, instead of using its own algorithms if the size of the involved matrices is greater than the specified limit (see -fblas-matmul-limit). This can be beneficial if an optimized BLAS library is available for suppliers. The BLAS library will have to indicate the connection time.

and you can even change the size limit for switching to BLAS with -fblas-matmul-limit = n

You can easily use MKL this way in gfortran.

Intel Fortran has something similar

[no -] opt-matmul This option allows [disables] the compiler - generated Matrix Multiply (matmul) library call by identifying the matrix multiplier sockets, if any, and replacing them with matmul libraries require increased performance. This option is enabled by default if the parameters / O 3 (- O3) and / Qparallel (- in parallel). This option has no effect if the option / O 2 (- O2) or higher.

+9
source share

All Articles