6 #define pvd CpvStaticDeclare
7 #define pvi CpvInitialize
9 static struct testdata
{
25 typedef struct message_
{
26 char core
[CmiMsgHeaderSizeBytes
];
35 static void fillMessage(Message
* msg
) {
37 size
= sizes
[msg
->idx
].size
+ sizeof(double);
38 items
= size
/ sizeof(double);
39 for (i
= 0; i
< items
; i
++) msg
->data
[i
] = i
+ 0x1234;
42 static void checkMessage(Message
* msg
) {
44 size
= sizes
[msg
->idx
].size
+ sizeof(double);
45 items
= size
/ sizeof(double);
46 for (i
= 0; i
< items
; i
++) {
47 if (msg
->data
[i
] != (i
+ 0x1234))
48 CmiAbort("[pingpong] Data corrupted. Run megacon !!\n");
53 typedef struct Time_
{
54 char core
[CmiMsgHeaderSizeBytes
];
63 pvd(double, starttime
);
65 pvd(double**, times
); /* stores times for all nbrs and sizes */
66 pvd(int*, nodeList
); /* stores nums of pes rank 0 on all nodes*/
75 pvd(int, numSizes
); /* how many test sizes exist */
78 pvd(int, timeHandler
);
79 pvd(int, nodeHandler
);
81 pvd(int, sizeHandler
);
82 pvd(int, iterHandler
);
83 pvd(int, bounceHandler
);
84 pvd(int, setupHandler
);
85 pvd(int, startHandler
);
87 pvd(char*, buffer_msgs
);
89 static void recvTime(TimeMessage
* msg
) {
94 CmiInitMsgHeader(m
.core
, sizeof(EmptyMsg
));
96 for (i
= 0; i
< CmiNumNodes(); i
++) {
97 if (i
== msg
->srcNode
) continue;
98 for (j
= 0; j
< pva(numSizes
); j
++) {
99 time
= *(msg
->data
+ i
* pva(numSizes
) + j
);
100 pva(gavg
)[j
] += time
;
101 if (time
> pva(gmax
)[j
]) {
103 pva(gmaxSrc
)[j
] = msg
->srcNode
;
104 pva(gmaxDest
)[j
] = i
;
106 if (time
< pva(gmin
)[j
]) {
108 pva(gminSrc
)[j
] = msg
->srcNode
;
109 pva(gminDest
)[j
] = i
;
113 if (pva(numRecv
) == CmiNumNodes()) {
114 for (j
= 0; j
< pva(numSizes
); j
++)
115 pva(gavg
)[j
] /= (CmiNumNodes() * (CmiNumNodes() - 1));
116 for (j
= 0; j
< pva(numSizes
); j
++) {
117 CmiPrintf("%d\t\t%le\n", sizes
[j
].size
, pva(gavg
)[j
]);
120 CmiPrintf("[pingpong] size=%d\tmaxTime=%le seconds\t[%d->%d]\n",
122 pva(gmax
)[j
],pva(gmaxSrc
)[j
],pva(gmaxDest
)[j
]);
123 CmiPrintf("[pingpong] size=%d\tminTime=%le seconds\t[%d->%d]\n",
125 pva(gmin
)[j
],pva(gminSrc
)[j
],pva(gminDest
)[j
]);
129 CmiSetHandler(&m
, pva(ack_handler
));
130 CmiSyncSend(0, sizeof(EmptyMsg
), &m
);
135 static void startNextNode(EmptyMsg
* msg
) {
137 CmiInitMsgHeader(m
.core
, sizeof(EmptyMsg
));
139 if ((CmiMyNode() + 1) != CmiNumNodes()) {
140 CmiSetHandler(&m
, pva(nbrHandler
));
141 CmiSyncSend(pva(nodeList
)[CmiMyNode() + 1], sizeof(EmptyMsg
), &m
);
145 static void startNextNbr(EmptyMsg
* msg
) {
150 /* CmiAssert(CmiMyPe()==0); */
152 CmiInitMsgHeader(m
.core
, sizeof(EmptyMsg
));
155 if (pva(nextNbr
) == CmiMyNode()) {
156 CmiSetHandler(&m
, pva(nbrHandler
));
157 CmiSyncSend(CmiMyPe(), sizeof(EmptyMsg
), &m
);
160 if (pva(nextNbr
) == CmiNumNodes()) {
162 CmiSetHandler(&m
, pva(nodeHandler
));
163 CmiSyncSend(CmiMyPe(), sizeof(EmptyMsg
), &m
);
164 size
= sizeof(TimeMessage
) + pva(numSizes
) * CmiNumNodes() * sizeof(double);
165 tm
= (TimeMessage
*)CmiAlloc(size
);
166 for (i
= 0; i
< CmiNumNodes(); i
++)
167 memcpy(tm
->data
+ i
* pva(numSizes
), pva(times
)[i
],
168 sizeof(double) * pva(numSizes
));
169 tm
->srcNode
= CmiMyNode();
170 CmiSetHandler(tm
, pva(timeHandler
));
171 CmiSyncSendAndFree(0, size
, tm
);
173 CmiSetHandler(&m
, pva(sizeHandler
));
174 CmiSyncSend(CmiMyPe(), sizeof(EmptyMsg
), &m
);
178 static void startNextSize(EmptyMsg
* msg
) {
183 /* CmiAssert(CmiMyPe()==0); */
185 CmiInitMsgHeader(m
.core
, sizeof(EmptyMsg
));
187 if (pva(nextSize
) == pva(numSizes
)) {
189 CmiSetHandler(&m
, pva(nbrHandler
));
190 CmiSyncSend(CmiMyPe(), sizeof(EmptyMsg
), &m
);
192 int size
= sizeof(Message
) + sizes
[pva(nextSize
)].size
;
195 (char*)malloc((sizes
[pva(nextSize
)].numiter
) * sizeof(Message
*));
196 for (i
= 0; i
< sizes
[pva(nextSize
)].numiter
; i
++) {
197 mm
= (Message
*)CmiAlloc(size
);
198 mm
->srcpe
= CmiMyPe();
199 mm
->idx
= pva(nextSize
);
200 CmiSetHandler(mm
, pva(bounceHandler
));
201 ((Message
**)pva(buffer_msgs
))[i
] = mm
;
203 mm
= (Message
*)CmiAlloc(size
);
204 mm
->srcpe
= CmiMyPe();
205 mm
->idx
= pva(nextSize
);
206 CmiSetHandler(mm
, pva(setupHandler
));
207 /* fillMessage(mm); */
208 CmiSyncSendAndFree(pva(nextNbr
), size
, mm
);
213 static void startNextIter(Message
* msg
) {
218 CmiInitMsgHeader(m
.core
, sizeof(EmptyMsg
));
219 if (pva(nextIter
) >= sizes
[pva(nextSize
)].numiter
) {
220 pva(endtime
) = CmiWallTimer();
221 /* checkMessage(msg); */
222 CmiAssert(CpvInitialized(starttime
));
224 CmiAssert(pva(nextNbr
) < CmiNumNodes());
225 CmiAssert(pva(nextNbr
) >= 0);
226 CmiAssert(pva(nextSize
) < pva(numSizes
));
227 CmiAssert(pva(nextSize
) >= 0);
229 free(pva(buffer_msgs
));
230 pva(buffer_msgs
) = 0;
232 pva(times
)[pva(nextNbr
)][pva(nextSize
)] =
233 (pva(endtime
) - pva(starttime
)) / (2.0 * sizes
[pva(nextSize
)].numiter
);
235 CmiSetHandler(&m
, pva(sizeHandler
));
236 CmiSyncSend(CmiMyPe(), sizeof(EmptyMsg
), &m
);
239 mm
= ((Message
**)pva(buffer_msgs
))[pva(nextIter
)];
240 mm
->iter
= pva(nextIter
);
241 /* CmiSetHandler(mm, pva(bounceHandler)); */
242 CmiSyncSendAndFree(pva(nextNbr
), sizeof(Message
) + sizes
[mm
->idx
].size
, mm
);
247 static void bounceMessage(Message
* msg
) {
249 int iter
= msg
->iter
;
250 mm
= *((Message
**)(pva(buffer_msgs
) + iter
* sizeof(char*)));
251 CmiSetHandler(mm
, pva(iterHandler
));
252 /* CmiAssert(msg->srcpe==0); */
253 CmiSyncSendAndFree(msg
->srcpe
, sizeof(Message
) + sizes
[msg
->idx
].size
, mm
);
256 static void setupMessage(Message
* msg
) {
260 int nextSize
= msg
->idx
;
261 size
= sizeof(Message
) + sizes
[nextSize
].size
;
262 pva(buffer_msgs
) = (char*)malloc((sizes
[nextSize
].numiter
) * sizeof(Message
*));
264 for (i
= 0; i
< sizes
[nextSize
].numiter
; i
++) {
265 mm
= (Message
*)CmiAlloc(size
);
266 mm
->srcpe
= CmiMyPe();
267 CmiSetHandler(mm
, pva(iterHandler
));
268 /* mm->idx = pva(nextSize); */
269 /* *((Message**)buffer_msgs+i*sizeof(char*)) = mm; */
270 ((Message
**)pva(buffer_msgs
))[i
] = mm
;
272 mm
= (Message
*)CmiAlloc(size
);
273 mm
->srcpe
= CmiMyPe();
275 CmiSetHandler(mm
, pva(startHandler
));
276 /* fillMessage(mm); */
277 /* CmiAssert(msg->srcpe == 0); */
278 CmiSyncSendAndFree(msg
->srcpe
, size
, mm
);
281 static void startMessage(Message
* msg
) {
287 CmiSetHandler(&m
, pva(iterHandler
));
288 /* fillMessage(mm); */
289 pva(starttime
) = CmiWallTimer();
290 CmiSyncSend(CmiMyPe(), sizeof(EmptyMsg
), &m
);
294 size
= sizeof(Message
) + sizes
[pva(nextSize
)].size
;
295 mm
= (Message
*)CmiAlloc(size
);
296 mm
->srcpe
= CmiMyPe();
297 mm
->idx
= pva(nextSize
);
298 CmiSetHandler(mm
, pva(iterHandler
));
299 /* fillMessage(mm); */
300 pva(starttime
) = CmiWallTimer();
301 CmiSyncSendAndFree(mm
->srcpe
, size
, mm
);
306 void pingpong_cachemiss_init(void) {
308 CmiInitMsgHeader(m
.core
, sizeof(EmptyMsg
));
310 if (CmiNumNodes() == 1) {
311 CmiPrintf("[pingpong] This benchmark requires > 1 nodes.\n");
312 CmiSetHandler(&m
, pva(ack_handler
));
313 CmiSyncSend(0, sizeof(EmptyMsg
), &m
);
316 CmiSetHandler(&m
, pva(nbrHandler
));
317 CmiSyncSend(0, sizeof(EmptyMsg
), &m
);
320 void pingpong_cachemiss_moduleinit(void) {
330 pvi(double, starttime
);
331 pva(starttime
) = 0.0;
332 pvi(double, endtime
);
335 for (i
= 0; sizes
[i
].size
!= (-1); i
++)
338 pvi(double**, times
);
339 pva(times
) = (double**)malloc(CmiNumNodes() * sizeof(double*));
340 for (i
= 0; i
< CmiNumNodes(); i
++)
341 pva(times
)[i
] = (double*)malloc(pva(numSizes
) * sizeof(double));
342 for (i
= 0; i
< CmiNumNodes(); i
++)
343 for (j
= 0; j
< pva(numSizes
); j
++) pva(times
)[i
][j
] = 0.0;
345 pva(nodeList
) = (int*)malloc(CmiNumNodes() * sizeof(int));
346 for (i
= 0; i
< CmiNumNodes(); i
++) pva(nodeList
)[i
] = CmiNodeFirst(i
);
348 pva(gavg
) = (double*)malloc(sizeof(double) * pva(numSizes
));
350 pva(gmax
) = (double*)malloc(sizeof(double) * pva(numSizes
));
352 pva(gmin
) = (double*)malloc(sizeof(double) * pva(numSizes
));
354 pva(gmaxSrc
) = (int*)malloc(sizeof(int) * pva(numSizes
));
356 pva(gmaxDest
) = (int*)malloc(sizeof(int) * pva(numSizes
));
358 pva(gminSrc
) = (int*)malloc(sizeof(int) * pva(numSizes
));
360 pva(gminDest
) = (int*)malloc(sizeof(int) * pva(numSizes
));
361 for (i
= 0; i
< pva(numSizes
); i
++) {
364 pva(gmin
)[i
] = 1000000000.0;
366 pva(gmaxDest
)[i
] = 0;
368 pva(gminDest
)[i
] = 0;
370 pvi(int, timeHandler
);
371 pva(timeHandler
) = CmiRegisterHandler((CmiHandler
)recvTime
);
372 pvi(int, nodeHandler
);
373 pva(nodeHandler
) = CmiRegisterHandler((CmiHandler
)startNextNode
);
374 pvi(int, nbrHandler
);
375 pva(nbrHandler
) = CmiRegisterHandler((CmiHandler
)startNextNbr
);
376 pvi(int, sizeHandler
);
377 pva(sizeHandler
) = CmiRegisterHandler((CmiHandler
)startNextSize
);
378 pvi(int, iterHandler
);
379 pva(iterHandler
) = CmiRegisterHandler((CmiHandler
)startNextIter
);
380 pvi(int, bounceHandler
);
381 pva(bounceHandler
) = CmiRegisterHandler((CmiHandler
)bounceMessage
);
382 pvi(int, setupHandler
);
383 pva(setupHandler
) = CmiRegisterHandler((CmiHandler
)setupMessage
);
384 pvi(int, startHandler
);
385 pva(startHandler
) = CmiRegisterHandler((CmiHandler
)startMessage
);
387 pvi(char *, buffer_msgs
);
388 pva(buffer_msgs
) = 0;