OpenMP Review

This lab is a final OpenMP review before your midterms. It will help if you have the text available for this lab.

  1. Suppose OpenMP did not have the reduction clause. Show how to implement an efficient parallel reduction by adding a private variable and using the critical pragma. Use the following code segment.
    double area, pi, x;
    int i,n;
    area = 0.0;
    for (i = 0; i < n; i++) {
        x = (i + 0.5) / n;
        area += 4.0 / (1.0 + x * x);
    }
    pi = area / n;
    
  2. Give an example of a parallel for loop that would probably execute in less time if it were dynamically scheduled rather than statically scheduled.
  3. Use OpenMP directives to parallelize the Sieve of Eratosthenes.
On campus students should e-mail the answers to Kaustubh.