MCPcopy Create free account
hub / github.com/AdvancedCompiler/AdvancedCompiler / main

Function main

code/Chapter9/9-30.c:37–90  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36}
37int main()
38{
39 isync[0]=1;
40 for(i=0;i<N1;i++)
41 {
42 for(j=0;j<N2;j=j+4)
43 a[i][j]=3;
44 for(j=1;j<N2;j=j+4)
45 a[i][j]=5;
46 for(j=2;j<N2;j=j+4)
47 a[i][j]=4;
48 for(j=3;j<N2;j=j+4)
49 a[i][j]=8;
50 for(j=4;j<N2;j=j+5)
51 a[i][j]=7;
52 }
53 double start_time,end_time,used_time;
54 start_time=omp_get_wtime();
55 #pragma omp parallel default(shared) private(i,j) shared(a) num_threads(8)
56 {
57 mthreadnum=1;
58 mthreadnum=omp_get_num_threads()+1;
59 iam=1;
60 iam=omp_get_thread_num()+1;
61 isync[iam]=0;
62 #pragma omp barrier
63
64 for(int j=1;j<N2-1;j++)
65{
66 sync_left();
67 #pragma omp for schedule(static) nowait
68 for(int i=1;i<N1-1;i++)
69 {
70
71 a[i][j]=0.25*(a[i-1][j]+a[i][j-1]+a[i+1][j]+a[i][j+1]);
72
73 }
74 sync_right();
75 }
76 }
77end_time=omp_get_wtime();
78 used_time=end_time-start_time;
79double sum=0;
80 for(i=0;i<N1;i++)
81 {
82 for(j=0;j<N2;j++)
83 {
84 sum+=a[i][j];
85
86 }
87
88}
89printf("sum=%lf,used_time=%lf seconds\n",sum,used_time);
90}

Callers

nothing calls this directly

Calls 2

sync_leftFunction · 0.70
sync_rightFunction · 0.70

Tested by

no test coverage detected