add benchmark program to mimic PME communication pattern in NAMD
authorYanhuaSun <sun51@illinois.edu>
Sun, 11 Sep 2011 01:56:37 +0000 (20:56 -0500)
committerYanhuaSun <sun51@illinois.edu>
Sun, 11 Sep 2011 01:56:37 +0000 (20:56 -0500)
examples/charm++/PMEMimic/Makefile [new file with mode: 0644]
examples/charm++/PMEMimic/PMEMimic.C [new file with mode: 0644]
examples/charm++/PMEMimic/PMEMimic.ci [new file with mode: 0644]
examples/charm++/PMEMimic/README [new file with mode: 0644]

diff --git a/examples/charm++/PMEMimic/Makefile b/examples/charm++/PMEMimic/Makefile
new file mode 100644 (file)
index 0000000..341c80d
--- /dev/null
@@ -0,0 +1,23 @@
+CHARMC=/expand/home/jessie/PPL/git/charm/mpi-linux-x86_64/bin/charmc $(OPTS)
+
+OBJS = PMEMimic.o
+
+all: PMEMimic
+
+PMEMimic: $(OBJS)
+       $(CHARMC) -language charm++ -o PMEMimic $(OBJS)
+
+PMEMimic.decl.h: PMEMimic.ci
+       $(CHARMC)  PMEMimic.ci
+
+clean:
+       rm -f *.decl.h *.def.h conv-host *.o PMEMimic charmrun
+
+PMEMimic.o: PMEMimic.C PMEMimic.decl.h
+       $(CHARMC) -c PMEMimic.C
+
+test: all
+       ./charmrun PMEMimic +p4 10 $(TESTOPTS)
+
+bgtest: all
+       ./charmrun PMEMimic +p4 10 +x2 +y2 +z1
diff --git a/examples/charm++/PMEMimic/PMEMimic.C b/examples/charm++/PMEMimic/PMEMimic.C
new file mode 100644 (file)
index 0000000..0b0a5a8
--- /dev/null
@@ -0,0 +1,191 @@
+#include <stdio.h>
+#include "PMEMimic.decl.h"
+
+/*readonly*/ CProxy_Main mainProxy;
+/*readonly*/ 
+
+int     N;
+int     grid_x;
+int     grid_y;
+int     grid_z;
+int     max_iter;
+int     pes_per_node;
+
+CProxy_PMEPencil pme_x;
+CProxy_PMEPencil pme_y;
+CProxy_PMEPencil pme_z;
+
+class DataMsg : public CMessage_DataMsg
+{
+public:
+    int phrase;
+    char data[2048];
+
+    DataMsg() {}
+
+};
+
+class PMEMap : public CkArrayMap 
+{ 
+    int offset;
+public: 
+    PMEMap(int off) { offset = off;} 
+    PMEMap(CkMigrateMessage *m){} 
+    int registerArray(CkArrayIndex& numElements,CkArrayID aid) { 
+        return 0; 
+    } 
+    int procNum(int /*arrayHdl*/,const CkArrayIndex &idx) { 
+        int penum;
+        int *index =  (int *)idx.data();
+        int obj_index =  index[0]*grid_x + index[1];
+        penum = obj_index * pes_per_node + offset;
+        return penum; 
+    } 
+}; 
+
+
+/*mainchare*/
+class Main : public CBase_Main
+{
+    double startTimer;
+    int done_pme, iteration;
+public:
+
+    Main(CkArgMsg* m)
+    {
+        //Process command-line arguments
+        grid_x = grid_y = grid_z = 10;
+        max_iter = 100;
+        pes_per_node = 3;
+        if(m->argc > 1)
+        {
+            pes_per_node = 3;
+            grid_x = grid_y = grid_z = atoi(m->argv[1]);
+            max_iter = atoi(m->argv[2]);
+        }
+        delete m;
+
+    //Start the computation
+      CkPrintf("Running PMEMimic on %d processors for %d elements\n",
+          CkNumPes(), grid_x);
+      mainProxy = thisProxy;
+
+      CProxy_PMEMap myMap_x=CProxy_PMEMap::ckNew(0); 
+      CkArrayOptions opts_x(grid_y, grid_z); 
+      opts_x.setMap(myMap_x);
+
+      CProxy_PMEMap myMap_y=CProxy_PMEMap::ckNew(1); 
+      CkArrayOptions opts_y(grid_x, grid_z); 
+      opts_y.setMap(myMap_y);
+
+      CProxy_PMEMap myMap_z=CProxy_PMEMap::ckNew(2); 
+      CkArrayOptions opts_z(grid_x, grid_y); 
+      opts_z.setMap(myMap_z);
+
+      pme_x = CProxy_PMEPencil::ckNew(opts_x);
+      pme_y = CProxy_PMEPencil::ckNew(opts_y);
+      pme_z = CProxy_PMEPencil::ckNew(opts_z);
+
+      done_pme=0;
+      startTimer = CmiWallTimer();
+      pme_x.start();
+    };
+
+    void done()
+    {
+        done_pme++;
+        if(done_pme == 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);
+            CkExit();
+        }
+    }
+};
+
+/*array [1D]*/
+class PMEPencil : public CBase_PMEPencil
+{
+    int recv_nums, iteration;
+public:
+  PMEPencil()
+  {
+    recv_nums = 0;
+    iteration = 0;
+  }
+  PMEPencil(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;
+    recv_nums++;
+    expect_num = grid_x;
+    index = msg_recv->phrase;
+
+    if(recv_nums == expect_num)
+    {
+        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 = 1;
+                pme_y(x, thisIndex.y).recvTrans(msg);  
+            }
+            CkPrintf("x==>y\n");
+        }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->phrase+1;
+                pme_z(thisIndex.x, y).recvTrans(msg); 
+            }
+            CkPrintf("y==>z\n");
+        }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->phrase+1;
+                pme_z(thisIndex.x, z).recvTrans(msg); 
+            }
+            CkPrintf("z==>y\n");
+        } 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_z(y, thisIndex.y).recvTrans(msg); 
+            }
+            CkPrintf("y==>x\n");
+
+        }
+        recv_nums = 0;
+    }
+    delete msg_recv;
+  }
+};
+
+
+#include "PMEMimic.def.h"
diff --git a/examples/charm++/PMEMimic/PMEMimic.ci b/examples/charm++/PMEMimic/PMEMimic.ci
new file mode 100644 (file)
index 0000000..c311066
--- /dev/null
@@ -0,0 +1,31 @@
+mainmodule PMEMimic {
+  readonly CProxy_Main mainProxy;
+
+  readonly int     N;
+  readonly int     grid_x;
+  readonly int     grid_y;
+  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;
+
+  group PMEMap : CkArrayMap {
+      entry PMEMap(int); 
+  }
+
+  mainchare Main {
+    entry Main(CkArgMsg *m);
+    entry void done();
+  };
+
+  message DataMsg;
+
+  array [2D] PMEPencil {
+    entry PMEPencil();
+    entry void start();
+    entry void recvTrans( DataMsg *m);
+  };        
+  
+};
diff --git a/examples/charm++/PMEMimic/README b/examples/charm++/PMEMimic/README
new file mode 100644 (file)
index 0000000..4c89d33
--- /dev/null
@@ -0,0 +1,4 @@
+Mimic PME communication pattern in NAMD.
+
+exec pes_per_node grid_x max_iteration
+