Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

linking with intel's lapack

prayerz
Beginner
342 Views
Hi,

pls how do i link my program (called solve.f) with intel's lapack. i already tried but i get errors:

ifort -g -o solve solve.o -L/usr/local/intel101/mkl/lib/em64t/ -lmkl_lapack -lmkl_em64t -lguide
/usr/local/intel101/mkl/lib/em64t//libmkl_lapack.so: undefined reference to `mkl_serv_load_fun'
/usr/local/intel101/mkl/lib/em64t//libguide.so: undefined reference to `pthread_atfork'
/usr/local/intel101/mkl/lib/em64t//libmkl_lapack.so: undefined reference to `mkl_serv_load_dll'
make: *** [solve] Error 1

what am i doing wrong? the code is sequential.

thanks for any help.

o.
0 Kudos
3 Replies
TimP
Honored Contributor III
342 Views
One problem is that you are linking the static library mkl_em64t which redefines symbols already contained in the dynamic libraries specified (since MKL 10.0) in mkl_lapack. The docs warn against combinations of static and dynamic libraries. Another is that you haven't specified -lpthread. When linking, the ifort options -openmp or -parallel will take care of both -lguide and -lpthread. There's no harm in setting -openmp to get the OpenMP libraries, even at compile time, even when you have no use of OpenMP in your code, if that's what you mean by sequential.
If you want the mkl_sequential library, don't use the combination "library" mkl_lapack or libguide, instead use for example -lmkl_intel_lp64 -lmkl_core -lmkl_sequential. If there is a missing reference to pthread_atfork, add -lpthread.
0 Kudos
prayerz
Beginner
342 Views
Thank you so much, Tim. You're a genius!
your advice works like magic!

i had to include /usr/local/intel101/mkl/lib/em64t/ in my LD_LIBRARY_PATH so that the dynamic libraries could be found at runtime.
is there a way to compile the code using only static libraries. when i tried to add "-static", it complained that it could not find "-lm" (apparently i don't have a static math library?)

o.
0 Kudos
TimP
Honored Contributor III
342 Views
Static linking is a little more complicated, hence recommendations against it in the docs. Ifort has the option, formerly spelled -i-static, in current versions spelled -static-intel, to use only static libraries the from ifort installation, while continuing to use dynamic libraries from linux. -static would attempt to link all static libraries from ifort and linux, but could run into trouble with MKL, until you have set up the static MKL link.
This forum has several past posts on static MKL link, in addition to the examples in the MKL docs. It's a bit annoying, as it doesn't work with -L, and requires the --begin-group .... -end-group loader directives, or equivalent.
The main reason for static link would be to enable the executable to run where ifort and MKL aren't installed, without carrying along the necessary .so files. It also has some advantages when profiling for performance, in those cases where you have performance problems outside MKL.
The next major release of ifort and icc should include MKL library path setting in the scripts like ifortvars.sh, so should ease the problem of getting all the paths right for your MKL installation. For now, there should be mklvars scripts in the tools/environment/ directory of your MKL installation, in case you prefer those to setting LD_LIBRARY_PATH directly.
0 Kudos
Reply