ECF 1.5
Communicator.h
1#ifndef Communicator_h
2#define Communicator_h
3
4class Individual;
5typedef boost::shared_ptr<Individual> IndividualP;
6class State;
7typedef boost::shared_ptr<State> StateP;
8
9
10namespace Comm
11{
12
13// message tags:
14const int T_DEFAULT = 0;
15const int T_CONTROL = 99;
16const int T_CONTINUE = 1;
17const int T_TERMINATE = 2;
18const int T_VALUES = 3;
19const int T_LOGS = 4;
20const int T_FINAL = 5;
21const int T_DATA = 6;
22
23// controls:
24const int CONTINUE = 1;
25const int TERMINATE = 0;
26
27// timing categories
28enum timing
29{ COMP, IDLE, SEND, RECV, PACK, UNPACK };
30
31#ifdef _MPI
32
33// MPI defines
34const int ANY_PROCESS = MPI::ANY_SOURCE;
35
43{
44protected:
45 // MPI parameters
46 uint mpiGlobalSize_, mpiGlobalRank_;
47 uint mpiSize_, mpiRank_;
48 std::string processorName_;
49 StateP state_;
50 MPI::Status status_;
51 MPI::Status controlStatus_;
52 int logLevel_;
53 std::vector<uint> demeMasters;
54 bool bInitialized_;
55
56 // communicators
69 MPI::Intercomm frameworkComm_;
70
76 MPI::Intercomm demeComm_;
77
78 // timing
79 double currentTime_, lastTime_;
80 double beginTime_, endTime_;
81 double idleTime_;
82 double sendTime_;
83 double recvTime_;
84 double compTime_;
85 double packTime_, unpackTime_;
86 uint sendCnt_;
87 uint recvCnt_;
88 double time(enum timing T);
89public:
91 bool initialize(StateP, int, char**);
92 bool finalize();
93 bool isInitialized()
94 { return bInitialized_; }
95
96 // send methods:
97 bool sendIndividuals(std::vector<IndividualP>, uint, uint nIndividuals = 0);
98 bool sendIndividualsGlobal(std::vector<IndividualP>, uint, uint nIndividuals = 0);
99 bool sendFitness(std::vector<IndividualP>, uint, uint nIndividuals = 0);
100 bool sendValuesGlobal(std::vector<double>, uint);
101 bool sendLogsGlobal(std::string, uint iProcess = 0, bool blocking = false);
102 bool sendDataGlobal(voidP, uint, uint);
103
104 // receive methods:
105 uint recvDemeIndividuals(std::vector<IndividualP>&, uint);
106 std::vector<IndividualP> recvIndividuals(uint iProcess = MPI::ANY_SOURCE);
107 std::vector<IndividualP> recvIndividualsGlobal(uint iProcess = MPI::ANY_SOURCE);
108 uint recvReplaceIndividuals(std::vector<IndividualP>&, uint);
109 uint recvDemeFitness(std::vector<IndividualP>&, uint);
110 std::vector<uint> recvFitnessVector(std::vector<IndividualP>&, uint);
111 std::vector<double> recvValuesGlobal(uint iProcess = MPI::ANY_SOURCE);
112 std::string recvLogsGlobal();
113 voidP recvDataGlobal(uint iProcess = MPI::ANY_SOURCE);
114
115 // other:
116 bool messageWaiting(uint iProcess = MPI::ANY_SOURCE, uint tag = MPI::ANY_TAG);
117 void synchronize();
118 bool sendControlMessage(uint, int);
119 int recvControlMessage(uint);
120 bool sendTerminateMessage(uint, bool);
121 bool recvTerminateMessage(uint);
122 bool checkTerminationMessage(uint master = 0);
123 uint createDemeCommunicator(uint nDemes);
124 uint getDemeMaster(uint iDeme);
125
126 // info:
127 uint getLastSource();
128 uint getCommRank()
129 { return mpiRank_; }
130 uint getCommSize()
131 { return mpiSize_; }
132 uint getCommGlobalRank()
133 { return mpiGlobalRank_; }
134 uint getCommGlobalSize()
135 { return mpiGlobalSize_; }
136
137};
138typedef boost::shared_ptr<Communicator> CommunicatorP;
139
140#else // non _MPI
141
142class Communicator
143{
144public:
145 bool initialize(StateP state, int argc, char** argv)
146 { return true; }
147 bool finalize()
148 { return true; }
149 uint getCommRank()
150 { return 0; }
151 uint getCommGlobalRank()
152 { return 0; }
153 uint getCommSize()
154 { return 0; }
155
156};
157typedef boost::shared_ptr<Communicator> CommunicatorP;
158#endif // _MPI
159
160} // namespace
161
162typedef boost::shared_ptr<Comm::Communicator> CommunicatorP;
163
164
165#endif // Communicator_h
Communicator class for interprocess communication.
Definition: Communicator.h:43
double time(enum timing T)
MPI::Intercomm frameworkComm_
Definition: Communicator.h:69
MPI::Intercomm demeComm_
Definition: Communicator.h:76
Individual class - inherits a vector of Genotype objects.
Definition: Individual.h:12
State class - backbone of the framework.
Definition: State.h:39