-
Notifications
You must be signed in to change notification settings - Fork 0
/
4.c
49 lines (44 loc) · 1.01 KB
/
4.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
#include<omp.h>
#include<stdio.h>
void main() {
int i,j,k;
int a[4][3],b[3][4],c[4][4];
omp_set_num_threads(4);
#pragma omp parallel for
for(i=0;i<4;i++)
for(j=0;j<3;j++)
a[i][j] = i + j;
#pragma omp parallel for
for(i=0;i<3;i++)
for(j=0;j<4;j++)
b[i][j] = i * j;
#pragma omp parallel for
for(i=0;i<4;i++)
for(j=0;j<4;j++)
c[i][j] = 0;
#pragma omp parallel for
for(i=0;i<4;i++) {
printf("Thread %d did row %d\n",omp_get_thread_num(),i);
for(j=0;j<4;j++)
for(k=0;k<3;k++)
c[i][j] += a[i][k]*b[k][j];
}
printf("Matrix A\n");
for(i=0;i<4;i++) {
for(j=0;j<3;j++)
printf("%d ",a[i][j]);
printf("\n");
}
printf("Matrix B\n");
for(i=0;i<3;i++) {
for(j=0;j<4;j++)
printf("%d ",b[i][j]);
printf("\n");
}
printf("Matrix C\n");
for(i=0;i<4;i++) {
for(j=0;j<4;j++)
printf("%d ",c[i][j]);
printf("\n");
}
}