Fixing bug in linear.C. The benchmark was not storing the bucketsize correctly.
[charm.git] / tests / charm++ / commtest / commlib_stream / linear.C
1
2 /************************
3      Benchmark to demostrate the performance of streaming communication by
4      having several simulteneous rings of messages among the array elements.
5
6      - Sameer Kumar (01/20/05)
7
8 *******************************/
9
10
11 #include <stdio.h>
12 #include "hello.decl.h"
13 #include "StreamingStrategy.h"
14 #include "MeshStreamingStrategy.h"
15
16 /*readonly*/ CProxy_Main mainProxy;
17 /*readonly*/ int nElements;
18
19 int NUM_MSGS;
20
21 #define TEST_HI 4001
22 #define MAX_COUNT 2000
23 int bucketSize = 100;
24 #define MAX_PER_ITR 2*bucketSize 
25
26 ComlibInstanceHandle ss_inst;  //basic streaming strategy
27 ComlibInstanceHandle mss_inst;  //mesh streaming strategy
28 ComlibInstanceHandle samp_inst; //streaming with short message packing
29 ComlibInstanceHandle dummy_inst; //streaming with short message packing
30
31 /*mainchare*/
32 class Main : public Chare
33 {
34     double startTime;
35     int recv_count;
36     int step_count;
37     CProxy_Hello arr;
38
39 public:
40     Main(CkArgMsg* m)
41     {
42         //Process command-line arguments
43         nElements=5;
44         if(m->argc >1 ) nElements=atoi(m->argv[1]);
45         if(m->argc > 2 ) bucketSize= atoi(m->argv[2]);
46         delete m;
47         
48         recv_count = 0;
49         step_count = 0;
50         
51         //Start the computation
52         CkPrintf("Running Hello on %d processors for %d elements with bucket %d\n",
53                  CkNumPes(),nElements, bucketSize);
54         mainProxy = thishandle;
55         
56         arr = CProxy_Hello::ckNew(nElements);
57         
58         StreamingStrategy *strat=new StreamingStrategy(1,bucketSize);
59         StreamingStrategy *sstrat=new StreamingStrategy(1,bucketSize);
60
61         MeshStreamingStrategy *mstrat=new 
62           MeshStreamingStrategy(1, bucketSize);
63         
64         sstrat->enableShortArrayMessagePacking();
65         
66         //mstrat->enableShortArrayMessagePacking();
67         
68         ss_inst = CkGetComlibInstance();
69         mss_inst = CkGetComlibInstance();
70         samp_inst = CkGetComlibInstance();
71
72         ss_inst.setStrategy(strat); 
73         mss_inst.setStrategy(mstrat); 
74         samp_inst.setStrategy(sstrat);         
75
76         startTime=CkWallTimer();
77         CkPrintf("Starting ring...\n");
78         
79         arr.start();
80         step_count ++;
81     };
82
83     void done(void) {
84         recv_count ++;
85         
86         if(recv_count == CkNumPes()) {
87             char stype[256];
88
89             if(step_count == 1)
90                 sprintf(stype, "");
91             else if(step_count == 2)
92                 sprintf(stype, "Mesh ");
93             else if(step_count == 3)
94                 sprintf(stype, "SAMP ");
95
96             CkPrintf("%sStreaming Performance %g us/msg on %d pes and %d elements\n", 
97                      stype, 
98                      (CkWallTimer()-startTime)*1e6/(MAX_COUNT * MAX_PER_ITR), 
99                      CkNumPes(), nElements);
100
101             if(step_count < 3) {
102                 arr.start();
103                 step_count ++;
104                 recv_count = 0;
105                 startTime = CkWallTimer();
106             }
107             else {
108                 CkExit();
109             }
110         }
111     };
112 };
113
114 /*array [1D]*/
115 class Hello : public CBase_Hello 
116 {
117     int recv_count;
118     int step_count;
119 public:
120     Hello() {
121         recv_count = 0;
122         step_count = 0;
123     }
124     
125     Hello(CkMigrateMessage *m) {}
126     
127     void start() {
128         if(step_count == 0)
129             ss_inst.beginIteration();
130         else if(step_count == 1)            
131             mss_inst.beginIteration();
132         else
133             samp_inst.beginIteration();            
134         
135         step_count++;
136
137         recv_count = 0;        
138         for(int count = 0; count < MAX_PER_ITR; count++)
139             SayHi(TEST_HI, 0);
140     }
141     
142     void SayHi(int hiNo, int hcount) {
143         
144         CkAssert(hiNo >= TEST_HI);
145         
146         // CkPrintf("Hi[%d] from element %d\n",hiNo,thisIndex);
147         CProxy_Hello array_proxy = thisProxy;
148         ComlibDelegateProxy(&array_proxy);
149         
150         int next = thisIndex+1;
151         if(next >= nElements)
152             next = 0;
153         
154         if(hcount < MAX_COUNT)
155             //Pass the hello on:
156             array_proxy[next].SayHi(hiNo+1, hcount+1);
157         else if(recv_count == MAX_PER_ITR-1) 
158             mainProxy.done();    
159         else
160             recv_count ++;
161     }
162 };
163
164 #include "hello.def.h"