added many to many example to mimic PME 2D communication
authorYanhuaSun <sun51@illinois.edu>
Fri, 27 Jul 2012 04:48:45 +0000 (23:48 -0500)
committerYanhuaSun <sun51@illinois.edu>
Fri, 27 Jul 2012 04:48:45 +0000 (23:48 -0500)
examples/charm++/manyToMany/Makefile [new file with mode: 0644]
examples/charm++/manyToMany/manyToMany.C [new file with mode: 0644]
examples/charm++/manyToMany/manyToMany.ci [new file with mode: 0644]

diff --git a/examples/charm++/manyToMany/Makefile b/examples/charm++/manyToMany/Makefile
new file mode 100644 (file)
index 0000000..e4b3b8c
--- /dev/null
@@ -0,0 +1,21 @@
+CHARMC=../../../bin/charmc $(OPTS)
+
+OBJS = manyToMany.o
+
+all: manyToMany
+
+manyToMany: $(OBJS)
+       $(CHARMC) -language charm++ -o manyToMany $(OBJS)
+
+manyToMany.decl.h: manyToMany.ci
+       $(CHARMC)  manyToMany.ci
+
+clean:
+       rm -f *.decl.h *.def.h conv-host *.o manyToMany charmrun
+
+manyToMany.o: manyToMany.C manyToMany.decl.h
+       $(CHARMC) -c manyToMany.C
+
+test: all
+       ./charmrun manyToMany +p4 1024 
+
diff --git a/examples/charm++/manyToMany/manyToMany.C b/examples/charm++/manyToMany/manyToMany.C
new file mode 100644 (file)
index 0000000..205e7d2
--- /dev/null
@@ -0,0 +1,117 @@
+#include "manyToMany.decl.h"
+#include <math.h>
+
+/*readonly*/ CProxy_Main mainProxy;
+/*readonly*/ int numChares;
+/*readonly*/ int msgSize;
+/*readonly*/ int max_iter;
+
+struct manyToManyMsg : public CMessage_manyToManyMsg {
+  char *data;
+};
+
+struct Main : public CBase_Main {
+       double start;
+       CProxy_manyToMany manyToManyProxy;
+    int         iter;
+
+       Main(CkArgMsg* m) {
+
+        max_iter = 400;
+        numChares = sqrt(CkNumPes());
+        msgSize = 1024;
+               // 3D manyToMany on a NxNxN array
+        if(m->argc >= 2)
+        {
+            msgSize = atoi(m->argv[1]);
+        }
+        if(m->argc >= 3)
+        {
+            numChares = atoi(m->argv[2]);
+        }
+        
+        delete m;
+
+        iter = 0;
+               mainProxy = thisProxy;
+               // Construct an array of manyToMany chares to do the calculation
+               manyToManyProxy = CProxy_manyToMany::ckNew(numChares, numChares);
+       }
+
+       void manyToManyReady() {
+               start = CkWallTimer();
+               // Broadcast the 'go' signal to the manyToMany chare array
+               manyToManyProxy.domanyToMany();
+        
+       }
+
+       void nextmanyToMany() {
+               
+        iter++;
+        if(iter < max_iter)
+        {
+            manyToManyProxy.domanyToMany();
+        }else
+        {
+            double time = CkWallTimer() - start;
+            CkPrintf("manyToMany on %d cores for msg size: %d per iteration:%f ms\n",
+                CkNumPes(), msgSize,  time/max_iter*1000);
+            CkExit();
+        }
+    }
+
+};
+
+struct manyToMany : public CBase_manyToMany {
+       manyToMany_SDAG_CODE
+
+       int count;
+    int iter;
+    manyToManyMsg  **msgs;
+    int recvCnt;
+
+       manyToMany() {
+                __sdag_init();
+        iter = 0;
+        recvCnt = 0;
+               msgs = new manyToManyMsg*[numChares];
+               for(int i = 0; i < numChares; i++) {
+                       msgs[i] = new (msgSize) manyToManyMsg;
+               }
+
+               // reduction to the mainchare to signal that initialization is complete
+               contribute(CkCallback(CkReductionTarget(Main,manyToManyReady), mainProxy));
+       }
+
+       // Sends transpose messages to every other chare
+       void sendmanyToMany() {
+               
+        for(int i = thisIndex.y; i < thisIndex.y+numChares; i++) {
+                       int t = i % numChares;
+                       CkSetRefNum(msgs[t],iter);
+                       thisProxy(thisIndex.x, t).getmanyToMany(msgs[t]);
+               }
+       }
+
+       // Sends transpose messages to every other chare
+       void getmanyToMany() {
+       }
+
+    void processmanyToMany(manyToManyMsg *msg)
+    {
+        msgs[recvCnt] = msg;
+        recvCnt++;
+    }
+
+
+       void finish(){
+           recvCnt = 0;        
+        contribute(CkCallback(CkReductionTarget(Main,nextmanyToMany), mainProxy));
+       }
+
+       manyToMany(CkMigrateMessage* m) {}
+       ~manyToMany() {}
+
+};
+
+#include "manyToMany.def.h"
diff --git a/examples/charm++/manyToMany/manyToMany.ci b/examples/charm++/manyToMany/manyToMany.ci
new file mode 100644 (file)
index 0000000..fc2af12
--- /dev/null
@@ -0,0 +1,40 @@
+mainmodule manyToMany {
+
+       readonly CProxy_Main mainProxy;
+    readonly int max_iter;
+    readonly int numChares;
+    readonly int msgSize;
+
+       message manyToManyMsg {
+               char data[];
+       };
+
+       mainchare Main {
+               entry Main(CkArgMsg *m);
+               entry [reductiontarget] void manyToManyReady();
+               entry [reductiontarget] void nextmanyToMany();
+       };
+
+       array [2D] manyToMany {
+               entry manyToMany();
+        entry void sendmanyToMany();
+               entry void getmanyToMany(manyToManyMsg *m);
+       
+        entry void domanyToMany() {
+           
+            atomic {
+                sendmanyToMany();
+            }
+
+            for(count = 0; count < numChares; ++count){
+                when getmanyToMany[iter](manyToManyMsg *m) atomic {
+                    processmanyToMany(m);
+                }
+            }
+            atomic {
+                           iter++;
+                               finish();
+            }
+               };
+       };
+};