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


Data Scope Attribute Clauses

The Data Scope Attribute Clauses are used to explicitly define how variables should be scoped.They include :

  • Private
  • Firstprivate
  • Lastprivate
  • Shared
  • Default
  • Reduction
  • Copyin

“private” Clause

Purpose: The private clause declares variables in its list to be private to each thread
Format: private (list)

  • A new object of the same type is declared for each thread in the team
  • Private(var) creates a new local copy of var for each thread

Example: “private” Clause

void wrong() {
int tmp = 0;
#pragma omp parallel for private(tmp)
for (int j = 0; j < 1000; ++j)
tmp += j;
printf(“%d”, tmp);
}
  • What is wrong with the code ?
  • Value of tmp was not initialized at line 5
  • What value of tmp it will be printed in second last line ?
  • In OpenMP 2.5 the value of the shared variable is undefined after the region So tmp is unspecified for OpenMP 2.5 while 0 in OpenMP 3.0