Module 11: The “lastprivate” Clause
Lecture 21: Clause and Routines
Reduction
Example: Reduction
double ave = 0.0, A [ MAX ]; int i;
#pragma omp parallel for reduction (+ : ave)
for (i = 0; i < MAX; i++) {
ave + = A[i];
}
ave = ave/MAX;
Data Scope Attribute Clauses
“copyin” Clause
Purpose:
The copyin clause provides a means for assigning the same value to threadprivate variables for all threads in the team.
Format:
copyin (list)
The master thread variable is used as the copy source. The team threads are initialized with its value upon entry into the parallel construct.
Loop Work-sharing Construct: Schedule Clause
Format
schedule ( static | dynamic | guided [, chunk ] )
schedule (runtime)
The schedule clause affect how loop iterations are mapped into threads
Static [ ,chunk ]
Loop iterations are divided into pieces of size chunk and then statically assigned to threads
In absence of chunk size iterations are evenly (if possible) divided contiguously among the threads.
Pre-determined and predictable by the programmer
Least work at runtime: scheduling done at compile-time