/* Compute integral from 0 to 1 4/(1+x*x). This shoudl be equal to PI. Parallel version using a parallel for construct. Note that we have critical race to the global sum, which we need to protect Scalability: good. */ #include #include #include #define NUM_THREADS 2 int main(int argc, char** argv) { long num_steps = 10000000; double t1, t2; double step = 1/(double)num_steps; double global_sum = 0; t1 = omp_get_wtime(); int i; omp_set_num_threads(NUM_THREADS); #pragma omp parallel { //private variables to each thread double x, sum = 0; int thread_id = omp_get_thread_num(); printf("Start(%d)\n", thread_id); #pragma omp for for (i=0; i