minor fix for migration overhead when iteration is odd
[charm.git] / tests / charm++ / migrate / migrateHello.C
1 #include <stdio.h>
2 #include "migrateHello.decl.h"
3
4 /*readonly*/ CProxy_Main mainProxy;
5 /*readonly*/ int numIterations;
6
7 /*mainchare*/
8 class Main : public CBase_Main
9 {
10     CProxy_MigrateHello arr;
11 public:
12   Main(CkArgMsg* m)
13   {
14     //Process command-line arguments
15     numIterations=1000;
16     if(m->argc >1 ) numIterations=atoi(m->argv[1]);
17     delete m;
18
19     //Start the computation
20     CkPrintf("Running MigrateHello on %d processors for %d iterations \n",
21              CkNumPes(),numIterations);
22     mainProxy = thisProxy;
23     arr =  CProxy_MigrateHello::ckNew(1);
24     arr[0].SayHi(0);
25   };
26
27 };
28
29 double startTimer;
30 /*array [1D]*/
31 class MigrateHello : public CBase_MigrateHello
32 {
33 public:
34   MigrateHello()
35   {
36     //CkPrintf("MigrateHello %d created\n",thisIndex);
37   }
38
39   MigrateHello(CkMigrateMessage *m) {}
40   
41   void SayHi(int hiNo)
42   {
43       if(hiNo <2 )
44           startTimer = CkWallTimer();
45       else if(hiNo >= numIterations)
46       {
47           double time = CkWallTimer() - startTimer;
48           CkPrintf(" migration cost total : %f sec single migration cost: %f us\n", time, time/(hiNo-1)*1000000); 
49           CkExit();
50       }
51       //CkPrintf("executing  %d  %d\n", CkMyPe(), hiNo);
52       thisProxy[thisIndex].SayHi(hiNo+1);
53       migrateMe(1-CkMyPe());
54   }
55 };
56
57 #include "migrateHello.def.h"