Openmp sections

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

why is the following code not executed in parallel:

#include <iostream>
#include <omp.h>
 
int main()
{
 
#pragma omp sections nowait
{
  #pragma omp section
  {
    int i = 0;
    while (true) {
      ++i;
      if (i % 1000000 == 0) {
         std::cerr << "1. Thread: " << omp_get_thread_num() 
                   << "  i = " << i << std::endl;
      } 
    }
  }

  #pragma omp section
  {
    int i;
    while (true) {
      ++i;
      if (i % 1000000 == 0) {
        std::cerr << "2. Thread: " << omp_get_thread_num()
                  << "  i = " << i << std::endl;
      }
    }
  }
}

}

I know that the usage of std::cerr is not threadsafe. But this is only to see 
that only one thread is running. If I remove it, there still only one thread 
running.

I use g++ 4.3.0 and compile with:

g++ -fopenmp test.C -lgomp

./a.out prints only messages from 1. Thread.

Greetings
Christoph

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux