Module 10: Open Multi-Processing
  Lecture 20: The “omp sections” Directive
 


Data Scope Attribute Clauses

“firstprivate” Clause

Purpose: The firstprivate clause combines the behavior of the private clause with automatic initialization of the variables in the list
Format: firstprivate (list)

  • Special case of private clause
  • Initializes each private copy with the corresponding value from the master thread prior to entry into the parallel or work-sharing construct

The “firstprivate” Clause

Example: “firstprivate” Clause

void useless() {
int tmp = 0;
#pragma omp parallel for firstprivate(tmp)
for (int j = 0; j ¡ 1000; ++j)
tmp += j;
printf(“%d”, tmp);
}
  • Each thread gets its own code with initial value 0.Is there something still wrong with the code ?
  • What value of tmp it will be printed in second last line ?
  • Tmp is unspecified for OpenMP 2.5 while 0 in OpenMP 3.0

“lastprivate” Clause

Purpose: The lastprivate clause combines the behavior of the private clause with a copy from the last loop iteration or section to the original variable object.
Format: lastprivate (list)

  • The value copied back into the original variable object is obtained from the last (sequentially) iteration or section of the enclosing construct.