Is it possible to selectively enable an openmp directive with template parameter or run time variable?
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) { /*...*/ }
}
Update (Testing if clause)
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";
}
}
}
Error message (g++ 6, compiled with 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. I will try to look up if the if clause can work with the for clause. thanks.if’ is not valid for ‘#pragma omp for’