Is it possible with OpenMP, when a function, lower in stack, ignites multiprocessing, then OpenMP facilites ignore multiprocessing requests from functions' bodies, higher in stack?
Is this the way OpenMP always works? If not, can I do this? How?
void do1()
{
#pragma omp parallel for
for (unsigned int i = 0; i < 10; ++i);
}
void do2()
{
#pragma omp parallel for
for (unsigned int i = 0; i < 10; ++i) do1();
}
void do3()
{
#pragma omp parallel for
for (unsigned int i = 0; i < 10; ++i) do2();
}
int main()
{
do1(); // runs in parallel
do2(); // do2() runs in parallel, do1() I want not
do3(); // do3() runs in parallel, do1() and do2() I want not
}
OpenMP works exactly as you described, if nested parallelism is disabled. On current OpenMP implementations it is disabled by default, but it is not specified by the standard, so to be on the safe side it is worth disabling it by setting OMP_MAX_ACTIVE_LEVELS
environmental variable to 1 or by using omp_set_max_active_levels(1);
function in your code.