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

Function main

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

Callers

nothing calls this directly

Calls 2

sync_leftFunction · 0.70
sync_rightFunction · 0.70

Tested by

no test coverage detected