Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

the OpenMP "master" pragma must not be enclosed by the "parallel for" pragma

Why won't the intel compiler let me specify that some actions in an openmp parallel for block should be executed by the master thread only?

And how can I do what I'm trying to achieve without this kind of functionality?

What I'm trying to do is update a progress bar through a callback in a 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...
}

I want only the master thread to call the callback, because if I don't enforce that (say by using omp critical instead to ensure only one thread uses the callback at once) I get the following runtime exception:

The application called an interface that was marshalled for a different thread.

...hence the desire to keep all callbacks in the master thread.

Thanks in advance.

like image 728
Sideshow Bob Avatar asked Oct 05 '11 12:10

Sideshow Bob


1 Answers

#include <omp.h>
void f(){}
int main()
{
#pragma omp parallel for schedule (guided)
    for (int i = 0; i < 100; ++i)
    {
        #pragma omp master
        f();
    }
    return 0;
}

Compiler Error C3034 OpenMP 'master' directive cannot be directly nested within 'parallel for' directive Visual Studio 2010 OpenMP 2.0

May be so:

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 it is error
    //#pragma omp critical it is right
    if (omp_get_thread_num() == 0) // may be good
        set_progressor_callback(num_items_computed);

    //actual computation goes here
    ...blah...
}
like image 82
Artyom Smirnoff Avatar answered Nov 04 '22 19:11

Artyom Smirnoff