|
The “lastprivate” Clause
Example: “lastprivate” Clause |
void useless() {
int tmp = 0;
#pragma omp parallel for firstprivate(tmp)lastprivate(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 ?
- Tmp is defined as its value at the “last sequential” iteration (i .e., for j=999)
Data Scope Attribute Clauses
“shared” Clause |
Purpose: The shared clause declares variables in its list to be shared among all the threads in the team
Format: Shared (list) |
- A shared variable exists in only one memory and all the threads can read or write the same address
- Its programmers responsibility to ensure that multiple threads properly access shared variables (such as critical sections)
“default” Clause |
Purpose: The default clause allows user to specify a default scope for all variables in the parallel region
Format: Default(shared | none) |
- Using NONE as a default requires that the programmer explicitly scope all the variables
- The C/C++ OpenMP does not include private or firstprivate as a possible default
- Only the Fortran API supports default(private)
- Note that the default storage attribute is DEFAULT(SHARED) (so no need to use it)
|