#include #include #include int main (int argc, char *argv[]) { double h; double estimate; double sum = 0,sum2; double x; int i, n; int nthreads, tid; int procs; n = atoi(argv[1]); h = 1.0 / ( double ) ( 2 * n ); printf("h = %lf n = %d\n",h,n); /* Set the number of threads to the number of processors */ procs = omp_get_num_procs(); omp_set_num_threads(procs); /* Create a team of threads giving them their own copies of variables */ #pragma omp parallel private ( i, x, sum2 ) { sum2 = 0.0; #pragma omp for for ( i = 1; i <= n; i++ ) { x = h * ( double ) ( 2 * i - 1 ); sum2 = sum2 + 1.0 / ( 1.0 + x * x ); } printf("sum2 is %lf\n", sum2); sum +=sum2; } printf("total sum is %lf\n", sum); return (0); }