-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathopenmp2.c
29 lines (29 loc) · 884 Bytes
/
openmp2.c
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
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
/***************************************************************/
#include <omp.h>
int main(void) {
int np = omp_get_max_threads();
if (np<2) exit(1);
/* allocate shared pointers */
int ** A = malloc(np*sizeof(int*));
#pragma omp parallel shared(A)
{
int me = omp_get_thread_num();
/* allocate per-thread data */
A[me] = malloc(sizeof(int));
#pragma omp barrier
int B = 0x86;
/* store local B at PE 0 into A at PE 1 */
if (me==0) A[1][0] = B;
/* global synchronization of execution and data */
#pragma omp barrier
/* observe the result of the store */
if (me==1) printf("A@1=%d\n",A[1][0]);
free(A[me]);
}
free(A);
return 0;
}
/***************************************************************/