Fixing bug in linear.C. The benchmark was not storing the bucketsize correctly.
[charm.git] / tests / charm++ / commtest / commlib_stream / hello.C
1
2 #include <stdio.h>
3 #include "hello.decl.h"
4 #include "StreamingStrategy.h"
5 #include "MeshStreamingStrategy.h"
6
7 /*readonly*/ CProxy_Main mainProxy;
8 /*readonly*/ int nElements;
9
10 #define TEST_HI 4001
11 #define MAX_COUNT 200
12 #define NUM_RINGS 200 
13
14 ComlibInstanceHandle ss_inst;
15 ComlibInstanceHandle mss_inst;
16 ComlibInstanceHandle samp_inst;
17 ComlibInstanceHandle dummy_inst;
18
19 int bucketSize = 400;
20
21 /*mainchare*/
22 class Main : public Chare
23 {
24     double startTime;
25     int recv_count;
26 public:
27     Main(CkArgMsg* m)
28     {
29         //Process command-line arguments
30         nElements=5;
31         if(m->argc >1 ) nElements=atoi(m->argv[1]);
32         delete m;
33         
34         recv_count = 0;
35
36         //Start the computation
37         CkPrintf("Running Hello on %d processors for %d elements\n",
38                  CkNumPes(),nElements);
39         mainProxy = thishandle;
40         
41         CProxy_Hello arr = CProxy_Hello::ckNew(nElements);
42         
43         StreamingStrategy *strat=new StreamingStrategy(1,bucketSize);
44         MeshStreamingStrategy *mstrat=new MeshStreamingStrategy(1,bucketSize);
45         
46         //strat->enableShortArrayMessagePacking();
47         //strat->disableIdleFlush();
48         
49         mstrat->enableShortArrayMessagePacking();
50         
51         ComlibInstanceHandle cinst = CkGetComlibInstance();
52         cinst.setStrategy(strat); 
53         
54         //ComlibInstanceHandle cinst1 = CkGetComlibInstance();
55         
56         //cinst1.setStrategy(mstrat);
57         
58         startTime=CkWallTimer();
59         CkPrintf("Starting ring...\n");
60         
61         arr.start();
62     };
63     
64     void done(void)
65     {
66         recv_count ++;
67         
68         if(recv_count == CkNumPes()) {
69             CkPrintf("All done: %d elements in %f seconds\n", nElements,
70                      CkWallTimer()-startTime);
71             CkExit();
72         }
73     };
74 };
75
76 /*array [1D]*/
77 class Hello : public CBase_Hello 
78 {
79     int c;
80     
81 public:
82     Hello() {
83         c = 0;
84     }
85     
86     Hello(CkMigrateMessage *m) {}
87     
88     void start() {
89         for(int count = 0; count < NUM_RINGS; count++)
90             SayHi(TEST_HI, 0);
91     }
92     
93     void SayHi(int hiNo, int hcount) {
94         
95         CkAssert(hiNo >= TEST_HI);
96         
97         // CkPrintf("Hi[%d] from element %d\n",hiNo,thisIndex);
98         CProxy_Hello array_proxy = thisProxy;
99         ComlibDelegateProxy(&array_proxy);
100         
101         int next = thisIndex+1;
102         if(next >= nElements)
103             next = 0;
104         
105         if(hcount < MAX_COUNT)
106             //Pass the hello on:
107             array_proxy[next].SayHi(hiNo+1, hcount+1);
108         else{
109             c++;
110             if (c == NUM_RINGS) mainProxy.done();    
111         }
112     }
113 };
114
115 #include "hello.def.h"