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

Function main

code/Chapter9/9-31.c:37–89  ·  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,m) 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 int b=9;
64 for(int i=1;i<N1-1;i=i+b)
65{
66 sync_left();
67 #pragma omp for schedule(static) nowait
68 for(int j=1;j<N2-1;j++)
69 {
70
71 for(int m=i;m<min(i+b,N1-1);m++)
72 {
73 a[m][j]=0.25*(a[m-1][j]+a[m][j-1]+a[m+1][j]+a[m][j+1]);
74 }
75 }
76 sync_right();
77 }
78 }
79 end_time=omp_get_wtime();
80 used_time=end_time-start_time;
81
82 double sum=0;
83 for(i=0;i<N1;i++)
84 {
85 for(j=0;j<N2;j++)
86 sum+=a[i][j];
87 }
88 printf("sum=%lf,used_time=%lf seconds\n",sum,used_time);
89}

Callers

nothing calls this directly

Calls 2

sync_leftFunction · 0.70
sync_rightFunction · 0.70

Tested by

no test coverage detected