OpenMp set number of threads for parallel loop depending on variable

a 夏天 提交于 2019-12-10 14:43:48

问题


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.

Sorry if this is a naive question, but I am a newbie in OpenMP.


回答1:


Sure .. just tack this on to your parallel for directive:

#pragma parallel for num_threads(variable)
for( ... )


来源:https://stackoverflow.com/questions/19248169/openmp-set-number-of-threads-for-parallel-loop-depending-on-variable

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