-
Notifications
You must be signed in to change notification settings - Fork 0
/
openmp_master.c
58 lines (43 loc) · 853 Bytes
/
openmp_master.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include <omp.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
int main(void)
{
int i = 0, N = 8;
omp_set_num_threads(N);
int *a;
int *b;
int *c;
#pragma omp parallel
{
#pragma omp master
{
a = malloc(N * sizeof(int));
b = malloc(N * sizeof(int));
c = malloc(N * sizeof(int));
srand(time(NULL));
}
#pragma omp for
for( i = 0; i < N; i++) {
a[i] = rand() % 10;
b[i] = rand() % 10;
}
#pragma omp for
for( i = 0; i < N; i++) {
c[i] = a[i] * b[i];
}
#pragma omp for
for( i = 0; i < N ; i++) {
printf("A[%d] * B[%d] = %d \n", i, i, c[i]);
}
}
free(a);
free(b);
free(c);
/** We cam commine the directives into a single line
* #pragma omp parallel for
*/
return 0;
}