fix openMP in jacobi
authorYanhua Sun <yanhuas@jyc1.(none)>
Wed, 19 Sep 2012 18:11:32 +0000 (13:11 -0500)
committerYanhua Sun <yanhuas@jyc1.(none)>
Wed, 19 Sep 2012 18:11:32 +0000 (13:11 -0500)
tests/charm++/jacobi3d-sdag/Makefile
tests/charm++/jacobi3d-sdag/jacobi3d.C

index c6aa7e0a4cf3787557dfbf6f39bef0fee9130dbc..61e38c36a36350521bf12b068a4fdf3a68218365 100644 (file)
@@ -4,7 +4,7 @@ OBJS = jacobi3d.o
 
 OBJS_OMP = jacobi3d_omp.o
 
-OMP_FLAG = -DJACOBI_OPENMP
+OMP_FLAG = -DJACOBI_OPENMP -fopenmp
 
 all: jacobi3d
 
@@ -13,7 +13,7 @@ jacobi3d: $(OBJS)
 #      $(CHARMC) -language charm++ -module EveryLB -memory paranoid -o jacobi3d $(OBJS)
 
 jacobi3d_omp: $(OBJS_OMP)
-       $(CHARMC) -language charm++ -module DummyLB -fopenmp -o jacobi3d $(OBJS)
+       $(CHARMC) -language charm++ -module DummyLB $(OMP_FLAG) -o jacobi3d_omp $(OBJS_OMP)
 
 projections: $(OBJS)
        $(CHARMC) -language charm++ -tracemode projections -lz -o jacobi3d.prj $(OBJS)
@@ -39,5 +39,5 @@ jacobi3d.o: jacobi3d.C jacobi3d.decl.h
        $(CHARMC) -c jacobi3d.C
 
 jacobi3d_omp.o: jacobi3d.C jacobi3d.decl.h
-       $(CHARMC) $(OMP_FLAG) -fopenmp -c jacobi3d.C
+       $(CHARMC) $(OMP_FLAG) -o $(OBJS_OMP) -c jacobi3d.C
 
index 739063f4b3d114fc8b100e17d868110c505eb177..d7cfdd20de4b8698bfffe27aba6aecc234b4cdd9 100644 (file)
@@ -68,9 +68,9 @@ int myrand(int numpes) {
 
 #define index(a, b, c) ( (a)*(blockDimY+2)*(blockDimZ+2) + (b)*(blockDimZ+2) + (c) )
 
-#define PRINT_FREQ      10
-#define CKP_FREQ               200
-#define MAX_ITER               1000
+#define PRINT_FREQ      100
+#define CKP_FREQ               100
+#define MAX_ITER        400    
 #define WARM_ITER              5
 #define LEFT                   1
 #define RIGHT                  2
@@ -184,15 +184,8 @@ class Main : public CBase_Main {
       CkPrintf("Total Hops: %d\n", hops);
        
 #ifdef JACOBI_OPENMP 
-      int numOmpThreads = 
-        CkNumPes() / (num_chare_x * num_chare_y * num_chare_z);
-      if (numOmpThreads <= 1) {
-        numOmpThreads = 1; 
-      }
-      CkPrintf("Computation loop will be parallelized"
-               " with %d OpenMP threads\n", numOmpThreads);
       CProxy_OmpInitializer ompInit = 
-        CProxy_OmpInitializer::ckNew(numOmpThreads);
+        CProxy_OmpInitializer::ckNew(4);
 #else    
       //Start the computation
       start();
@@ -431,7 +424,7 @@ class Jacobi: public CBase_Jacobi {
                        else
                                AtSync();
 #else
-                       doStep();
+            contribute(0, 0, CkReduction::concat, CkCallback(CkIndex_Main::report(), mainProxy));
 #endif
                } else {
                        doStep();
@@ -446,23 +439,22 @@ class Jacobi: public CBase_Jacobi {
     // Check to see if we have received all neighbor values yet
     // If all neighbor values have been received, we update our values and proceed
     void compute_kernel() {
-#pragma unroll    
-#ifdef JACOBI_OPENMP
-  #pragma omp parallel for
-#endif
-      for(int i=1; i<blockDimX+1; ++i) {
-       for(int j=1; j<blockDimY+1; ++j) {
-         for(int k=1; k<blockDimZ+1; ++k) {
-           // update my value based on the surrounding values
-           new_temperature[index(i, j, k)] = (temperature[index(i-1, j, k)] 
+        int i;
+  #pragma omp parallel for schedule(dynamic) 
+      for(i=1; i<blockDimX+1; ++i) {
+          //printf("[%d] did  %d iteration out of %d \n", omp_get_thread_num(), i, blockDimX+1); 
+          for(int j=1; j<blockDimY+1; ++j) {
+              for(int k=1; k<blockDimZ+1; ++k) {
+                  // update my value based on the surrounding values
+                   new_temperature[index(i, j, k)] = (temperature[index(i-1, j, k)] 
                                            +  temperature[index(i+1, j, k)]
                                            +  temperature[index(i, j-1, k)]
                                            +  temperature[index(i, j+1, k)]
                                            +  temperature[index(i, j, k-1)]
                                            +  temperature[index(i, j, k+1)]
                                            +  temperature[index(i, j, k)] ) * DIVIDEBY7;
-         }
-       }
+              }
+          }
       }
     }
 
@@ -583,7 +575,15 @@ public:
           if (numThreads < 1) {
             numThreads = 1; 
           }
-          omp_set_num_threads(numThreads);
+          //omp_set_num_threads(numThreads);
+          if(CkMyPe() == 0)
+          {
+#pragma omp parallel
+              { if(omp_get_thread_num() == 0 )
+                  CkPrintf("Computation loop will be parallelized"
+               " with %d OpenMP threads\n", omp_get_num_threads());
+              }
+          }
 #endif
           mainProxy.start();
        }