title: Timing my c code
body: <p>I have written a code in C for finding the volume between two parabloids. Although the code takes about 7 seconds to run when I check it on my clock, using the inbuilt clock function gives me only 2.6 seconds. </p>
  
  <p>I have run the same code using openmp after parallelizing it and it takes 7 seconds there. Can someone please point out the flaw in my timing?</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;math.h&gt;
  #include &lt;time.h&gt;
  
  int main ()
  {
      int i, j, k;
      double xmin = 0;
      double xmax = 0.707;
      long Nx = 10000, Ny, n;
      double dx = (xmax - xmin)/(Nx-1);
      double x[Nx];
      double Nelemy[Nx];
      double y, z1, z2;
      double vol1[Nx], vol2[Nx];
      double sum1 = 0, sum2 = 0;
      double start, end, elapsedTime;
  
      start = clock();
  
      // Fill in the array containing values at x nodes and number of elements at in y at each node of x
      for (i=0; i&lt;Nx; i++)
      {
          x[i] = 0;
          x[i] = i*dx;
          y = sqrt(1 - 2*x[i]*x[i]);
          n = y/dx;
          Ny = ceil(n) + 1;
          Nelemy[i] = 0;
          Nelemy[i] = Ny;
      }
  
      // Calculate area for each cell
      double dA = dx*dx;
  
      // Calculate the value of z for each cell
      for (i=0; i&lt;Nx; i++)
      {
          vol1[i] = 0;
          vol2[i] = 0;
          Ny = Nelemy[i];
          double Y[Ny];
          for (k=0; k&lt;Ny; k++)
          {
              Y[k] = 0;
              Y[k] = k*dx;
          }
  
          for (j=0; j&lt;Ny; j++)
          {
              z1 = 5 * ( x[i] * x[i] + Y[j] * Y[j]);
              z2 = 6 - 7 *  x[i] * x[i] - Y[j] * Y[j];
              // Calculate the partial volume
              vol1[i] = vol1[i] + dA * z1;
              vol2[i] = vol2[i] + dA * z2;
          }
      }
  
      // print the contents of vol
      for (i=0; i&lt;Nx; i++)
      {
          sum1 += vol1[i];
          sum2 += vol2[i];
      }
      end = clock();
      elapsedTime = (double)(end - start) / CLOCKS_PER_SEC;
  
      printf("The enclosed Volume is: %lf\n", (sum2 - sum1));
      printf("The total time taken is: %lf\n", elapsedTime);
  
      return 0;
  }
  </code></pre>