Agrim Pathak Agrim Pathak - 1 year ago 168
C++ Question

Linking Ipopt with Intel MKL

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

Answer Source

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

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

source /opt/intel/parallel_studio_xe_2016.<##>.<###>/ 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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download