B3 - variables and synchronisation
- each thread has its own stack variables, used when subroutines are called
- all other variables may be chosen to be:
- shared: a single storage location accessed by all the threads
- private: multiple storage locations, one per threads
- reduction: for variables that are the target of an arithmetic reduction operation, eg: final summation of temporary private variables at the end of the parallel construct
- default behaviour can be specified for variables not included in one of the lists
- default only supports shared/none:
#pragma omp parallel default(shared) private(i)
#pragma omp parallel default(none) shared (n, b, c) private(i)
-
recommended to use
default(nonein all but very simple programs -
helpful for catching unintended sharing
-
can also declare thread-private variables within regions only run by the master thread:
int i, j, k;
#pragma omp threadprivate(i, j)
these persist into parallel regions
- all but the master thread's versions are inaccessible in serial regions
- note that the compiler probably will not allocate thread-private variables in memory local to each thread, so they may be much