added a point-point broadcast example
authorYanhuaSun <sun51@illinois.edu>
Tue, 27 Dec 2011 06:07:45 +0000 (00:07 -0600)
committerYanhuaSun <sun51@illinois.edu>
Tue, 27 Dec 2011 06:07:45 +0000 (00:07 -0600)
tests/charm++/broadcast/Makefile [new file with mode: 0644]
tests/charm++/broadcast/broadcast.C [new file with mode: 0644]
tests/charm++/broadcast/broadcast.ci [new file with mode: 0644]

diff --git a/tests/charm++/broadcast/Makefile b/tests/charm++/broadcast/Makefile
new file mode 100644 (file)
index 0000000..e368d86
--- /dev/null
@@ -0,0 +1,32 @@
+SRC=../../../src
+CHARMC=../../../bin/charmc $(OPTS)
+
+OBJS = broadcast.o
+
+all:   pgm
+
+pgm: $(OBJS)
+       $(CHARMC) -language charm++ -o pgm $(OBJS)
+
+cifiles: broadcast.ci
+       $(CHARMC)  broadcast.ci
+       touch cifiles
+
+clean:
+       rm -f *.decl.h *.def.h conv-host *.o pgm charmrun cifiles pgm.exe pgm.pdb pgm.ilk
+
+broadcast.o: broadcast.C cifiles
+       $(CHARMC) -I$(SRC)/conv-core broadcast.C
+
+test: all
+       @echo "Intra-processor broadcast.."
+       ./charmrun ./pgm +p1 $(TESTOPTS)
+       @echo "Inter-processor broadcast.."
+       ./charmrun ./pgm +p2 $(TESTOPTS)
+
+bgtest: all
+       @echo "Intra-processor broadcast.."
+       ./charmrun ./pgm +p1 +x1 +y1 +z1
+       @echo "Inter-processor broadcast.."
+       ./charmrun ./pgm +p2 +x2 +y1 +z1
+
diff --git a/tests/charm++/broadcast/broadcast.C b/tests/charm++/broadcast/broadcast.C
new file mode 100644 (file)
index 0000000..7cb98ad
--- /dev/null
@@ -0,0 +1,113 @@
+#include <string.h> // for strlen, and strcmp
+#include <charm++.h>
+
+#define NITER 1000
+#define PAYLOAD 100
+
+#include "broadcast.decl.h"
+class PingMsg : public CMessage_PingMsg
+{
+  public:
+    char *x;
+
+};
+
+CProxy_main mainProxy;
+int iterations;
+int payload;
+
+class main : public CBase_main
+{
+  int phase;
+  CProxy_Ping1 arr1;
+public:
+  main(CkMigrateMessage *m) {}
+  main(CkArgMsg* m)
+  {
+
+    iterations=NITER;
+    payload=PAYLOAD;
+    if(m->argc>1)
+      payload=atoi(m->argv[1]);
+    if(m->argc>2)
+      iterations=atoi(m->argv[2]);
+    if(m->argc>3)
+      CkPrintf("Usage: pgm +pN [payload] [iterations]\n Where N [1-2], payload (default %d) is integer >0 iterations (default %d) is integer >0 ", PAYLOAD, NITER);
+    CkPrintf("broadcast with payload: %d iterations: %d\n", payload,iterations);
+    mainProxy = thishandle;
+    phase = 0;
+    arr1 = CProxy_Ping1::ckNew(CkNumPes());
+    phase=0;
+    mainProxy.maindone();
+    delete m;
+  }
+
+  void maindone(void)
+  {
+    switch(phase++) {
+      case 0:
+       arr1[0].start();
+    break;
+      default:
+    CkExit();
+    }
+  }
+};
+
+
+class Ping1 : public CBase_Ping1
+{
+  CProxy_Ping1 *pp;
+  int niter, ack;
+  double start_time, end_time;
+public:
+  Ping1()
+  {
+    pp = new CProxy_Ping1(thisArrayID);
+    niter = 0;
+  }
+  Ping1(CkMigrateMessage *m) {}
+  void start(void)
+  {
+      int i;
+      ack = 0;
+      for(i=1; i<CkNumPes(); i++)
+      {
+          (*pp)[i].recv(new (payload) PingMsg);
+      }
+    start_time = CkWallTimer();
+  }
+
+  void back(PingMsg *msg)
+  {
+      int i;
+    ack++;
+    if(ack == CkNumPes()-1)
+    {
+        niter++;
+        if(niter==iterations) {
+            end_time = CkWallTimer();
+            CkPrintf("Time for 1D Arrays broadcast and reduction is %lf us\n",
+                 1.0e6*(end_time-start_time)/iterations);
+
+            //mainProxy.maindone();
+            niter=0;
+            start_time = CkWallTimer();
+            mainProxy.maindone();
+        }else
+        {
+            for(i=1; i<CkNumPes(); i++)
+            {
+                (*pp)[i].recv(new (payload) PingMsg);
+            }
+            ack =0;
+        }
+    }
+  }
+  void recv(PingMsg *msg)
+  {
+        (*pp)[0].back(msg);
+  }
+};
+
+#include "broadcast.def.h"
diff --git a/tests/charm++/broadcast/broadcast.ci b/tests/charm++/broadcast/broadcast.ci
new file mode 100644 (file)
index 0000000..9f1f71b
--- /dev/null
@@ -0,0 +1,17 @@
+mainmodule broadcast {
+  readonly CProxy_main mainProxy;
+  readonly int iterations;
+  readonly int payload;
+  mainchare main {
+    entry main();
+    entry void maindone(void);
+  };
+  message PingMsg{char x[];};
+
+  array [1D] Ping1 {
+    entry Ping1();
+    entry void start(void);
+    entry void recv(PingMsg *);
+    entry void back(PingMsg *);
+  };           
+};