Worksharing and Parallel Loops
Worksharing and Parallel Loops
Worksharing and Parallel Loops
Implicit barrier 4
OpenMP loop worksharing construct
Basic approach:
• Find compute intensive loops (use a profiler!)
• Make the loop iterations independent .. So they can safely
execute in any order without loop-carried dependencies
• Place the appropriate OpenMP directive and test
int i, A[MAX]; Where is
int i, j, A[MAX]; int
j =i,5;A[MAX]; the bug?
j = 5; #pragma omp parallel for
for (i=0;i< MAX; i++) { for (i=0;i< MAX; i++) {
j +=2; int j = 5 + 2*(i+1);
j +=2;
A[i] = big(j); A[i] = big(j);
} }
OpenMP collapse clause
Try running STREAM with one thread per available core and
schedule:
• Static
• Dynamic
• Guided
• How do they perform?
Sections worksharing construct