Basic linking to BLAS95

Basic linking to BLAS95

Hi forum,
I am sorry for posting a lame question but I am just starting to use Fortran. I translated some of my programs from MATLAB and I want to see what the improvement in speed will be. So far using ifort -O3 I can get them to run about 5 times faster and now I want to use BLAS to see if there will be further improvement.
Unfortunately, I haven't yet figured out how to link with BLAS95 correctly. I have built the BLAS95 routines with ifort and have the mkl95_blas.mod and mkl95_precision.mod in the standard dir ../lib/emt64t.
Suppose I want to run the simpliest program using just gemm:

program myprog

use mkl95_precision
use mkl95_blas

implicit none
real(8), dimension(2,2) ::a,b,c

!/ matrices defined here
call gemm(a,b,c)

end program myprog

Could you please tell me which options (-L, -I paths, libraries) should I invoke with ifort to get it working (I only want BLAS95 for a start). Because I am lost as I always get the error:
/tmp/ifortbs5xfm.o: In function `MAIN__':
myprog.f90:(.text+0x204): undefined reference to `dgemm_mkl95_'

Hope somebody will help me get started

6 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi Tomasz and all others

I seem to have the same background and be in the same situation as Tomasz, and I only saw his post after I had completed my own, which I allow myself to post in this thread.

I have tried long and hard to link my own Fortran 95 program with the BLAS and LAPACK implementations of the Intel MKL, but without success.

This is an excerpt from my program:
program main

use mkl95_blas
use mkl95_lapack

implicit none


test1 = (/ (i*1.d0,i=1,10) /)
test2 = 0

call copy(test1,test2)

end program main

When I compile I get the following error:

/home/tjoff/programming/fortran/workspace/Liftlin/src/Main.f90:120: undefined reference to `dcopy_mkl95_'
make: *** [all] Error 1

Excerpt from my Makefile:

MKLPATH = /opt/intel/mkl/
MKLINCLUDE = /opt/intel/mkl/
ifort -o a.out main.f90

where i have tried various values for $(LINKFLAGS), e.g.

-Wl,--start-group $(MKLPATH)/libmkl_intel_lp64.a
$(MKLPATH)/libmkl_intel_thread.a $(MKLPATH)/libmkl_core.a -Wl,--end-group
-lguide -lpthread

which according to the Users guide should be "static linking of user code myprog.f, Fortran 90 LAPACK interface1, and parallel Intel
MKL supporting LP64 interface", which i suppose is what I want.
I have tried both static and dynamic linking as given in the Users guide, but it all results in the above error.

I have checked the following:

- ifort runs perfectly

- in my .bashrc file I have the line
source /opt/intel/mkl/
and the environment variables all seem right to me

- The instructions in the User Guide section "Fortran 90 Interfaces and Wrappers to LAPACK and BLAS" have been followed, and the directory /opt/intel/mkl/ contains
the files mkl95_blas.mod, mkl95_lapack.mod and mkl95_precision.mod as well as some .f77, f.90 and .h files.
The directory /opt/intel/mkl/ also contains mkl95_blas.mod, mkl95_lapack.mod and mkl95_precision.mod as well as all the .a and .so files.

I will be very grateful for any hints

regards, Jakob

When you build the Fortran 95 wrapper files (for BLAS) you should get these three files


If you move the "*.mod" files to /opt/intel/mkl/include and the "*.a" file to /opt/intel/mkl/lib/32 then you simply use

ifort -I/opt/intel/mkl/include my_example.f90 -L/opt/intel/mkl/lib/32 -lmkl_blas95 -lmkl -lguide -lpthread

Btw Matlab (specially under windoze) also seems to use MKL underneath so you may not see large speedups wrt to blas/lapack calls. See

Thanks a lot tabrezali! I tried your advice, and now both BLAS and LAPACK are working for me:

ifort -o a.out main.f90 -I/opt/intel/mkl/ -L/opt/intel/mkl/ -lmkl_blas95 -lmkl_lapack95 -lmkl -lguide -lpthread

It seems that I was missing before was the -lmkl option.
Again, thanks for answering, it was really helpful.

Best regards, Jakob

Are you sure your lapack95 calls are working correctly because I think it is more like "-lmkl_lapack95 -lmkl_lapack ...".

Basically the 95 stuff just gets added before what you need otherwise. Playing around or refering the docs will get you there.

Thanks a lot, works beautifully now! It looks like the Intel Fortran Compiler matrix multiplication is quite good on its own, as I don't see that much improvement from using MKL. But on the whole the program runs significantly faster then in MATLAB (much faster for loops, similar for matrix multiplications).

Leave a Comment

Please sign in to add a comment. Not a member? Join today