是否可以選擇性地啓用帶有模板參數或運行時變量的openmp指令?在並行區域內選擇性啓用OpenMP for循環
this (all threads work on the same for loop).
#pragma omp parallel
{
#pragma omp for
for (int i = 0; i < 10; ++i) { /*...*/ }
}
versus this (each thread works on its own for loop)
#pragma omp parallel
{
for (int i = 0; i < 10; ++i) { /*...*/ }
}
更新(如果測試子句)
TEST.CPP:
#include <iostream>
#include <omp.h>
int main() {
bool var = true;
#pragma omp parallel
{
#pragma omp for if (var)
for (int i = 0; i < 4; ++i) {
std::cout << omp_get_thread_num() << "\n";
}
}
}
錯誤消息(G ++ 6,使用g ++ TEST.CPP -fopenmp編譯)
test.cpp: In function ‘int main()’:
test.cpp:8:25: error: ‘if’ is not valid for ‘#pragma omp for’
#pragma omp for if (var)
^~
'#pragma omp parallel if(variable)' –
這兩個版本都是並行的,大多數情況下我想選擇啓用'#pragma omp for line'。如果if子句可以和for子句一起工作,我會嘗試查找。謝謝。 –
它確實。 https://msdn.microsoft.com/en-us/library/5187hzke.aspx希望對所有編譯器都是如此。 –