本文介绍了OMP 并行区域内英特尔 MKL 函数的线程数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 C 中有一个多线程代码,使用 OpenMP 和英特尔 MKL 函数.我有以下代码:

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

我想在这个 pramga 中使用多核处理器的所有内核(nth 的值).但我希望每个核心独立计算一个 mkl_ddot 函数(每个 mkl_ddot 函数 1 个线程).

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).

我想知道在这种情况下 mkl_ddot 函数使用了多少线程.我在一些论坛上读到,默认情况下,mkl 函数在 pragma 并行运行中仅使用 1 个内核(这就是我想要的).但我不确定这种行为,我无法在手册中找到解释这种情况的特定部分.

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.

提前致谢.

推荐答案

这是正确的 - 默认情况下,如果 MKL 检测到正在从并行区域内部调用它,则它使用单个线程运行.我已经在这个答案中解释了改变这种行为的方法.您可以简单地反转布尔参数以确保 MKL 只使用单个线程.

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.

但是,如果您只希望 MKL 函数以单线程方式运行,例如您只能从并行区域内部使用它,最好与顺序 MKL 驱动程序链接.使用英特尔的编译器,这很容易 - 只需指定 -mkl=sequential.对于其他编译器,您应该查看库手册,了解如何将您的程序链接到顺序驱动程序.

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.

这篇关于OMP 并行区域内英特尔 MKL 函数的线程数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-06 18:25