|
Data Environment:
Default storage attributes:
- Shared Memory programming model:
- Most variables are shared by default
- Global variables are shared among threads
- Fortran: COMMON blocks, SAVE variables, MODULE variables
- C: File scope variables, static
- Both: Dynamically allocated memory (ALLOCATE, malloc, new)
- But not everything is shared...
- Stack variables in subprograms(Fortran) or functions(C) called from parallel regions are private
- Automatic variables within a statement block are private
Example: Data Sharing
double A[10];
int main() {
int index [ 10 ] ;
#pragma omp parallel
work(index);
printf(“%d”, index[0]);
} |
extern double A [ 10 ];
void work(int index) {
double temp[10];
static int count;
...
} |
- Which variables are “shared” and “private” ?
- Which variables are “shared” and “private” ?
- A index and count are shared by all threads
- Variable temp is local to each thread
Changing Storage Attributes
It is possible to change storage attribute of data for constructs using OpenMP clauses |