6 #include "boost/smart_ptr.hpp"
27 template <
class Sim_t>
54 bool isOptimizer =
true)
68 if (!isOptimizer)
return;
98 size_t stop_value = 0;
100 MPI_Irecv(&stop_value, 1, MPI_UNSIGNED_LONG,
leader_pid_,
111 if(stop_req != MPI_REQUEST_NULL) {
114 MPI_Test(&stop_req, &flag, &status);
129 std::cout <<
"Exception while running simulation: "
132 MPI_Irecv(&stop_value, 1, MPI_UNSIGNED_LONG,
leader_pid_,
167 MPI_Send(&dummy, 1, MPI_UNSIGNED_LONG,
pilot_rank_,
182 virtual bool onMessage(MPI_Status status,
size_t recv_value) {
187 size_t job_id = recv_value;
210 sim->collectResults();
212 requested_results = sim->getResults();
214 std::cout <<
"Exception while running simulation: "
218 MPI_Send(&job_id, 1, MPI_UNSIGNED_LONG, pilot_rank_,
222 MPI_Recv(&dummy, 1, MPI_UNSIGNED_LONG, pilot_rank_,
231 std::stringstream os;
232 os <<
"Unexpected MPI_TAG: " << status.MPI_TAG;
233 std::cout <<
"(Worker) Error: " << os.str() <<
std::endl;
std::map< std::string, reqVarInfo_t > reqVarContainer_t
virtual const char * what() const
void prePoll()
executed before checking for new request
#define MPI_WORKER_STATUSUPDATE_TAG
notify pilot about worker status
#define MPI_WORKER_FINISHED_TAG
notify pilot that work has been finished and results are ready to collect
void notifyCoWorkers(int tag)
notify coworkers of incoming broadcast
boost::shared_ptr< CmdArguments > CmdArguments_t
#define MPI_WORKER_FINISHED_ACK_TAG
pilot notifies worker that he is ready to collect the results
void postPoll()
executed after handling (if any) new request
A worker MPI entity consists of a processor group that runs a simulation of type Sim_t. The main loop in run() accepts new jobs from the master process runs the simulation and reports back the results.
void MPI_Send_reqvars(reqVarContainer_t reqvars, size_t pid, MPI_Comm comm)
namedVariableCollection_t Param_t
boost::scoped_ptr< Sim_t > SimPtr_t
void onStop()
enable implementation to react to STOP tag
virtual bool onMessage(MPI_Status status, size_t recv_value)
Worker(Expressions::Named_t constraints, std::string simName, Comm::Bundle_t comms, CmdArguments_t args)
#define MPI_WORK_JOBID_TAG
unique id of the job
Worker(Expressions::Named_t objectives, Expressions::Named_t constraints, std::string simName, Comm::Bundle_t comms, CmdArguments_t args, bool isOptimizer=true)
void MPI_Recv_params(Param_t ¶ms, size_t pid, MPI_Comm comm)
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
#define MPI_COWORKER_NEW_JOB_TAG
notifies coworkers about new jobs
std::string simulation_name_
void MPI_Bcast_params(Param_t ¶ms, size_t root, MPI_Comm comm)
broadcast params to all entities in comm
Expressions::Named_t objectives_
bundles all communicators for a specific role/pid
An interface implementing the basics of a poll loop, posting an MPI_Irecv and waiting for new request...
void setupPoll()
executed before starting polling loop
MPI_Comm comm_m
communicator the poller listens to requests
Inform & endl(Inform &inf)
#define MPI_STOP_TAG
global stop tag to exit poll loop (
Expressions::Named_t constraints_