6 #define pvd CpvStaticDeclare
7 #define pvi CpvInitialize
9 static struct testdata
{
25 typedef struct message_
{
26 char core
[CmiMsgHeaderSizeBytes
];
32 static void fillMessage(Message
* msg
) {
34 size
= sizes
[msg
->idx
].size
+ sizeof(double);
35 items
= size
/ sizeof(double);
36 for (i
= 0; i
< items
; i
++) msg
->data
[i
] = i
+ 0x1234;
39 static void checkMessage(Message
* msg
) {
41 size
= sizes
[msg
->idx
].size
+ sizeof(double);
42 items
= size
/ sizeof(double);
43 for (i
= 0; i
< items
; i
++) {
44 if (msg
->data
[i
] != (i
+ 0x1234))
45 CmiAbort("[pingpong] Data corrupted. Run megacon !!\n");
49 typedef struct Time_
{
50 char core
[CmiMsgHeaderSizeBytes
];
59 pvd(double, starttime
);
61 pvd(double**, times
); /* stores times for all nbrs and sizes */
62 pvd(int*, nodeList
); /* stores nums of pes rank 0 on all nodes*/
71 pvd(int, numSizes
); /* how many test sizes exist */
74 pvd(int, timeHandler
);
75 pvd(int, nodeHandler
);
77 pvd(int, sizeHandler
);
78 pvd(int, iterHandler
);
79 pvd(int, bounceHandler
);
81 static void recvTime(TimeMessage
* msg
) {
86 CmiInitMsgHeader(m
.core
, sizeof(EmptyMsg
));
88 for (i
= 0; i
< CmiNumPes(); i
++) {
89 if (i
== msg
->srcNode
) continue;
90 for (j
= 0; j
< pva(numSizes
); j
++) {
91 time
= *(msg
->data
+ i
* pva(numSizes
) + j
);
93 if (time
> pva(gmax
)[j
]) {
95 pva(gmaxSrc
)[j
] = msg
->srcNode
;
98 if (time
< pva(gmin
)[j
]) {
100 pva(gminSrc
)[j
] = msg
->srcNode
;
101 pva(gminDest
)[j
] = i
;
105 if (pva(numRecv
) == CmiNumPes()) {
106 for (j
= 0; j
< pva(numSizes
); j
++)
107 pva(gavg
)[j
] /= (CmiNumPes() * (CmiNumPes() - 1));
108 CmiPrintf("[pingpong] CmiSyncSend\n");
109 for (j
= 0; j
< pva(numSizes
); j
++) {
110 CmiPrintf("[pingpong] size=%d\taverageTime=%le seconds\n", sizes
[j
].size
,
112 CmiPrintf("[pingpong] size=%d\tmaxTime=%le seconds\t[%d->%d]\n",
113 sizes
[j
].size
, pva(gmax
)[j
], pva(gmaxSrc
)[j
], pva(gmaxDest
)[j
]);
114 CmiPrintf("[pingpong] size=%d\tminTime=%le seconds\t[%d->%d]\n",
115 sizes
[j
].size
, pva(gmin
)[j
], pva(gminSrc
)[j
], pva(gminDest
)[j
]);
117 CmiSetHandler(&m
, pva(ack_handler
));
118 CmiSyncSend(0, sizeof(EmptyMsg
), &m
);
123 static void startNextNode(EmptyMsg
* msg
) {
125 CmiInitMsgHeader(m
.core
, sizeof(EmptyMsg
));
127 if ((CmiMyPe() + 1) != CmiNumPes()) {
128 CmiSetHandler(&m
, pva(nbrHandler
));
129 CmiSyncSend(pva(nodeList
)[CmiMyPe() + 1], sizeof(EmptyMsg
), &m
);
133 static void startNextNbr(EmptyMsg
* msg
) {
138 CmiInitMsgHeader(m
.core
, sizeof(EmptyMsg
));
141 if (pva(nextNbr
) == CmiMyPe()) {
142 CmiSetHandler(&m
, pva(nbrHandler
));
143 CmiSyncSend(CmiMyPe(), sizeof(EmptyMsg
), &m
);
146 if (pva(nextNbr
) == CmiNumPes()) {
148 CmiSetHandler(&m
, pva(nodeHandler
));
149 CmiSyncSend(CmiMyPe(), sizeof(EmptyMsg
), &m
);
150 size
= sizeof(TimeMessage
) + pva(numSizes
) * CmiNumPes() * sizeof(double);
151 tm
= (TimeMessage
*)CmiAlloc(size
);
152 for (i
= 0; i
< CmiNumPes(); i
++)
153 memcpy(tm
->data
+ i
* pva(numSizes
), pva(times
)[i
],
154 sizeof(double) * pva(numSizes
));
155 tm
->srcNode
= CmiMyPe();
156 CmiSetHandler(tm
, pva(timeHandler
));
157 CmiSyncSendAndFree(0, size
, tm
);
159 CmiSetHandler(&m
, pva(sizeHandler
));
160 CmiSyncSend(CmiMyPe(), sizeof(EmptyMsg
), &m
);
164 static void startNextSize(EmptyMsg
* msg
) {
168 CmiInitMsgHeader(m
.core
, sizeof(EmptyMsg
));
170 if (pva(nextSize
) == pva(numSizes
)) {
172 CmiSetHandler(&m
, pva(nbrHandler
));
173 CmiSyncSend(CmiMyPe(), sizeof(EmptyMsg
), &m
);
175 int size
= sizeof(Message
) + sizes
[pva(nextSize
)].size
;
176 mm
= (Message
*)CmiAlloc(size
);
177 mm
->srcpe
= CmiMyPe();
178 mm
->idx
= pva(nextSize
);
179 CmiSetHandler(mm
, pva(iterHandler
));
181 CmiSyncSendAndFree(CmiMyPe(), size
, mm
);
182 pva(starttime
) = CmiWallTimer();
187 static void startNextIter(Message
* msg
) {
190 CmiInitMsgHeader(m
.core
, sizeof(EmptyMsg
));
192 if (pva(nextIter
) > sizes
[pva(nextSize
)].numiter
) {
193 pva(endtime
) = CmiWallTimer();
195 pva(times
)[pva(nextNbr
)][pva(nextSize
)] =
196 (pva(endtime
) - pva(starttime
)) / (2.0 * sizes
[pva(nextSize
)].numiter
);
198 CmiSetHandler(&m
, pva(sizeHandler
));
199 CmiSyncSend(CmiMyPe(), sizeof(EmptyMsg
), &m
);
202 CmiSetHandler(msg
, pva(bounceHandler
));
203 CmiSyncSendAndFree(pva(nextNbr
), sizeof(Message
) + sizes
[msg
->idx
].size
,
208 static void bounceMessage(Message
* msg
) {
209 CmiSetHandler(msg
, pva(iterHandler
));
210 CmiSyncSendAndFree(msg
->srcpe
, sizeof(Message
) + sizes
[msg
->idx
].size
, msg
);
213 void pingpong_init(void) {
216 CmiInitMsgHeader(m
.core
, sizeof(EmptyMsg
));
217 if (CmiNumPes() == 1) {
218 CmiPrintf("[pingpong] This benchmark requires > 1 nodes.\n");
219 CmiSetHandler(&m
, pva(ack_handler
));
220 CmiSyncSend(0, sizeof(EmptyMsg
), &m
);
223 CmiSetHandler(&m
, pva(nbrHandler
));
224 CmiSyncSend(0, sizeof(EmptyMsg
), &m
);
227 void pingpong_moduleinit(void) {
237 pvi(double, starttime
);
238 pva(starttime
) = 0.0;
239 pvi(double, endtime
);
242 for (i
= 0; sizes
[i
].size
!= (-1); i
++)
245 pvi(double**, times
);
246 pva(times
) = (double**)malloc(CmiNumPes() * sizeof(double*));
247 for (i
= 0; i
< CmiNumPes(); i
++)
248 pva(times
)[i
] = (double*)malloc(pva(numSizes
) * sizeof(double));
249 for (i
= 0; i
< CmiNumPes(); i
++)
250 for (j
= 0; j
< pva(numSizes
); j
++) pva(times
)[i
][j
] = 0.0;
252 pva(nodeList
) = (int*)malloc(CmiNumPes() * sizeof(int));
253 for (i
= 0; i
< CmiNumPes(); i
++) pva(nodeList
)[i
] = i
; /*CmiNodeFirst(i);*/
255 pva(gavg
) = (double*)malloc(sizeof(double) * pva(numSizes
));
257 pva(gmax
) = (double*)malloc(sizeof(double) * pva(numSizes
));
259 pva(gmin
) = (double*)malloc(sizeof(double) * pva(numSizes
));
261 pva(gmaxSrc
) = (int*)malloc(sizeof(int) * pva(numSizes
));
263 pva(gmaxDest
) = (int*)malloc(sizeof(int) * pva(numSizes
));
265 pva(gminSrc
) = (int*)malloc(sizeof(int) * pva(numSizes
));
267 pva(gminDest
) = (int*)malloc(sizeof(int) * pva(numSizes
));
268 for (i
= 0; i
< pva(numSizes
); i
++) {
271 pva(gmin
)[i
] = 1000000000.0;
273 pva(gmaxDest
)[i
] = 0;
275 pva(gminDest
)[i
] = 0;
277 pvi(int, timeHandler
);
278 pva(timeHandler
) = CmiRegisterHandler((CmiHandler
)recvTime
);
279 pvi(int, nodeHandler
);
280 pva(nodeHandler
) = CmiRegisterHandler((CmiHandler
)startNextNode
);
281 pvi(int, nbrHandler
);
282 pva(nbrHandler
) = CmiRegisterHandler((CmiHandler
)startNextNbr
);
283 pvi(int, sizeHandler
);
284 pva(sizeHandler
) = CmiRegisterHandler((CmiHandler
)startNextSize
);
285 pvi(int, iterHandler
);
286 pva(iterHandler
) = CmiRegisterHandler((CmiHandler
)startNextIter
);
287 pvi(int, bounceHandler
);
288 pva(bounceHandler
) = CmiRegisterHandler((CmiHandler
)bounceMessage
);