-->

Linking Ipopt with Intel MKL

2019-07-29 19:17发布

问题:

I'm trying to link Ipopt with Intel MKL (instructions).

Intel's Link Advisor suggests:

Link line:

 -Wl,--start-group ${MKLROOT}/lib/intel64/libmkl_intel_ilp64.a ${MKLROOT}/lib/intel64/libmkl_core.a ${MKLROOT}/lib/intel64/libmkl_intel_thread.a -Wl,--end-group -lpthread -lm -ldl

Compiler options:

 -DMKL_ILP64 -qopenmp -I${MKLROOT}/include

I try to configure Ipopt with:

../configure CXX=icpc CC=icc F77=ifort --with-blas=" -Wl,--start-group ${MKLROOT}/lib/intel64/libmkl_intel_ilp64.a ${MKLROOT}/lib/intel64/libmkl_core.a ${MKLROOT}/lib/intel64/libmkl_intel_thread.a -Wl,--end-group -lpthread -lm -ldl" CXXFLAGS=" -DMKL_ILP64 -qopenmp -I${MKLROOT}/include"

This eventually fails indicating:

checking whether user supplied BLASLIB=[text above]  does not work

回答1:

First you need to make sure that MKL is correctly installed and configured as shown here.

https://software.intel.com/en-us/get-started-with-parallel-studio-xe-for-linux

A permanent way is to put the following line in your .bashrc or .profile

source /opt/intel/parallel_studio_xe_2016.<##>.<###>/psxevars.sh intel64

You could use the following cmdline to check if MKL is ready. It should display the valid MKL installation dir.

$ echo $MKLROOT

If you are using MKL link line advisor, why don't you follow the instruction precisely? I noticed you miss the OpenMP lib -liomp5 in link option, and the whole compile option.

I can build Ipopt with single dynamic MKL by

$ mkdir build
$ cd build
$ ../configure --with-blas=' -Wl,--no-as-needed -L${MKLROOT}/lib/intel64  -lmkl_rt -lpthread -lm -ldl' CFLAGS=' -m64 -I${MKLROOT}/include' CXXFLAGS=' -m64 -I${MKLROOT}/include'

and with dynamic MKL by

$ mkdir build
$ cd build
$ ../configure --with-blas='-Wl,--no-as-needed -L${MKLROOT}/lib/intel64 -lmkl_intel_lp64 -lmkl_core -lmkl_intel_thread -liomp5 -lpthread -lm -ldl' CFLAGS=' -m64 -I${MKLROOT}/include' CXXFLAGS=' -m64 -I${MKLROOT}/include'

But it does not work with static MKL.

The above settings only work with gcc compiler.


Dynamic MKL with icc compiler also works with the following setting.

$ mkdir build
$ cd build
$ ../configure --with-blas=' -L${MKLROOT}/lib/intel64 -lmkl_intel_ilp64 -lmkl_core -lmkl_intel_thread -lpthread -lm -ldl' CFLAGS=' -DMKL_ILP64 -qopenmp -I${MKLROOT}/include' CXXFLAGS=' -DMKL_ILP64 -qopenmp -I${MKLROOT}/include' CC=icc CXX=icpc


回答2:

Following up on @kangshiyin 's answer: I found that one needs the -liomp5 library and use the LP64 integer representation instead of ILP64. I also defined the Fortran compilers in F77 and FC. The configure command looked like:

../configure --prefix=${YOUR_PREFIX} \
--with-blas=' -L${MKLROOT}/lib/intel64 -lmkl_intel_lp64 -lmkl_core \
-lmkl_intel_thread -liomp5 -lpthread -lm -ldl' \
CC=icc CXX=icpc FC=ifort F77=ifort \
CFLAGS=' -DMKL_LP64 -qopenmp -I${MKLROOT}/include' \
CXXFLAGS='-std=c++11 -DMKL_LP64 -qopenmp -I${MKLROOT}/include' \
OPT_CCFLAGS="-Ofast" OPT_CXXFLAGS="-Ofast" OPT_FCFLAGS="-Ofast"

This worked on an Ubuntu 16.04.3 LTS installation, with the 2017.0.2 versions of the Intel compilers and the MKL. The Ipopt version was 3.12.7.

Update: I tried this also on MacOS "El Capitan" (OS X 10.11.6). Turns out that you have to add the following linker flags to your invocation of configure:

LDFLAGS="-Wl,-rpath,$MKLROOT/../compiler/lib -Wl,-rpath,$MKLROOT/lib"

otherwise the libiomp5.dylib library will not be found. This is apparently due to the changed security setup in "El Capitan", according to some posts on the Intel C++ compiler forum.



回答3:

Ipopt needs to link against an LP64 Blas and Lapack library, it uses 32 bit integer indices. The ILP64 version of MKL you tried to link against is built for 64 bit integer indices.