/* Compute integral from 0 to 1 4/(1+x*x). This should be equal to PI. First attempt at parallelization, which does not work for a couple of reasons: 1. each thread is computing the whole thing in parallel. 2. there are a number of shared variable that cause race conditions and the result is wrong. [ltoma@lobster /Volumes/CS/ltoma/public_html/teaching/cs3225-GIS/fall16/Code/OpenMP]$gcc-6 -fopenmp pi1.c [ltoma@lobster /Volumes/CS/ltoma/public_html/teaching/cs3225-GIS/fall16/Code/OpenMP]$./a.out Start(2) Start(3) Start(4) Start(0) Start(1) Start(6) Start(5) Start(7) Done(6): pi = 3.040 Done(3): pi = 3.035 Done(2): pi = 3.040 Done(4): pi = 3.040 Done(0): pi = 3.035 Done(7): pi = 3.035 Done(1): pi = 3.035 Done(5): pi = 3.035 Done. time = 1.0 Lauras-MacBook-Pro:OpenMP ltoma$ ./a.out Start(4) Start(2) Start(6) Start(5) Start(1) Start(3) Start(0) Start(7) Done(6): pi = 3.161 Done(4): pi = 3.161 Done(1): pi = 3.161 Done(5): pi = 3.161 Done(7): pi = 3.161 Done(2): pi = 3.161 Done(0): pi = 3.161 Done(3): pi = 3.161 Done. time = 1.1 */ #include #include #include int main(int argc, char** argv) { long num_steps = 10000000; double step, x, pi, sum =0; int i; double t1, t2; step = 1/(double)num_steps; t1 = omp_get_wtime(); #pragma omp parallel { int thread_id = omp_get_thread_num(); printf("Start(%d)\n", thread_id); for (i=0; i