added example of alltoall
authorYanhuaSun <sun51@illinois.edu>
Fri, 27 Jul 2012 04:18:54 +0000 (23:18 -0500)
committerYanhuaSun <sun51@illinois.edu>
Fri, 27 Jul 2012 04:18:54 +0000 (23:18 -0500)
examples/charm++/allToAll/Makefile [new file with mode: 0644]
examples/charm++/allToAll/allToAll.C [new file with mode: 0644]
examples/charm++/allToAll/allToAll.ci [new file with mode: 0644]

diff --git a/examples/charm++/allToAll/Makefile b/examples/charm++/allToAll/Makefile
new file mode 100644 (file)
index 0000000..ccb7763
--- /dev/null
@@ -0,0 +1,21 @@
+CHARMC=../../../bin/charmc $(OPTS)
+
+OBJS = allToAll.o
+
+all: allToAll
+
+allToAll: $(OBJS)
+       $(CHARMC) -language charm++ -o allToAll $(OBJS)
+
+allToAll.decl.h: allToAll.ci
+       $(CHARMC)  allToAll.ci
+
+clean:
+       rm -f *.decl.h *.def.h conv-host *.o allToAll charmrun
+
+allToAll.o: allToAll.C allToAll.decl.h
+       $(CHARMC) -c allToAll.C
+
+test: all
+       ./charmrun allToAll +p4 1024 
+
diff --git a/examples/charm++/allToAll/allToAll.C b/examples/charm++/allToAll/allToAll.C
new file mode 100644 (file)
index 0000000..bcb8cdf
--- /dev/null
@@ -0,0 +1,116 @@
+#include "allToAll.decl.h"
+
+/*readonly*/ CProxy_Main mainProxy;
+/*readonly*/ int numChares;
+/*readonly*/ int msgSize;
+/*readonly*/ int max_iter;
+
+struct allToAllMsg : public CMessage_allToAllMsg {
+  char *data;
+};
+
+struct Main : public CBase_Main {
+       double start;
+       CProxy_allToAll allToAllProxy;
+    int         iter;
+
+       Main(CkArgMsg* m) {
+
+        max_iter = 1000;
+        numChares = CkNumPes();
+        msgSize = 1024;
+               // 3D allToAll 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 allToAll chares to do the calculation
+               allToAllProxy = CProxy_allToAll::ckNew(numChares);
+       }
+
+       void allToAllReady() {
+               start = CkWallTimer();
+               // Broadcast the 'go' signal to the allToAll chare array
+               allToAllProxy.doAllToAll();
+        
+       }
+
+       void nextallToAll() {
+               
+        iter++;
+        if(iter < max_iter)
+        {
+            allToAllProxy.doAllToAll();
+        }else
+        {
+            double time = CkWallTimer() - start;
+            CkPrintf("allToAll on %d cores for msg size: %d per iteration:%f ms\n",
+                CkNumPes(), msgSize,  time/max_iter*1000);
+            CkExit();
+        }
+    }
+
+};
+
+struct allToAll : public CBase_allToAll {
+       allToAll_SDAG_CODE
+
+       int count;
+    int iter;
+    allToAllMsg  **msgs;
+    int recvCnt;
+
+       allToAll() {
+                __sdag_init();
+        iter = 0;
+        recvCnt = 0;
+               msgs = new allToAllMsg*[numChares];
+               for(int i = 0; i < numChares; i++) {
+                       msgs[i] = new (msgSize) allToAllMsg;
+               }
+
+               // reduction to the mainchare to signal that initialization is complete
+               contribute(CkCallback(CkReductionTarget(Main,allToAllReady), mainProxy));
+       }
+
+       // Sends transpose messages to every other chare
+       void sendAllToAll() {
+               
+        for(int i = thisIndex; i < thisIndex+numChares; i++) {
+                       int t = i % numChares;
+                       CkSetRefNum(msgs[t],iter);
+                       thisProxy[t].getAllToAll(msgs[t]);
+               }
+       }
+
+       // Sends transpose messages to every other chare
+       void getAllToAll() {
+       }
+
+    void processAllToAll(allToAllMsg *msg)
+    {
+        msgs[recvCnt] = msg;
+        recvCnt++;
+    }
+
+
+       void finish(){
+           recvCnt = 0;        
+        contribute(CkCallback(CkReductionTarget(Main,nextallToAll), mainProxy));
+       }
+
+       allToAll(CkMigrateMessage* m) {}
+       ~allToAll() {}
+
+};
+
+#include "allToAll.def.h"
diff --git a/examples/charm++/allToAll/allToAll.ci b/examples/charm++/allToAll/allToAll.ci
new file mode 100644 (file)
index 0000000..c1b0cac
--- /dev/null
@@ -0,0 +1,40 @@
+mainmodule allToAll {
+
+       readonly CProxy_Main mainProxy;
+    readonly int max_iter;
+    readonly int numChares;
+    readonly int msgSize;
+
+       message allToAllMsg {
+               char data[];
+       };
+
+       mainchare Main {
+               entry Main(CkArgMsg *m);
+               entry [reductiontarget] void allToAllReady();
+               entry [reductiontarget] void nextallToAll();
+       };
+
+       array [1D] allToAll {
+               entry allToAll();
+        entry void sendAllToAll();
+               entry void getAllToAll(allToAllMsg *m);
+       
+        entry void doAllToAll() {
+           
+            atomic {
+                sendAllToAll();
+            }
+
+            for(count = 0; count < numChares; ++count){
+                when getAllToAll[iter](allToAllMsg *m) atomic {
+                    processAllToAll(m);
+                }
+            }
+            atomic {
+                           iter++;
+                               finish();
+            }
+               };
+       };
+};