Number of threads of Intel MKL functions inside OMP parallel regions

白昼怎懂夜的黑 提交于 2021-02-05 08:07:22

问题


I have a multithreaded code in C, using OpenMP and Intel MKL functions. I have the following code:

    omp_set_num_threads(nth);
#pragma omp parallel for private(l,s) schedule(static)
for(l=0;l<lines;l++)
{
    for(s=0;s<samples;s++)
    {
        out[l*samples+s]=mkl_ddot(&bands, &hi[s*bands+l], &inc_one, &hi_[s*bands+l], &inc_one);
    }
}//fin for l

I want to use all the cores of the multicore processor (the value of nth) in this pramga. But I want that each core computes a single mkl_ddot function independently (1 thread per mkl_ddot function).

I want to know how many threads are used by the mkl_ddot function in this case. I read in some forums, that by default mkl functions inside a pragma parallel run using only 1 cores (thats what i want). But I am not sure about this behaviour and I can not find the specific section in the manual explaining this situation.

Thanks in advance.


回答1:


That's correct - by default MKL runs with a single thread if it detects that it is being called from inside a parallel region. I have explained the way to change this behaviour in this answer. You can simply invert the boolean parameters there to make sure that MKL would only use a single thread.

Yet, if you only want MKL functions to run single-threadedly, e.g. you only use it from inside parallel regions, you'd better link with the sequential MKL driver instead. With Intel's compiler this is easy - just specify -mkl=sequential. For other compilers you should look into the library's manual for how to link your program against the sequential driver.




回答2:


The Intel MKL Library uses OPENMP threading software for multithreading. The number of threads created will be based on the enviornment variable "OMP_NUM_THREADS". The default value for OMP_NUM_THREADS depends on the Intel MKL version and OPENMP libraries.

But in your case, you are doing a nested parallelism. But by default the nested parallelism is turn off. Hence the number of threads used by mkl_ddot function will be ONE (which means no parallelism at mkl_ddot function level).

You can enable the nested parallelism by invoking omp_set_nested(1). By this way, in your case, the nested parallelism will be enabled and more than one thread will be used by mkl_ddot function.



来源:https://stackoverflow.com/questions/21560544/number-of-threads-of-intel-mkl-functions-inside-omp-parallel-regions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!