Hello! I am trying to mix mkl and TBB in my project, therefore I am trying to make MKL dynamically switch on/off as I wish. I use the mkl_set_num_threads() to set the number of threads, when I want the multi-threading mode off, I set it to one before I call the real working function, else if I want to use the multi-threading mode I set mkl_set_num_threads before the working function is called. The code (take BLAS2 as an example) is like this:
// set omp to run
if (withOMP) {
omp_init(); // set it to maximum number of threads we can find with mkl_set_num_threads()
}else{
omp_turnoff(); // set the number of threads to 1
}
#ifdef WITH_SINGLE_PRECISION
sgemv(&symA, &row_A, &col_A, &alpha, A, &ld_A, x, &inc_x, &beta, y, &inc_y);
#else
dgemv(&symA, &row_A, &col_A, &alpha, A, &ld_A, x, &inc_x, &beta, y, &inc_y);
#endif
however, in my BLAS and LAPACK testing I find if the openmp is turned off, then it can never been switched on again. The running with MKL will always be in serial mode no matter the calls of omp_init(). the multi-threading mode could be observed only if omp_turnoff() is not called.
I am useing MKL 11.1 version of multi-threading library(intel64) together with g++(version 4.7.2, also 64 bit). My library linking is
-L$(MKLROOT)/lib/intel64 -lmkl_intel_lp64 -lmkl_core -lmkl_intel_thread -liomp5 -ldl -lpthread -lm
Thanks very much!
fenglai