#include <stdio.h>
#include <stdlib.h>
#include <math.h>

#pragma goose func
double integrand(double x)
{
  double s;
  s = 4.0/(1.0+x*x);
  return s;
}

int
main(int argc, char **argv)
{
  int i, n;
  double x, dx, sum = 0.0;

  if(argc >= 2){
    n = atoi(argv[1]);
  }else{
    n = 16384;
  }
  dx = 1.0/n;

#pragma omp parallel for private(x)
#pragma goose parallel for icnt(i) result(sum) ip(i) shared_ro(dx)
  for(i=0;i<n;i++) {
      x = (i+0.5)*dx;
    sum += integrand(x)*dx;        
  }
  printf("n:%d  sum:%.14e  sum/M_PI-1.0:%e\n",
         n, sum, sum/M_PI-1.0);
  exit(0);
}
