fix PMEMic bug
authorYanhua Sun <sun51@nid05430.(none)>
Sun, 11 Sep 2011 06:14:16 +0000 (23:14 -0700)
committerYanhua Sun <sun51@nid05430.(none)>
Sun, 11 Sep 2011 06:14:16 +0000 (23:14 -0700)
examples/charm++/PMEMimic/Makefile
examples/charm++/PMEMimic/PMEMimic.C
examples/charm++/PMEMimic/PMEMimic.ci

index 4cfc28dc808749cce21a0e87e519f34b90b9818e..cca7bf8a9f4b14367aa703c332a33f2067200958 100644 (file)
@@ -2,10 +2,13 @@ CHARMC=../../../bin/charmc $(OPTS)
 
 OBJS = PMEMimic.o
 
-all: PMEMimic
+all: pgm pgm.prj
 
-PMEMimic: $(OBJS)
-       $(CHARMC) -language charm++ -o PMEMimic $(OBJS)
+pgm: $(OBJS)
+       $(CHARMC) -language charm++ -o pgm $(OBJS)
+
+pgm.prj: $(OBJS)
+       $(CHARMC) -language charm++ -tracemode projections -o pgm.prj $(OBJS)
 
 PMEMimic.decl.h: PMEMimic.ci
        $(CHARMC)  PMEMimic.ci
@@ -17,7 +20,7 @@ PMEMimic.o: PMEMimic.C PMEMimic.decl.h
        $(CHARMC) -c PMEMimic.C
 
 test: all
-       ./charmrun +p12 PMEMimic 3 2 2 $(TESTOPTS)
+       ./charmrun +p12 pgm 3 2 2 $(TESTOPTS)
 
 bgtest: all
-       ./charmrun PMEMimic +p4 10 +x2 +y2 +z1
+       ./charmrun pgm +p4 10 +x2 +y2 +z1
index 3fdab5931eca4cdd5936ff44041e1257253ed1d7..d0d7d48ba3d49d7bbdd76f4885e5c981fd40a37c 100644 (file)
@@ -11,9 +11,9 @@ int     grid_z;
 int     max_iter;
 int     pes_per_node;
 
-CProxy_PMEPencil pme_x;
-CProxy_PMEPencil pme_y;
-CProxy_PMEPencil pme_z;
+CProxy_PMEPencil_X pme_x;
+CProxy_PMEPencil_Y pme_y;
+CProxy_PMEPencil_Z pme_z;
 
 class DataMsg : public CMessage_DataMsg
 {
@@ -81,9 +81,9 @@ public:
       CkArrayOptions opts_z(grid_x, grid_y); 
       opts_z.setMap(myMap_z);
 
-      pme_x = CProxy_PMEPencil::ckNew(0, opts_x);
-      pme_y = CProxy_PMEPencil::ckNew(1, opts_y);
-      pme_z = CProxy_PMEPencil::ckNew(2, opts_z);
+      pme_x = CProxy_PMEPencil_X::ckNew(0, opts_x);
+      pme_y = CProxy_PMEPencil_Y::ckNew(1, opts_y);
+      pme_z = CProxy_PMEPencil_Z::ckNew(2, opts_z);
 
       done_pme=0;
       startTimer = CmiWallTimer();
@@ -94,31 +94,31 @@ public:
     void done()
     {
         done_pme++;
-        if(done_pme == grid_x)
+        if(done_pme == grid_x*grid_x)
         {
             done_pme = 0;
 
-            CkPrintf("PME(%d, %d, %d) on %d PEs, %d iteration, avg time:%f\n", grid_x, grid_y, grid_z, CkNumPes(), max_iter, CmiWallTimer()-startTimer);
+            CkPrintf("PME(%d, %d, %d) on %d PEs, %d iteration, avg time:%f(ms)\n", grid_x, grid_y, grid_z, CkNumPes(), max_iter, (CmiWallTimer()-startTimer)/max_iter*1000);
             CkExit();
         }
     }
 };
 
 /*array [1D]*/
-class PMEPencil : public CBase_PMEPencil
+class PMEPencil_X : public CBase_PMEPencil_X
 {
     int PME_index;
     int buffered_num, buffered_phrase;
     int recv_nums, iteration;
 public:
-  PMEPencil(int i)
+  PMEPencil_X(int i)
   {
       PME_index = i;
       recv_nums = 0;
       iteration = 0;
       buffered_num = 0;
   }
-  PMEPencil(CkMigrateMessage *m) {}
+  PMEPencil_X(CkMigrateMessage *m) {}
 
   void start()
   {
@@ -197,5 +197,192 @@ public:
   }
 };
 
+/*array [1D]*/
+class PMEPencil_Y : public CBase_PMEPencil_Y
+{
+    int PME_index;
+    int buffered_num, buffered_phrase;
+    int recv_nums, iteration;
+public:
+  PMEPencil_Y(int i)
+  {
+      PME_index = i;
+      recv_nums = 0;
+      iteration = 0;
+      buffered_num = 0;
+  }
+  PMEPencil_Y(CkMigrateMessage *m) {}
+
+  void start()
+  {
+   //thisindex.x thisindex.y
+    // x (yz), y(x, z)
+    for(int x=0; x<grid_x; x++)
+    {
+      DataMsg *msg= new DataMsg;
+      msg->phrase = 1;
+      pme_y(x, thisIndex.y).recvTrans(msg);  
+    }
+  }
+  void recvTrans(DataMsg *msg_recv)
+  {
+    int expect_num, index;
+    expect_num = grid_x;
+    index = msg_recv->phrase;
+
+    if(msg_recv->phrase != PME_index)
+    {
+        buffered_num++;
+        buffered_phrase = msg_recv->phrase;
+        delete msg_recv;
+        return;
+    }
+    recv_nums++;
+    if(recv_nums == expect_num)
+    {
+        //CkPrintf("[%d, %d] phrase %d, iter=%d\n", thisIndex.x, thisIndex.y, msg_recv->phrase, iteration);
+        if(index == 0  ) //x (y,z) to y(x,z)
+        {
+            iteration++;
+            if(iteration == max_iter)
+            {
+                mainProxy.done();
+                return;
+            }
+            for(int x=0; x<grid_x; x++)
+            {
+                DataMsg *msg= new DataMsg;
+                msg->phrase = msg_recv->phrase+1;
+                pme_y(x, thisIndex.y).recvTrans(msg);  
+            }
+        }else if(index == 1) //y(x,z) send to z(x,y)
+        {
+            for(int y=0; y<grid_y; y++)
+            {
+                DataMsg *msg= new DataMsg;
+                msg->phrase = msg_recv->phrase+1;
+                pme_z(thisIndex.x, y).recvTrans(msg); 
+            }
+            PME_index = 3;
+            recv_nums = buffered_num;
+        }else if(index == 2) //Z(x,y) send to y(x,z)
+        {
+            for(int z=0; z<grid_z; z++)
+            {
+                DataMsg *msg= new DataMsg;
+                msg->phrase = msg_recv->phrase+1;
+                pme_y(thisIndex.x, z).recvTrans(msg); 
+            }
+        } else if(index == 3) //y(x,z) to x(y,z)
+        {
+            for(int y=0; y<grid_y; y++)
+            {
+                DataMsg *msg= new DataMsg;
+                msg->phrase = 0;
+                pme_x(y, thisIndex.y).recvTrans(msg); 
+            }
+            PME_index = 1;
+            recv_nums = buffered_num;
+        }
+        recv_nums = 0;
+    }
+    delete msg_recv;
+  }
+};
+
+/*array [1D]*/
+class PMEPencil_Z : public CBase_PMEPencil_Z
+{
+    int PME_index;
+    int buffered_num, buffered_phrase;
+    int recv_nums, iteration;
+public:
+  PMEPencil_Z(int i)
+  {
+      PME_index = i;
+      recv_nums = 0;
+      iteration = 0;
+      buffered_num = 0;
+  }
+  PMEPencil_Z(CkMigrateMessage *m) {}
+
+  void start()
+  {
+   //thisindex.x thisindex.y
+    // x (yz), y(x, z)
+    for(int x=0; x<grid_x; x++)
+    {
+      DataMsg *msg= new DataMsg;
+      msg->phrase = 1;
+      pme_y(x, thisIndex.y).recvTrans(msg);  
+    }
+  }
+  void recvTrans(DataMsg *msg_recv)
+  {
+    int expect_num, index;
+    expect_num = grid_x;
+    index = msg_recv->phrase;
+
+    if(msg_recv->phrase != PME_index)
+    {
+        buffered_num++;
+        buffered_phrase = msg_recv->phrase;
+        delete msg_recv;
+        return;
+    }
+    recv_nums++;
+    if(recv_nums == expect_num)
+    {
+        //CkPrintf("[%d, %d] phrase %d, iter=%d\n", thisIndex.x, thisIndex.y, msg_recv->phrase, iteration);
+        if(index == 0  ) //x (y,z) to y(x,z)
+        {
+            iteration++;
+            if(iteration == max_iter)
+            {
+                mainProxy.done();
+                return;
+            }
+            for(int x=0; x<grid_x; x++)
+            {
+                DataMsg *msg= new DataMsg;
+                msg->phrase = msg_recv->phrase+1;
+                pme_y(x, thisIndex.y).recvTrans(msg);  
+            }
+        }else if(index == 1) //y(x,z) send to z(x,y)
+        {
+            for(int y=0; y<grid_y; y++)
+            {
+                DataMsg *msg= new DataMsg;
+                msg->phrase = msg_recv->phrase+1;
+                pme_z(thisIndex.x, y).recvTrans(msg); 
+            }
+            PME_index = 3;
+            recv_nums = buffered_num;
+        }else if(index == 2) //Z(x,y) send to y(x,z)
+        {
+            for(int z=0; z<grid_z; z++)
+            {
+                DataMsg *msg= new DataMsg;
+                msg->phrase = msg_recv->phrase+1;
+                pme_y(thisIndex.x, z).recvTrans(msg); 
+            }
+        } else if(index == 3) //y(x,z) to x(y,z)
+        {
+            for(int y=0; y<grid_y; y++)
+            {
+                DataMsg *msg= new DataMsg;
+                msg->phrase = 0;
+                pme_x(y, thisIndex.y).recvTrans(msg); 
+            }
+            PME_index = 1;
+            recv_nums = buffered_num;
+        }
+        recv_nums = 0;
+    }
+    delete msg_recv;
+  }
+};
+
+
 
 #include "PMEMimic.def.h"
index dba93c1a28ea81c4bdfa5cf248c1b466ab30eab6..58ce7963d1e26642ea16cf1a1dac32c0e6ad7662 100644 (file)
@@ -7,9 +7,9 @@ mainmodule PMEMimic {
   readonly int     grid_z;
   readonly int     pes_per_node;
   readonly int     max_iter;
-  readonly CProxy_PMEPencil pme_x;
-  readonly CProxy_PMEPencil pme_y;
-  readonly CProxy_PMEPencil pme_z;
+  readonly CProxy_PMEPencil_X pme_x;
+  readonly CProxy_PMEPencil_Y pme_y;
+  readonly CProxy_PMEPencil_Z pme_z;
 
   group PMEMap : CkArrayMap {
       entry PMEMap(int); 
@@ -22,10 +22,21 @@ mainmodule PMEMimic {
 
   message DataMsg;
 
-  array [2D] PMEPencil {
-    entry PMEPencil(int);
+  array [2D] PMEPencil_X {
+    entry PMEPencil_X(int);
     entry void start();
     entry void recvTrans( DataMsg *m);
   };        
-  
+  array [2D] PMEPencil_Y {
+    entry PMEPencil_Y(int);
+    entry void start();
+    entry void recvTrans( DataMsg *m);
+  }; 
+array [2D] PMEPencil_Z {
+    entry PMEPencil_Z(int);
+    entry void start();
+    entry void recvTrans( DataMsg *m);
+  };  
+
 };