Skip to content

Commit d8e0da2

Browse files
committed
added decrement and enqueue example
1 parent cce6d1b commit d8e0da2

File tree

3 files changed

+53
-0
lines changed

3 files changed

+53
-0
lines changed

tests/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ add_subdirectory(broadcast)
22
add_subdirectory(group)
33
add_subdirectory(within-node-bcast)
44
add_subdirectory(conds)
5+
add_subdirectory(decrement_enqueue)
56
add_subdirectory(idle)
67
add_subdirectory(kNeighbors)
78
add_subdirectory(orig-converse/pingpong)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
add_reconverse_executable(decrement_enqueue decrement_enqueue.cpp)
2+
add_test(NAME decrement_enqueue COMMAND decrement_enqueue +pe 1)
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Simple reconverse test for CmiCreateDecrementToEnqueue / CmiDecrementCounter
2+
// Intended to run with 1 PE on 1 process.
3+
4+
#include "converse.h"
5+
#include <string.h>
6+
7+
// Handler invoked when the decrement counter reaches zero. Exits the program.
8+
void exit_handler(void *msg) {
9+
// We don't need the message payload; just exit.
10+
CmiPrintf("Exit handler called, exiting...\n");
11+
CmiExit(0);
12+
}
13+
14+
// Start function invoked by ConverseInit.
15+
void test_start(int argc, char **argv) {
16+
CmiPrintf("Starting decrement_enqueue test...\n");
17+
// Only PE 0 will create and drive the counter per the test spec.
18+
if (CmiMyPe() != 0) return;
19+
20+
int handler = CmiRegisterHandler((CmiHandler)exit_handler);
21+
22+
// Create a minimal message consisting only of the message header.
23+
int msgSize = (int)sizeof(CmiMessageHeader);
24+
void *msg = CmiAlloc(msgSize);
25+
memset(msg, 0, msgSize);
26+
27+
// Set handler, destination and size on the header so CmiDecrementCounter
28+
// can inspect them when it enqueues the message.
29+
CmiSetHandler(msg, handler);
30+
CmiMessageHeader *hdr = (CmiMessageHeader *)msg;
31+
hdr->destPE = (CmiUInt4)CmiMyPe();
32+
hdr->messageSize = msgSize;
33+
34+
// Create the decrement-to-enqueue helper with initial count 16.
35+
DecrementToEnqueueMsg *dte = CmiCreateDecrementToEnqueue(16u, msg);
36+
37+
// Decrement 16 times; on the 16th call the message will be sent and the
38+
// registered handler will call CmiExit.
39+
for (int i = 0; i < 16; ++i) {
40+
CmiDecrementCounter(dte);
41+
}
42+
43+
// Return from start; scheduler will run and the exit handler will stop it.
44+
}
45+
46+
int main(int argc, char **argv) {
47+
// Start the Converse runtime with our test_start function.
48+
ConverseInit(argc, argv, test_start, 0, 0);
49+
return 0;
50+
}

0 commit comments

Comments
 (0)