examples: add example program demonstrating sync entry methods
[charm.git] / examples / charm++ / completion / comp.cc
1 #include "comp.decl.h"
2 #include "completion.h"
3
4 struct Main : public CBase_Main {
5   CProxy_CompletionDetector detector;
6   const int num;
7
8   Main(CkArgMsg* msg)
9     : num(10) {
10     delete msg;
11     detector = CProxy_CompletionDetector::ckNew();
12     detector.start_detection(num,
13                              CkCallback(CkIndex_Main::startTest(), thisProxy),
14                              CkCallback(CkIndex_Main::finishTest(), thisProxy), 0);
15   }
16
17   void startTest() {
18     CkPrintf("completion module initialized\n");
19     CProxy_completion_array::ckNew(detector, num, num);
20   }
21
22   void finishTest() {
23     CkPrintf("completion completed successfully\n");
24     CkExit();
25   }
26 };
27
28 struct completion_array : public CBase_completion_array {
29   completion_array(CProxy_CompletionDetector det, int n) {
30     CkPrintf("Array element %d producing %d elements\n", thisIndex, thisIndex + 1);
31     det.ckLocalBranch()->produce(thisIndex + 1);
32     det.ckLocalBranch()->done();
33     CkPrintf("Array element %d consuming %d elements\n", thisIndex, n - thisIndex);
34     det.ckLocalBranch()->consume(n - thisIndex);
35   }
36   completion_array(CkMigrateMessage *) {}
37 };
38
39 #include "comp.def.h"