爲什麼intel編譯器不能讓我指定只應由主線程執行openmp parallel for
塊中的某些動作?OpenMP「master」編譯指令不能被「parallel for」編譯指令包含
如果沒有這種功能,我該怎麼做?
我試圖做的是更新通過回調的進度條在平行於:
long num_items_computed = 0;
#pragma omp parallel for schedule (guided)
for (...a range of items...)
{
//update item count
#pragma omp atomic
num_items_computed++;
//update progress bar with number of items computed
//master thread only due to com marshalling
#pragma omp master
set_progressor_callback(num_items_computed);
//actual computation goes here
...blah...
}
我想只有主線程調用回調,因爲如果我不強制執行(比如通過使用omp critical
代替,以保證只有一個線程使用回調一次)我得到以下運行時異常:
The application called an interface that was marshalled for a different thread.
...因此,讓所有的回調在主線程的願望。
在此先感謝。
這似乎是工作,謝謝。我擔心主線程可能與所有工作線程不同......因此回調將永遠不會執行......在omp規範中是可以想象的嗎? –
如果迭代次數很大,則不會注意到差異。並且在循環之後添加:if(omp_get_thread_num()== 0)set_progressor_callback(num_items_computed); –
from standart OpenMP about pragma omp parallel for():「循環結構指定一個或多個關聯循環的迭代將由團隊中的線程在其隱式任務的上下文中並行執行。迭代分佈在執行循環區域綁定的並行區域的團隊中已存在的線程上。「 –