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

Linking Fortran with MKL

da-james
Novice
1,418 Views

Hello,

I have some fortran code that has a pure function making calls to the lapack library (in particular, zgetrf and zgetrs), but then I was getting the following error:

Any procedure referenced in a PURE procedure, including one referenced via a defined operation or assignment, must have an explicit interface and be declared PURE. [ZGETRF]
call zgetrf(N, N, Mat, N, ipiv, info)

This led me to search and discover that MKL has an interface for lapack and/or it's own definitions of the library (I'm still confused on what it actually does have after reading through the documentation)

Anyway, I've trying a couple things: first I tried this tool to use mkl which led me to have

ifort -mkl

LIBS += -L${MKLROOT}/lib -Wl,-rpath,${MKLROOT}/lib -lmkl_rt -lpthread -lm -ldl

This compiled fine and I made an external call DGESV more or less following this example .

However, when I was going back to trying the functions I need to use, I was getting the same error.

 

Then I tried following the documentation here  (page 57 in particular, relating to the Fortran 95 Interface). Which I followed the steps of making the interface and removed the previous flags above and added the following flags:

MKLROOT = ~/Documents/projects/mkl-lapack
LIBS += -I${MKLROOT}/include/intel64/lp64 -L${MKLROOT}/lib -libmkl_lapack95_lp64

Once again it compiled fine, but then I got the same error as stated above.

At this point, I think I'm getting lost in the documentation and after reading this post, one of the comments does describe that mkl is it's own math library.

So my question is how do I properly link to the routines ZGETRF and ZGETRS such that it can work within a pure function either from lapack or mkl.

Any help is appreciated, thank you!

0 Kudos
6 Replies
mecej4
Honored Contributor III
1,394 Views

You probably did not include a "USE LAPACK95" statement in the source file of your pure procedure/function from which calls are made to ZGETRF/ZGETRS. The lapack95.mod file is generated from the source file lapack.f90 in the MKL include directory, and contains PURE attributes in the interfaces of those routines for which that attribute is applicable.

If, instead, you used the include file mkl_lapack.fi, that would not work since that file is intended for use with Fortran-77, and the PURE attribute was not available in that version of Fortran.

0 Kudos
da-james
Novice
1,386 Views

So after adding the "use lapack95" to my file I got an error of "library not loaded : @rpath/libmkl_intel_lp64.dylib" which then looking into my lib directory I noticed the files are for .a files. Forgot to mention that I'm working on a Mac OSX machine.

I tried seeing if there was a "make dylibintel64 ..." option for making the lapack interface which doesn't seem to work or be in the documentation. I also tried adding a -dynamiclib flag into the makefile of the mkl lapack interface, but that just produced errors. Is there a way to properly compile the libraries so make can access them?

0 Kudos
mecej4
Honored Contributor III
1,378 Views

The last Mac that I had ran OS7.6, so I have zero experience with those aspects of OSX that differ from their Linux/Unix counterparts.

For several years now, MKL has come with the BLAS95 and Lapack libraries pre-built for use with Intel compilers, so you should not need to build *95* MKL libraries yourself. Simply follow the MKL Link Line Advisor for your setup, and link using the command line that it provides.

If, for some reason, you do build those libraries, you should not corrupt the makefile with incorrect alterations. For instance, the linker flag -llibxyz would initiate a search for a library file with the name liblibxyz.a

I think that you did make some progress, in that you are now seeing linker errors instead of compilation errors. 

0 Kudos
RahulV_intel
Moderator
1,340 Views

Hi,


Could you please share your minimal reproducible code sample?

Also, kindly specify your macOS version and oneAPI/parallel studio version.


Thanks,

Rahul


0 Kudos
RahulV_intel
Moderator
1,322 Views

Hi,


Just a quick reminder to share the above details.


Thanks,

Rahul


0 Kudos
RahulV_intel
Moderator
1,312 Views

I have not heard back from you. So, I will close this thread. Feel free to post a new question if you require further assistance from Intel.


Thanks,

Rahul


0 Kudos
Reply