OpenMP streams "disobey" omp barrier

So here is the code:

#pragma omp parallel private (myId)
{
  set_affinity();

  myId = omp_get_thread_num(); 

  if (myId<myConstant)
  {
    #pragma omp for schedule(static,1)
    for(count = 0; count < AnotherConstant; count++)
      {
        //Do stuff, everything runs as it should
      }
  }

#pragma omp barrier //all threads wait as they should
#pragma omp single
 {
    //everything in here is executed by one thread as it should be
 }
   #pragma omp barrier //this is the barrier in which threads run ahead
   par_time(cc_time_tot, phi_time_tot, psi_time_tot);
   #pragma omp barrier
}
//do more stuff

Now, to explain what is happening. At the beginning of my parallel area, myId is set to private, so each thread has its own correct thread id. set_affinity () controls which thread runs on which kernel. The problem I have includes #pragma omp for schedule (static, 1).

block:

  if (myId<myConstant)
  {
    #pragma omp for schedule(static,1)
    for(count = 0; count < AnotherConstant; count++)
      {
        //Do stuff, everything runs as it should
      }
  }

This is some work that I want to distribute over a certain number of threads, 0 through myConstant-1. In these threads, I want to evenly (according to how the schedule does it (static, 1)) distribute the loop iterations. All this is done correctly.

, , . , myConstant 2. , 3 , , id 3 .

, , . id 3 ( myConstant ) , par_time(), , , . par_time() .

pragma omp (static, 1) , for ( if statement if (myId == 0)), . , .

, - , . , , - OMP.

+3
1

OpenMP V3.0, 2.5 " Worksharing Constructs", :

:

  • , , .
  • .

if, , . OpenMP "" .

, for, "static, 1", - count = 0 - 0. (count = 1) 1 .., . , , 0 . OpenMP, 2.5.1 Loop construct, , .

+6

Source: https://habr.com/ru/post/1787228/


All Articles