-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathsection_worksharing.c
More file actions
49 lines (44 loc) · 873 Bytes
/
section_worksharing.c
File metadata and controls
49 lines (44 loc) · 873 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
41
42
43
44
45
46
47
48
49
#include<stdio.h>
#include<omp.h>
#define N 2
int main(){
int i;
float a[N], b[N], c[N], d[N];
for(i=0; i<N; i++){
a[i]=i*1.5;
b[i]=i+15.50;
}
omp_set_num_threads(2);
int tid, numt;
#pragma omp parallel shared(a,b,c,d) private(i,tid)
{
tid=omp_get_thread_num();
numt=omp_get_num_threads();
printf("Thread ID: %d of %d is working\n", tid, numt);
#pragma omp sections nowait
{
#pragma omp section
for(i=0; i<N; i++){
c[i]=a[i]+b[i];
}
#pragma omp section
for(i=0; i<N; i++){
d[i]=a[i]*b[i];
}
#pragma omp section
{
for(i=0; i<N; i++){
printf("%f ",c[i]);
}
printf("\n");
}
#pragma omp section
{
for(i=0; i<N; i++){
printf("%f ",d[i]);
}
printf("\n");
}
}
}
}