rjhogan / Adept-2

Combined array and automatic differentiation library in C++
http://www.met.reading.ac.uk/clouds/adept/
Apache License 2.0
164 stars 29 forks source link

Adept with Intel MKL Blas/Lapack #26

Open Leersmaekers opened 1 year ago

Leersmaekers commented 1 year ago

Is there a way to link Adept with Intel MKL Blas and Lapack? I'm now using ./configure from msys64 on a Windows PC.

I now got the following lines at the and of ./configure:

configure: ***** Libraries used by Adept ** configure: BLAS (Basic Linear Algebra Subprograms) will not be used: MATRIX MULTIPLICATION IS UNAVAILABLE configure: LAPACK (Linear Algebra Package) will not be used: LINEAR ALGEBRA ROUTINES ARE UNAVAILABLE

Thanks in advance, Laurent

rjhogan commented 1 year ago

I don't compile things on windows myself so I'm not precisely sure. Following the info here: https://hpc.ncsu.edu/Software/Libraries.php?app=MKL, if you are using the Intel compiler you could try this:

./configure "LDFLAGS=-mkl"

If you are using the GNU compiler then you probably need this:

./configure "LDFLAGS=-lmkl_gf_lp64 -lmkl_core -lmkl_gnu_thread"

but this will assume that the MKL libraries are in the default location for DLLs. If they're somewhere else you'd need to specify the location maybe with a "-L" at the beginning of the LDFLAGS list.

If you're using the Microsoft compiler then the format of the compiler options is different and I don't know the syntax. But hopefully you can work it out. Robin.

Leersmaekers commented 1 year ago

I don't compile things on windows myself so I'm not precisely sure. Following the info here: https://hpc.ncsu.edu/Software/Libraries.php?app=MKL, if you are using the Intel compiler you could try this:

./configure "LDFLAGS=-mkl"

If you are using the GNU compiler then you probably need this:

./configure "LDFLAGS=-lmkl_gf_lp64 -lmkl_core -lmkl_gnu_thread"

but this will assume that the MKL libraries are in the default location for DLLs. If they're somewhere else you'd need to specify the location maybe with a "-L" at the beginning of the LDFLAGS list.

If you're using the Microsoft compiler then the format of the compiler options is different and I don't know the syntax. But hopefully you can work it out. Robin.

I have tried ./configure LDFLAGS="-mkl", with the same result I described above.

According to the Intel link advisor, I need the following line: ./configure LDFLAGS="-L${MKLROOT}/lib/intel64 -lmkl_intel_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl"

This unfortunately also leads to the same result.

Are the following lines suggesting the MKL library is not found, or is it just stating it can't find sgemm?

checking for sgemm_ in -lmkl_intel_lp64... no
checking for sgemm_ in -lmkl... no
rjhogan commented 1 year ago

I think that means that it finds the library but not sgemm. Can you look in ${MKLROOT}/lib/intel64 and see if there is a dll with "bias" in the name? Then add the appropriate -l argument.

Leersmaekers commented 1 year ago

There is indeed a lib file containing blas: mkl_blas95_ilp64.lib. Adding this file doesn't change the final outcome. The total call now is:

./configure LDFLAGS="-L${MKLROOT}/lib/intel64 -lmkl_intel_ilp64 -lmkl_blas95_ilp64 -lmkl_sequential -lmkl_core -lpthread -lm -ldl"

rjhogan commented 1 year ago

I'm afraid I don' know then. You might find some clues looking in the config.log file after ./configure is run.

Leersmaekers commented 1 year ago

I've read in a document that using "#include adept_source.h" is easier on e.g. Windows. I've followed this approach and ran the test_no_lib.cpp file without any issues. Now I'm wondering if there are any limitations using adept this way. The reasoning behind my concern is the fact it didn't need to link to blas and lapack.

rjhogan commented 1 year ago

This is a separate thing - it just makes compilation a bit easier. Both compilation methods can be used with or without blas and lapack. Do you need to be able to do matrix multiplication or solving systems of linear equations? If not, you don't need blas or lapack.