doc: Add serial to list of ci file reserved words
[charm.git] / examples / pose / PatternGen / Worker.h
1 #include "defs.h"
2
3 /// Initialization message used for constructing a Worker
4 class WorkerInitMsg {
5  public:
6   int myPID;           // poser ID
7   int totalNumWorkers; // number of worker objects in the simulation
8   int patternNum;      // communication pattern to use
9
10   WorkerInitMsg(int pid, int totalWorkers, int pattern): myPID(pid), totalNumWorkers(totalWorkers), patternNum(pattern) {}
11   WorkerInitMsg& operator=(const WorkerInitMsg& obj) {
12     eventMsg::operator=(obj);
13     myPID = obj.myPID;
14     totalNumWorkers = obj.totalNumWorkers;
15     patternNum = obj.patternNum;
16     return *this;
17   }
18 };
19
20
21 /// Message passed between Worker posers
22 class WorkMsg {
23  public:
24   int srcWorkerPID; // poser ID of the source Worker
25   int msgID;        // ID of the message
26
27   WorkMsg(int workerPID, int id): srcWorkerPID(workerPID), msgID(id) {}
28   WorkMsg& operator=(const WorkMsg& obj) {
29     eventMsg::operator=(obj);
30     srcWorkerPID = obj.srcWorkerPID;
31     msgID = obj.msgID;
32     return *this;
33   }
34 };
35
36
37 /// Posers that send messages to each other
38 class Worker {
39  public:
40   int myPID;           // poser ID
41   int totalNumWorkers; // number of worker objects in the simulation
42   int patternNum;      // communication pattern to use
43   int msgCount;        // current message count (total for whole simulation)
44   int iterNum;         // current iteration number
45   int msgNum;          // current message number (for current iteration)
46
47   Worker() {}
48   Worker(WorkerInitMsg *m); 
49   ~Worker() {}
50   Worker& operator=(const Worker& obj) {
51     rep::operator=(obj);
52     myPID = obj.myPID;
53     totalNumWorkers = obj.totalNumWorkers;
54     patternNum = obj.patternNum;
55     msgCount = obj.msgCount;
56     iterNum = obj.iterNum;
57     msgNum = obj.msgNum;
58     return *this;
59   }
60   void pup(PUP::er &p) { 
61     chpt<state_Worker>::pup(p); 
62     p|myPID; p|totalNumWorkers; p|patternNum; 
63     p|msgCount; p|iterNum; p|msgNum;
64   }
65   void dump() {
66     CkPrintf("Worker: myPID=%d totalNumWorkers=%d patternNum=%d msgCount=%d iterNum=%d msgNum=%d\n", 
67              myPID, totalNumWorkers, patternNum, msgCount, iterNum, msgNum);
68     chpt<state_Worker>::dump();
69   }
70   void terminus();
71
72   /// Send a message to a Worker
73   void sendMessage();
74
75   /// ENTRY: Receive a message from a Worker
76   void recvMessage(WorkMsg *wm);
77   void recvMessage_anti(WorkMsg *wm) {
78     dbPrintf("[ID=%d][ovt=%lld] recvMessage_anti msgCount=%d iterNum=%d msgNum=%d\n", myPID, ovt, msgCount, iterNum, msgNum);
79     restore(this);
80     dbPrintf("   ovt after rollback=%lld\n", ovt);
81   }
82   void recvMessage_commit(WorkMsg *wm) {
83     dbPrintf("[ID=%d][ovt=%lld] recvMessage_commit msgCount=%d iterNum=%d msgNum=%d\n", myPID, ovt, msgCount, iterNum, msgNum);
84   }
85
86   /// ENTRY: Send a message for pattern 1
87   void pattern1Iter(WorkMsg *wm);
88   void pattern1Iter_anti(WorkMsg *wm) {
89     dbPrintf("[ID=%d][ovt=%lld] pattern1Iter_anti msgCount=%d iterNum=%d msgNum=%d\n", myPID, ovt, msgCount, iterNum, msgNum);
90     restore(this);
91     dbPrintf("   ovt after rollback=%lld\n", ovt);
92   }
93   void pattern1Iter_commit(WorkMsg *wm) {
94     dbPrintf("[ID=%d][ovt=%lld] pattern1Iter_commit msgCount=%d iterNum=%d msgNum=%d\n", myPID, ovt, msgCount, iterNum, msgNum);
95   }
96 };