title: Measure execution time in C++ OpenMP code
body: <p>I am running a .cpp code (i) in sequential style and (ii) using OpenMP statements. I am trying to see the time difference. For calculating time, I use this:</p>
  
  <pre><code>#include &lt;time.h&gt;
  .....
  main()
  {
  
    clock_t start, finish;
    start = clock();
    .
    .
    .
    finish = clock();
  
    processing time = (double(finish-start)/CLOCKS_PER_SEC);
  
   }
  </code></pre>
  
  <p>The time is pretty accurate in sequential (above) run of the code. It takes about 8 seconds to run this. When I insert OpenMP statements in the code and thereafter calculate the time I get a reduction in time, but the time displayed is about 8-9 seconds on the console, when actually its just 3-4 seconds in real time!</p>
  
  <p>Here is how my code looks abstractly:</p>
  
  <pre><code>#include &lt;time.h&gt;
  .....
  main()
  {
  
    clock_t start, finish;
    start = clock();
    .
    .
    #pragma omp parallel for
    for( ... )
       for( ... )
         for (...)
      {           
        ...;      
      }
    .
    .
    finish = clock();
  
    processing time = (double(finish-start)/CLOCKS_PER_SEC);
  
   }
  </code></pre>
  
  <p>When I run the above code, I get the reduction in time but the time displayed is not accurate in terms of real time. It seems to me as though the clock () function is calculating each thread's individual time and adding up them up and displaying them.</p>
  
  <p>Can someone tell the reason for this or suggest me any other timing function to use to measure the time in OpenMP programs?</p>
  
  <p>Thanks.</p>