Maximum number of nested levels

jimdempseyatthecove
Total Points: 13284
Status Points: 13284
Black Belt
September 3, 2008 9:08 AM PDT
Rate
 
#4 Reply to #3

Mambru37,

If you do not specify the number of threads for the parallel sections then the parallel sections begins with the default number of available threads. Each section within the parallel sections in turn will run on one of the threads, in your case one thread from the set of threads for the sections will run for each of two sections. Any additional threads will wait at the end parallel sections (assuming you do not use NOWAIT).

Pseudo code for you to consider

...
int NumberOfPackages = YourGetNumberOfPackages();
void* PackageMask[] = {NULL, NULL};
bool FirstTime[] = {TRUE, TRUE};
void DoWork0(void)
{
  if(FirstTime[0])
  {
    #omp parallel
    {
       YourSetAffinity(PackageMask[0]);
    }
    FirstTime[0] = FALSE;
  }
  ...
}
// DoWork1 similar to above

main(...)
{
  ...
  PackageMask[0] = YourGetAffinityMaskForPackage(0);
  if(NumberOfPackages > 1)
  {
    PackageMask[1] = YourGetAffinityMaskForPackage(1);
  } else {
    PackageMask[1] = PackageMask[0];
  }
  #pragma omp parallel num_threads(2)
  {
    int ThreadNum = omp_get_thread_num();
    while(ProcessMainLoop)
    {
       if(FirstTime[ThreadNum])
       {
         SetAffinity(PackageMask[ThreadNum]);
       }
       DoMainIterationPreamble(ThreadNum); // e.g. read data
       #pragma omp barrier
       if(ThreadNum == 0)
       {
         DoWork0();
       } else {
         DoWork1();
       }
       #pragma omp barrier
    }
  }
}

 

  Jim Dempsey

Forum Statistics

4474 users have contributed to 24001 threads and 69861 posts to date.
In the past 24 hours, we have 42 new thread(s) 152 new posts(s), and 197 new user(s).

In the past 3 days, the most popular thread for everyone has been Catastrophic error The most posts were made to Getting Started in the Partner Program The post with the most views is You can report them here if

Please welcome our newest member Udaysimha Mysore (Intel)