开发者

Which openMP pragma do I use for a blocking for loop?

开发者 https://www.devze.com 2023-03-27 21:18 出处:网络
My algorithm (solving Poisson\'s equation) is completely parallelizable--provided that all the threads sync at the end of each iteration.

My algorithm (solving Poisson's equation) is completely parallelizable--provided that all the threads sync at the end of each iteration.

Function f, fNext;
init(f);
#pragma omp parallel
for(int step=0; step<maxITER; step++) {
#pragma omp for
   for(int i=0; i<N; i++) {
      for(int j=0; j<N; j++) {
         fNext(i,j) = someOperator( f(i,j) );
      }
   }
   f = fNext;
}//Threads must synchronize here

Does #pragma omp for ensu开发者_如何学运维re thread synchronization before continuing to the next iteration?


Yes. From the OpenMP Spec (eg, v 3.1, but this has been in since the beginning), under "worksharing constructs:"

There is an implicit barrier at the end of a loop construct unless a nowait clause is specified.

That is, at the end of the for loop, unless you do something like #pragma omp for nowait, there is an implied barrier so that no thread will execute f=fNext until all threads are done the for loop.

0

精彩评论

暂无评论...
验证码 换一张
取 消