calculation of hops added
authorAbhinav Bhatele <bhatele@illinois.edu>
Tue, 27 Nov 2007 10:41:19 +0000 (10:41 +0000)
committerAbhinav Bhatele <bhatele@illinois.edu>
Tue, 27 Nov 2007 10:41:19 +0000 (10:41 +0000)
examples/charm++/topology/jacobi2d/jacobi2d.C

index 8d78508f9c47823528a2db9c2352a472f3f05f9d..2c3bf552e3fdeab841afcc5fbaea6741c799d925 100644 (file)
@@ -42,7 +42,7 @@
 /*readonly*/ int num_chare_x;
 /*readonly*/ int num_chare_y;
 
-#define USE_TOPOMAP    1
+#define USE_TOPOMAP    0
 // We want to wrap entries around, and because mod operator % 
 // sometimes misbehaves on negative values. -1 maps to the highest value.
 #define wrap_x(a)  (((a)+num_chare_x)%num_chare_x)
@@ -116,6 +116,25 @@ class Main : public CBase_Main
       array = CProxy_Jacobi::ckNew(num_chare_x, num_chare_y);
 #endif
 
+      TopoManager tmgr;
+      CkArray *jarr = array.ckLocalBranch();
+      int jmap[num_chare_x][num_chare_y];
+
+      int hops=0, p;
+      for(int i=0; i<num_chare_x; i++)
+        for(int j=0; j<num_chare_y; j++)
+            jmap[i][j] = jarr->procNum(CkArrayIndex2D(i, j));
+
+      for(int i=0; i<num_chare_x; i++)
+        for(int j=0; j<num_chare_y; j++) {
+          int p = jmap[i][j];
+          hops += tmgr.getHopsBetweenRanks(p, jmap[wrap_x(i+1)][j]);
+          hops += tmgr.getHopsBetweenRanks(p, jmap[wrap_x(i-1)][j]);
+          hops += tmgr.getHopsBetweenRanks(p, jmap[i][wrap_y(j+1)]);
+          hops += tmgr.getHopsBetweenRanks(p, jmap[i][wrap_y(j-1)]);
+        }
+      CkPrintf("Total Hops: %d\n", hops);
+
       // save the total number of worker chares we have in this simulation
       num_chares = num_chare_x * num_chare_y;