Problem linking MKL with pthread and gomp

Problem linking MKL with pthread and gomp

A minimal test program:

#include "mkl_lapacke.h"

int main(int argc, char** argv)
{
   float a = 0.5f;
   LAPACKE_slasrt('I', 1, &a);

   return 0;
}

I used the "Library Link Line Advisor" to get the linker command line, but it still fails:

$ g++ -Wall -o test.exe test.cpp -lmkl_intel_lp64 -lmkl_core -lmkl_sequential -ldl -lpthread -lm
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_core.so: undefined reference to `pthread_mutex_trylock'
collect2: error: ld returned 1 exit status

$ g++ -Wall -o test.exe test.cpp -lmkl_intel_lp64 -lmkl_core -lmkl_gnu_thread -ldl -lpthread -lm -lgomp
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_critical_end'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `omp_get_thread_num'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_sections_end_nowait'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `omp_get_num_threads'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `omp_get_num_procs'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_ordered_start'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_atomic_end'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_sections_start'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_core.so: undefined reference to `pthread_mutex_trylock'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_critical_name_end'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_parallel_start'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_single_start'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `omp_get_nested'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `omp_in_parallel'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_loop_end'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `omp_get_max_threads'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_loop_end_nowait'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `omp_set_nested'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_loop_ordered_static_start'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_loop_ordered_dynamic_next'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_critical_start'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_critical_name_start'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_ordered_end'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_loop_ordered_dynamic_start'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_parallel_end'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_sections_next'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_atomic_start'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_barrier'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_parallel_sections_start'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_loop_dynamic_next'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_loop_ordered_static_next'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_gnu_thread.so: undefined reference to `GOMP_loop_dynamic_start'
collect2: error: ld returned 1 exit status

$ g++ -o test.exe test.cpp -lmkl_intel_lp64 -lmkl_core -lmkl_intel_thread -ldl -lpthread -lm -liomp5
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_ok_to_fork'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_end_single'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_ordered'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_init_8'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `omp_get_thread_num'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_barrier'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `omp_get_num_threads'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `omp_get_num_procs'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_next_4'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_end_reduce_nowait'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_critical'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_fini_8'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_cmplx8_add'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_float4_add'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_serialized_parallel'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_end_critical'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_init_8'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `ompc_set_nested'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_init_8u'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_core.so: undefined reference to `pthread_mutex_trylock'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `omp_get_nested'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_float8_max'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `omp_in_parallel'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_push_num_threads'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_reduce_nowait'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `omp_get_max_threads'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_init_4'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_end_serialized_parallel'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_flush'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_single'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_next_8'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_float8_add'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_float4_max'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_end_master'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_dispatch_init_4'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_global_thread_num'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_end_ordered'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_fork_call'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_fixed8_add'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_for_static_fini'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_master'
/opt/intel/composer_xe_2013_sp1.1.106/mkl/lib/intel64/libmkl_intel_thread.so: undefined reference to `__kmpc_atomic_cmplx4_add'
collect2: error: ld returned 1 exit status

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.8/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.8.1-10ubuntu9' --with-bugurl=file:///usr/share/doc/gcc-4.8/README.Bugs --enable-languages=c,c++,java,go,d,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.8 --enable-shared --enable-linker-build-id --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.8 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --with-system-zlib --disable-browser-plugin --enable-java-awt=gtk --enable-gtk-cairo --with-java-home=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64/jre --enable-java-home --with-jvm-root-dir=/usr/lib/jvm/java-1.5.0-gcj-4.8-amd64 --with-jvm-jar-dir=/usr/lib/jvm-exports/java-1.5.0-gcj-4.8-amd64 --with-arch-directory=amd64 --with-ecj-jar=/usr/share/java/eclipse-ecj.jar --enable-objc-gc --enable-multiarch --disable-werror --with-arch-32=i686 --with-abi=m64 --with-multilib-list=m32,m64,mx32 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.8.1 (Ubuntu/Linaro 4.8.1-10ubuntu9)

Any advice on how to do this is appreciated.

 

4 posts / 0 nouveau(x)
Dernière contribution
Reportez-vous à notre Notice d'optimisation pour plus d'informations sur les choix et l'optimisation des performances dans les produits logiciels Intel.

I couldn't reproduce your problem. I'm using GCC 4.8.1.

Please check if these env-variables are set properly: INCLUDE, CPATH, LIBRARY_PATH.

Also, since you've got Intel Compsoer XE 2013 SP1, you can try to build the code using Intel compiler (icc). If it builds fine then it must be a problem with your GCC.

 

You might add -v to your g++ command to get more insight about library paths in use, and check that the OpenMP libraries are present on those paths.  One would expect to need a -L specification for the directory including libiomp5.o when using g++ (as Zhang indicated, that should not be required with icpc).  I think it would be better to place -lpthread after -liomp5 or -lgomp, and g++ should not require -lm.

If your libgomp installation is too far off from whatever libmkl_gnu_thread expects, I suppose that could pose a problem.

Hello Per,

It looks similiar problem as the one in http://software.intel.com/en-us/articles/symbol-lookup-error-when-linking-intel-mkl-with-gcc-on-ubuntu.  Some ubuntu and GCC have the issue, some have not.

You may try to add the compiler option : -Wl,--no-as-needed.   for example

g++ -Wall -o test.exe test.cpp -Wl,--no-as-needed -lmkl_intel_lp64 -lmkl_sequential -lmkl_core -ldl -lpthread -lm

Best Regards,

Ying

Laisser un commentaire

Veuillez ouvrir une session pour ajouter un commentaire. Pas encore membre ? Rejoignez-nous dès aujourd’hui