0

I am running mkl_lab_solution.c which is an example for using MKL, I can compile it correctly, while I run it, I got Segmentation fault.My runtime is below:

  1. OS is centos 6.3
  2. gcc's version is 4.1.2
  3. mkl is mkl_10.3.12.361
  4. makefile is below

    gcc -g -L/opt/intel/composer_xe_2011_sp1.12.361/mkl/lib/intel64 -lmkl_intel_ilp64 -lmkl_intel_lp64 -lmkl_intel_sp2dp -lmkl_intel_thread -lmkl_core -lpthread -L/opt/intel/composer_xe_2011_sp1.12.361/compiler/lib/intel64 -liomp5 -L/usr/lib64 -lstdc++ -I/opt/intel/composer_xe_2011_sp1.12.361/mkl/include -o test mkl-lab-solution.c

Bort
  • 2,423
  • 14
  • 22
taoyuanjl
  • 145
  • 1
  • 14

1 Answers1

3

Since this works fine on my system, let me point you to possible errors. First, you need to run . /path/to/intel/compilervars.sh intel64 such all environment variables are set, like MKLROOT. Second, check on intel mkl link line advisor for the options on your system. So reading your compile command I guess: linux, gnu compiler, dynamic linked, 64 bit target architecture, 64 bit long pointer, multithreaded, intel omp library.

These settings give me:

linker options:

-L$(MKLROOT)/lib/intel64 -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread -lm

compile options:

-DMKL_ILP64 -m64 -I$(MKLROOT)/include

For whatever reason the brackets around MKLROOT don't work on bash, so just remove them. Next remember to put all compile options in front of linker options. The final command line should read like this:

gcc mkl-lab-solution.c -DMKL_ILP64 -m64 -I$MKLROOT/include -L$MKLROOT/lib/intel64 -lmkl_intel_ilp64 -lmkl_intel_thread -lmkl_core -liomp5 -lpthread -lm

Since you get runtime errors, I suspect that you are linking the Intel MKL libraries with objects compiled for different interface layers.

Bort
  • 2,423
  • 14
  • 22
  • thanks!It work upon your description.Another question is that I get linker options from [intel mkl link line advisor](http://software.intel.com/en-us/articles/intel-mkl-link-line-advisor) the details are "-Wl,--start-group $(MKLROOT)/lib/intel64/libmkl_intel_lp64.a $(MKLROOT)/lib/intel64/libmkl_intel_thread.a $(MKLROOT)/lib/intel64/libmkl_core.a $(MKLROOT)/lib/intel64/libmkl_blacs_openmpi_lp64.a -Wl,--end-group -liomp5 -lpthread -lm",I don't know the options named -Wl,--start-group, could you explain for me and could I miss them and not lost performance because I could not compile with nvcc – taoyuanjl May 16 '13 at 01:41
  • 1
    When you select static linking, you need to specify the necessary object files. This is done in `-Wl,--start-group object files -Wl,--end-group`. The advantage of static linking is that all used functions are compiled into your library/exectuable and don't need to be available in `LD_LIBRARY_PATH`. Your executable just get bigger. There is no difference in performance. You can miss them if you use shared linking but you have to make sure that all libraries are in your LD_LIBRARAY_PATH, run `/path/to/intel/compilervars.sh intel64` before executing your program. – Bort May 16 '13 at 09:24
  • 1
    I haven't tried nvcc with mkl yet. So unfortunately, I cannot comment on that. Technically, I think it should work. – Bort May 16 '13 at 09:26