title: How to organize a correct output of parallel program?
body: <p>I have alike C++ program with openMP usage</p>
  
  <pre><code>#pragma omp parallel for private(i)
  for (j=0;j&lt;NUM_STEPS_J) {
  
      for (i=0;i&lt;NUM_STEPS_I;i++) {
  
          std::cout &lt;&lt; "Print some information about step i" &lt;&lt; std::endl;
  
  
      }
  
      std::cout &lt;&lt; "Check of item " &lt;&lt; j &lt;&lt; " finished" &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>What is the best way to provide a correct output in my case?</p>
  
  <p>I know, that using "printf" instead "cout" solves this problem. </p>
  
  <p>But when I changed "cout" to "printf" the time of my program's execution increased from about 80 seconds to about 120 seconds. 
  I think, it is a sufficient influence on program's productivity.</p>
  
  <p>What is the best way to solve this problem without "printf"? </p>
  
  <p>Is it possible to lock "cout" function during output in some way?</p>