-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy paththreadprivate.cpp
More file actions
40 lines (29 loc) · 872 Bytes
/
threadprivate.cpp
File metadata and controls
40 lines (29 loc) · 872 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//Adapted from https://hpc-tutorials.llnl.gov/openmp/threadprivate_directive/
#include <stdio.h>
#include <omp.h>
int a, b = 20, i, tid;
float x;
#pragma omp threadprivate(a, x)
int main () {
/* Explicitly turn off dynamic threads */
omp_set_dynamic(0);
printf("1st Parallel Region:\n");
#pragma omp parallel private(b,tid)
{
tid = omp_get_thread_num();
a = tid;
b = tid;
x = 1.1 * tid +1.0;
printf("Thread %d: a,b,x= %d %d %f\n",tid,a,b,x);
} /* end of parallel section */
printf("************************************\n");
printf("Master thread doing serial work here\n");
printf("************************************\n");
printf("2nd Parallel Region:\n");
#pragma omp parallel private(tid)
{
tid = omp_get_thread_num();
printf("Thread %d: a,b,x= %d %d %f\n",tid,a,b,x);
} /* end of parallel section */
return 0;
}