forked from AdvancedCompiler/AdvancedCompiler
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstatic1.c
More file actions
31 lines (30 loc) · 652 Bytes
/
Copy pathstatic1.c
File metadata and controls
31 lines (30 loc) · 652 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
#include <stdio.h>
#include <omp.h>
#define N 2000
float A[N][N],B[N][N];
float C[N][N];
int main()
{
int i,j,k;
double start_time,end_time,used_time;
float sum=0.0;
for(i=0;i<N;i++)
for(int j=0;j<N;j++)
{
A[i][j]=i+1.0;
B[i][j]=1.0;
C[i][j]=0.0;
}
start_time=omp_get_wtime();
#pragma omp parallel for schedule(static,1) private(i,j,k) shared(A,B,C) num_threads(4)
for(i=0;i<N;i++)
for(j=0;j<N;j++)
for(k=0;k<N;k++)
C[i][j]+=A[i][k]*B[k][j];
end_time=omp_get_wtime();
used_time=end_time-start_time;
for(int i=0;i<N;i++)
for(int j=0;j<N;j++)
sum+=C[i][j];
printf("sum=%lf,used_time=%lf seconds\n",sum,used_time);
}