0

I want to compile this C code with MKL, but when I run it using the command mpicc -mkl mkl_thread.c, it gives me an error about an unrecognized command line option -mkl. When I run it as mpicc mkl_thread.c -o mkl_thread, it gives a different error, saying "undefined reference to `MKL_Set_Num_Threads'". I don't know how I can run it with or link with MKL.

My code is:

define NUM_PROCS 5 

int main (int argc, char ** argv)

{

    int threads_per_proc[NUM_PROCS] = { 1,2 ,3, 4,5 };
    int rank;
    MPI_Init(&argc, &argv);
    MPI_Comm_rank(MPI_COMM_WORLD, &rank);
    // ...
    // Signal an error if rank >= 5
    // ...
    mkl_set_num_threads(threads_per_proc[rank]);
    MPI_Finalize();
}
hopper
  • 13,060
  • 7
  • 49
  • 53
Gevni
  • 43
  • 2
  • 10

1 Answers1

1

-mkl is an Intel specific option which can not be recognized by mpicc.

For non-Intel compiler, you could specify the link options explicitly.

$ mpicc mkl_thread.c -o mkl_thread \
        -I$(MKLROOT)/include -L$(MKLROOT)/lib/intel64 \
        -lmkl_intel_lp64 -lmkl_intel_thread -lmkl_core \
        -liomp5 -lpthread -lm

Please refer to Intel® Math Kernel Library Link Line Advisor for other link options.

kangshiyin
  • 9,681
  • 1
  • 17
  • 29
  • mpicc mkl_thread.c -o mkl_thread -Wl,--start-group $MKLROOT/lib/intel64/libmkl_intel_lp64.a $MKLROOT/lib/intel64/libmkl_intel_thread.a $MKLROOT/lib/intel64/libmkl_core.a -Wl,--end-group -lpthread -lm. I use this command and get some errors that i don't understand./home/tmalik/intel/mkl/lib/intel64/libmkl_intel_thread.a(mkl_threading.o): In function `mkl_serv_mkl_get_max_threads': ../../../../serv/kernel/mkl_threading.c:(.text+0x57): undefined reference to `omp_in_parallel'. – Gevni Jan 28 '13 at 15:51
  • 1
    You could link either Intel OpenMP lib by `-liomp5` or GNU OpenMP lib by `-fopenmp`, which is required by MKL – kangshiyin Jan 28 '13 at 16:22
  • Thank you sooooooooo much. When i used -liomp5 it give error not find -liomp5. But with -fopenmp it works. Thank again – Gevni Jan 28 '13 at 16:36