OpenMp根据变量设置并行循环的线程数 [英] OpenMp set number of threads for parallel loop depending on variable
问题描述
有没有一种方法可以基于变量的值在OpenMP并行区域中设置线程数?最初,整个应用程序的线程数= nofCores.在我的AMD FX 8350上,nofCores = 8.对于此区域,如果变量为3,那么我只需要3个线程.如果variable> cores,则线程数应保持等于nofCores.
Is there a way to set number of threads in OpenMP parallel for region based on the value of a variable? Initially for the whole application number of threads = nofCores. On my AMD FX 8350, nofCores =8. For this area if the variable is 3 then I only need 3 threads. If variable>cores then number of threads should remain equal to nofCores.
我不想为所有应用程序全局设置线程数.仅用于此特定的并行循环.
I do not want to set the number of threads globally for all the application. Just for this specific parallel loop.
很抱歉,如果这是一个幼稚的问题,但我是OpenMP的新手.
Sorry if this is a naive question, but I am a newbie in OpenMP.
推荐答案
当然..只需将其添加到您的parallel for
指令即可:
Sure .. just tack this on to your parallel for
directive:
#pragma parallel for num_threads(variable)
for( ... )
这篇关于OpenMp根据变量设置并行循环的线程数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!