Pergunta

I have a code that reads like this

void h(particles *p) {    
    #pragma omp parallel for
    for (int i = 0; i < maxThreads; ++i) {
       int id = omp_get_thread_num();
       for (int j = 0; j < dtnum; ++j) {
           f( p, id);
           if ( j % 50 == 0 ) {
               if (id == 0) {
                   g(p);
               }
               #pragma omp barrier
           }
        }
    }
}
void f(particles *p, int id) {
   for (int i = id * prt_thread; i < (id + 1)*prt_thread; ++i) {
       x(p[i]);
   }
}

Basically I want to: 1)spawn a given amount of threads. each thread will process a chuck of p according to thread's id 2)each element of p must be processed dtnum times. The processing involve random events 3)every 50 iterations, one thread must perform another operation, while the other threads wait

Problem: gcc says warning: barrier region may not be closely nested inside of work-sharing, critical, ordered, master or explicit task region

what can I do?

Foi útil?

Solução

It's hard to tell from the very schematic code, but if all you want to do is sync up every so many iterations, it seems easiest to pull the iteration loop out of the parallel omp for loop - which seems clearer anyway - and just do

const int iterblocks=50;

#pragma omp parallel shared(p, dtnum) default(none)
for (int jblock=0; jblock<dtnum/iterblocks; jblock++) {
    for (int j=0; j<iterblocks; j++) {
       #pragma omp for nowait
       for (int i=0; i<prt; i++)
           x(p[i]);
    }
    #pragma omp barrier
    #pragma omp single
     g(p);
    #pragma omp barrier
}

Outras dicas

I think your code is wrong. You said :

each element of p must be processed dtnum times.

But each element of p will be execute maxThreads*dtnum times.

Could you be more explicit on what your code's supposed to do ?

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top