/* OpenMP example program that computes the value of Pi using the trapeziod rule. Compile with gcc -fopenmp -O3 omp_pi.c -o omp_pi */ // Online source: http://users.abo.fi/mats/PP2012/examples/OpenMP/omp_pi.c // Modified pi.c to add an orphan #include #include #include #include #include #ifdef _CIVL $input int N=100; #else #define N 1000 #endif double starttime, d, x, sum = 0.0; int nthreads; int n=N; void print_usage(char *s) { printf("Usage: %s -i \n", s); exit(0); } /* This is the function to integrate */ double f(double x) { return (4.0 / (1.0 + x*x)); } float piOrphan(){ /* The master thread checks how many there are */ int i; #pragma omp master { nthreads = omp_get_num_threads(); printf("Number of threads = %d\n", nthreads); starttime = omp_get_wtime(); /* Measure the execution time */ } /* This loop is executed in parallel by the threads */ #pragma omp for reduction(+:sum) for (i=0; i