| Thread Tools | Search this thread |
|---|
zhangzhe65
| March 31, 2009 10:19 PM PDT about OpenMP Critical | ||||
why? code1 #include "stdafx.h" #include "omp.h" #define N 100000 int _tmain(int argc, _TCHAR* argv[]) { int arx[N],ary[N]; int i,max_num_x=-1,max_num_y=-1; for(i=0;i<N;i++) { arx[i]=i; ary[i]=N-i; } omp_set_num_threads(10); #pragma omp parallel for for(i=0;i<N;i++) { //#pragma omp critical(max_arx) if(arx[i]>max_num_x) max_num_x=arx[i]; //#pragma omp critical(max_ary) if(ary[i]>max_num_y) max_num_y=ary[i]; } printf("max_num_x=%d max_num_y=%d\n",max_num_x,max_num_y); return 0; } and code2 #include "stdafx.h" #include "omp.h" #define N 100000 int _tmain(int argc, _TCHAR* argv[]) { int arx[N],ary[N]; int i,max_num_x=-1,max_num_y=-1; for(i=0;i<N;i++) { arx[i]=i; ary[i]=N-i; } omp_set_num_threads(10); #pragma omp parallel for for(i=0;i<N;i++) { #pragma omp critical(max_arx) if(arx[i]>max_num_x) max_num_x=arx[i]; #pragma omp critical(max_ary) if(ary[i]>max_num_y) max_num_y=ary[i]; } printf("max_num_x=%d max_num_y=%d\n",max_num_x,max_num_y); return 0; } please tell me why the results of the two codes are identical? I don't know why no add #pragma omp critical ,no data race too,in code1Slide 173 .O {color:white; font-size:149%;} a:link {color:#0860A8 !important;} a:active {color:#567EB9 !important;} a:visited {color:#AA014C !important;} <!--.sld {left:0px !important; width:6.0in !important; height:4.5in !important; font-size:103% !important;} --> Critical | |||||
|
|||||||||||||
|
|||||||||||||
| 8470 users have contributed to 31601 threads and 100646 posts to date. |
|---|
| In the past 24 hours, we have 30 new thread(s) 113 new posts(s), and 159 new user(s). In the past 3 days, the most popular thread for everyone has been gemm(A,A,A) like possible? The most posts were made to gemm(A,A,A) like possible? The post with the most views is Dear Steve, excuse me for a d Please welcome our newest member kopernikus |