/* L-6 MCS 572 Mon 23 Jan 2012 : sprng_estpi_mpi.c
 * The program uses SPRNG in a simple Monte Carlo
 * simulation to estimate Pi. */

#include <stdio.h>
#include <math.h>
#define SIMPLE_SPRNG
#include "sprng.h"
#define PI 3.14159265358979

int main(void)
{
   printf("basic estimation of Pi with SPRNG...\n");
   int seed = make_sprng_seed();  
   init_sprng(0,seed,SPRNG_DEFAULT); 

   printf("Give the number of samples : ");
   int n; scanf("%d",&n);

   int i,cnt=0;
   for(i=0; i<n; i++)
   {
      double x = sprng();
      double y = sprng();
      double z = x*x + y*y;
      if(z <= 1.0) cnt++;
   }
   double estimate = (4.0*cnt)/n;
   printf("estimate for Pi : %.15f",estimate);
   printf("  error : %.3e\n",fabs(estimate-PI));

   return 0;
}

