title: calculating Pi with Monte Carlo Simulation Multithreaded
body: <p>So, I'm currently working on a Monte Carlo Simulation in order to calculate Pi. I have currently 5 different scenarios: 500, 20000, 100000, 1000000, 10000000 points to calculate Pi, my problem is that I have to multithread the algorithm ( 2, 4, 6 and 8 threads for each number of points ) but I've been searching about multithreading and couldn't understand what do I have to do in order to achieve my goal.
  Hoping someone could explain me or show me how to actually do the multithreading bit of the algorithm.</p>
  
  <p>Code looks something like this:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;math.h&gt;
  
  
  int main () 
  {
  
   int circ, total, i;
   double a, x, y, pi;
  
   a = 0;
   i = 0;
  
   total = 500;
   circ = 0;
   for ( i = 0; i&lt;total; i++ ) {
    x = (double)rand ()/ RAND_MAX;
    y = (double)rand ()/ RAND_MAX;
    a = x*x + y*y
    if (a&lt;=1) circ ++;
    }
   pi = (double)circ/total * 4;
   printf ("For %d points, pi is %g \n", total, pi);
  
   total = 20000;
   circ = 0;
   for ( i = 0; i&lt;total; i++ ) {
    x = (double)rand ()/ RAND_MAX;
    y = (double)rand ()/ RAND_MAX;
    a = x*x + y*y
    if (a&lt;=1) circ ++;
    }
   pi = (double)circ/total * 4;
   printf ("For %d points, pi is %g \n", total, pi);
  
  
   total = 100000;
   circ = 0;
   for ( i = 0; i&lt;total; i++ ) {
    x = (double)rand ()/ RAND_MAX;
    y = (double)rand ()/ RAND_MAX;
    a = x*x + y*y
    if (a&lt;=1) circ ++;
    }
   pi = (double)circ/total * 4;
   printf ("For %d points, pi is %g \n", total, pi);
  
  
   total = 1000000;
   circ = 0;
   for ( i = 0; i&lt;total; i++ ) {
    x = (double)rand ()/ RAND_MAX;
    y = (double)rand ()/ RAND_MAX;
    a = x*x + y*y
    if (a&lt;=1) circ ++;
    }
   pi = (double)circ/total * 4;
   printf ("For %d points, pi is %g \n", total, pi);
  
   total = 10000000;
   circ = 0;
   for ( i = 0; i&lt;total; i++ ) {
    x = (double)rand ()/ RAND_MAX;
    y = (double)rand ()/ RAND_MAX;
    a = x*x + y*y
    if (a&lt;=1) circ ++;
    }
   pi = (double)circ/total * 4;
   printf ("For %d points, pi is %g \n", total, pi);
  </code></pre>
  
  <p>Thank you very much for your patience and have a good day :)</p>