AllReduce bug fixed, new benchmark added
authorEhsan Totoni <totoni2@illinois.edu>
Sun, 3 Jul 2011 17:34:19 +0000 (12:34 -0500)
committerEhsan Totoni <totoni2@illinois.edu>
Sun, 3 Jul 2011 17:34:19 +0000 (12:34 -0500)
examples/charm++/AllReduce/AllReduce [deleted file]
examples/charm++/AllReduce/bench/AllReduce.C [new file with mode: 0644]
examples/charm++/AllReduce/bench/AllReduce.ci [new file with mode: 0644]
examples/charm++/AllReduce/bench/AllReduce.h [new file with mode: 0644]
examples/charm++/AllReduce/bench/Makefile [new file with mode: 0644]
src/ck-core/ckreduction.h

diff --git a/examples/charm++/AllReduce/AllReduce b/examples/charm++/AllReduce/AllReduce
deleted file mode 100755 (executable)
index 1b1dbf1..0000000
Binary files a/examples/charm++/AllReduce/AllReduce and /dev/null differ
diff --git a/examples/charm++/AllReduce/bench/AllReduce.C b/examples/charm++/AllReduce/bench/AllReduce.C
new file mode 100644 (file)
index 0000000..a0bc01d
--- /dev/null
@@ -0,0 +1,46 @@
+#include <stdio.h>
+#include "AllReduce.decl.h"
+#include <math.h>
+
+
+/*readonly*/ CProxy_main mainProxy;
+/*readonly*/ int units;
+/*readonly*/ int allredSize;
+#include "AllReduce.h"
+
+/*mainchare*/
+
+main::main(CkArgMsg* m)
+  {
+    //Process command-line arguments
+    //Start the computation
+
+    mainProxy = thishandle;
+    if(m->argc<2)
+      {
+             CkPrintf("Needs number of array elements\n");
+       CkExit();
+      }
+    units=atoi(m->argv[1]);
+    // 4 MB size
+    allredSize= 4194304; //atoi(m->argv[2]);
+    baseSize = 262144;
+    currentSize = baseSize;
+    sizeInd = 0;
+    numItr = 10;
+    sizesNo = 5;
+    timeForEach = new double[sizesNo];
+    iterNo = 0;
+    for(int i=0; i<sizesNo; i++)
+           timeForEach[i] = 0.0;
+    arr = CProxy_AllReduce::ckNew(thisProxy, units);
+
+    CkPrintf("AllReduce for %d pes on %d units for %d size\n",
+            CkNumPes(),units,allredSize);
+
+    arr.init();
+    startTime = CmiWallTimer();
+    arr.dowork(baseSize);
+  }
+
+#include "AllReduce.def.h"
diff --git a/examples/charm++/AllReduce/bench/AllReduce.ci b/examples/charm++/AllReduce/bench/AllReduce.ci
new file mode 100644 (file)
index 0000000..af1bb86
--- /dev/null
@@ -0,0 +1,16 @@
+mainmodule AllReduce {
+  readonly int units;
+  readonly int allredSize;
+
+  mainchare main {
+    entry main(CkArgMsg *m);
+    entry void done();
+  };
+
+  array [1D] AllReduce {
+    entry AllReduce(CProxy_main);
+    entry void init();
+    entry void dowork(int);    
+    entry void report(CkReductionMsg *msg);
+  };           
+}
diff --git a/examples/charm++/AllReduce/bench/AllReduce.h b/examples/charm++/AllReduce/bench/AllReduce.h
new file mode 100644 (file)
index 0000000..c607033
--- /dev/null
@@ -0,0 +1,102 @@
+//! main char object.  Creates array, handles command line, catches reduction.
+#include <ctime>
+
+class main : public CBase_main
+{
+private:
+  CProxy_AllReduce arr;
+       double startTime;
+       int sizeInd;
+       double *timeForEach;
+       int iterNo;
+       int baseSize;
+       int sizesNo;
+       int numItr;
+       int currentSize;
+public:
+
+  main(CkArgMsg* m);
+
+  void done()
+  {
+         static int checkIn=0;
+         checkIn++;
+         if (checkIn==units) {
+                 checkIn = 0;
+                 // CkPrintf("All done in %lf seconds\n",(CmiWallTimer()-startTime));
+                 double newTime= CmiWallTimer();
+                 iterNo++;
+                 timeForEach[sizeInd] += newTime-startTime;
+                 if(iterNo==numItr)
+                 {
+                         timeForEach[sizeInd]/=numItr;
+                         sizeInd++;
+                         if(sizeInd==sizesNo){
+                                 print();
+                               CkExit();  
+                         }
+                         iterNo=0;
+                         currentSize *= 2;
+
+                 }
+                       startTime = CmiWallTimer();
+                       arr.dowork(currentSize);
+         }
+  }
+  void print(){
+         int sizeA = baseSize;
+         for(int i=0; i<sizesNo; i++)
+         {
+                 CkPrintf("size:%d time:%lf\n",sizeA, timeForEach[i]);
+                 sizeA *= 2;
+         }
+  }
+
+};
+
+
+//! AllReduce. A small example which does nothing useful, but provides an extremely simple, yet complete, use of a normal reduction case.
+/** The reduction performs a summation i+k1 i+k2 for i=0 to units
+ */
+class AllReduce : public CBase_AllReduce
+{
+ private:
+       CProxy_main mainProxy;
+       double* myData;
+ public:
+
+       AllReduce(CProxy_main ma)   { mainProxy=ma;  }
+
+  AllReduce(CkMigrateMessage *m) {};
+
+       void init()
+       {
+                               myData = new double[allredSize/(sizeof(double))];
+                                               for (int i=0; i<allredSize/sizeof(double); i++) {
+                                                                               myData[i] = (double)i;
+                                                                                               }
+       }
+
+  //! add our index to the global floats and contribute the result.
+  void dowork (int redSize)
+    {
+       CkCallback cb(CkIndex_AllReduce::report(NULL),  thisProxy);
+      contribute(redSize,myData,CkReduction::sum_double,cb); 
+    }
+  //! catches the completed reduction results.
+  void report(CkReductionMsg *msg)
+  {
+//       int reducedArrSize=msg->getSize()/sizeof(double);
+//       double *output=(double *)msg->getData();
+//       CkPrintf("done %d\n", thisIndex);
+//       for(int i=0;i<reducedArrSize;i++) {
+//               if (output[i]!=i*units) {
+//                       CkPrintf("result error!\n");
+//               }
+//       }
+         mainProxy.done();
+         delete msg;
+  }
+
+};
+
diff --git a/examples/charm++/AllReduce/bench/Makefile b/examples/charm++/AllReduce/bench/Makefile
new file mode 100644 (file)
index 0000000..3786b02
--- /dev/null
@@ -0,0 +1,23 @@
+CHARMC=../../../../bin/charmc $(OPTS) $(MOPTS) 
+
+OBJS = AllReduce.o
+
+all: AllReduce
+
+AllReduce: $(OBJS)
+       $(CHARMC) -language charm++ -o AllReduce $(OBJS) 
+
+AllReduce.decl.h: AllReduce.ci
+       $(CHARMC)  AllReduce.ci
+
+clean:
+       rm -f *.decl.h *.def.h conv-host *.o AllReduce charmrun *.log *.sum *.sts charmrun.exe AllReduce.exe AllReduce.pdb AllReduce.ilk
+
+AllReduce.o: AllReduce.C AllReduce.decl.h AllReduce.h
+       $(CHARMC) -c AllReduce.C
+
+test: all
+       ./charmrun ./AllReduce 20 100000 +p4 $(TESTOPTS)
+
+bgtest: all
+       ./charmrun ./AllReduce 20 100000 +p4 +x2 +y2 +z2
index 5cf11b065054ff33e6b3f15589e0e12b1c444f3f..7e5df3935c2e6cd5058018654088a1d86fe6c969 100644 (file)
@@ -430,7 +430,7 @@ public:
        // recieve an allreduce message
        void allreduce_recieve(CkReductionMsg* msg)
        {
-               allred_msgs.enq(msg);
+               // allred_msgs.enq(msg);
                fragsRecieved++;
                if(fragsRecieved==1)
                {
@@ -439,8 +439,12 @@ public:
                memcpy(data+msg->fragNo*FRAG_SIZE, msg->data, msg->dataSize);
                size += msg->dataSize;
                
-               if(fragsRecieved==msg->nFrags)
-                       cb.send(size, (void*)data);
+               if(fragsRecieved==msg->nFrags) {
+                       CkReductionMsg* ret = CkReductionMsg::buildNew(size, data);
+                       cb.send(ret);
+                       fragsRecieved=0; size=0;
+                       delete [] data;
+               }
                
        }
        // TODO: check for same reduction
@@ -448,7 +452,7 @@ public:
        int size;
        char* data;
        int fragsRecieved;
-       CkMsgQ<CkReductionMsg> allred_msgs;
+       // CkMsgQ<CkReductionMsg> allred_msgs;
 };
 #endif // _PIPELINED_ALLREDUCE_