35 #include "boost/smart_ptr.hpp"
44 template <
class Sim_t>
71 const std::map<std::string, std::string> &userVariables,
72 bool isOptimizer =
true)
87 if (!isOptimizer)
return;
116 MPI_Request stop_req;
117 size_t stop_value = 0;
119 MPI_Irecv(&stop_value, 1, MPI_UNSIGNED_LONG,
leader_pid_,
130 if(stop_req != MPI_REQUEST_NULL) {
133 MPI_Test(&stop_req, &flag, &status);
148 std::cout <<
"Exception while running simulation: "
151 MPI_Irecv(&stop_value, 1, MPI_UNSIGNED_LONG,
leader_pid_,
188 MPI_Send(&dummy, 1, MPI_UNSIGNED_LONG,
pilot_rank_,
203 virtual bool onMessage(MPI_Status status,
size_t recv_value) {
208 size_t job_id = recv_value;
232 sim->collectResults();
234 requested_results = sim->getResults();
236 std::cout <<
"Exception while running simulation: "
240 MPI_Send(&job_id, 1, MPI_UNSIGNED_LONG,
pilot_rank_,
244 MPI_Recv(&dummy, 1, MPI_UNSIGNED_LONG,
pilot_rank_,
253 std::stringstream os;
254 os <<
"Unexpected MPI_TAG: " << status.MPI_TAG;
255 std::cout <<
"(Worker) Error: " << os.str() <<
std::endl;
Inform & endl(Inform &inf)
boost::shared_ptr< CmdArguments > CmdArguments_t
void MPI_Send_reqvars(reqVarContainer_t reqvars, size_t pid, MPI_Comm comm)
void MPI_Bcast_params(Param_t ¶ms, size_t root, MPI_Comm comm)
broadcast params to all entities in comm
void MPI_Recv_params(Param_t ¶ms, size_t pid, MPI_Comm comm)
#define MPI_WORK_JOBID_TAG
unique id of the job
#define MPI_WORKER_FINISHED_TAG
notify pilot that work has been finished and results are ready to collect
#define MPI_COWORKER_NEW_JOB_TAG
notifies coworkers about new jobs
#define MPI_WORKER_STATUSUPDATE_TAG
notify pilot about worker status
#define MPI_WORKER_FINISHED_ACK_TAG
pilot notifies worker that he is ready to collect the results
#define MPI_STOP_TAG
global stop tag to exit poll loop (
std::map< std::string, reqVarInfo_t > reqVarContainer_t
namedVariableCollection_t Param_t
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
bundles all communicators for a specific role/pid
MPI_Comm comm_m
communicator the poller listens to requests
Expressions::Named_t objectives_
Worker(Expressions::Named_t objectives, Expressions::Named_t constraints, std::string simName, Comm::Bundle_t comms, CmdArguments_t args, const std::map< std::string, std::string > &userVariables, bool isOptimizer=true)
std::string simulation_name_
void postPoll()
executed after handling (if any) new request
void onStop()
enable implementation to react to STOP tag
void notifyCoWorkers(int tag)
notify coworkers of incoming broadcast
void prePoll()
executed before checking for new request
const std::map< std::string, std::string > userVariables_
void setupPoll()
executed before starting polling loop
Worker(Expressions::Named_t constraints, std::string simName, Comm::Bundle_t comms, CmdArguments_t args)
virtual bool onMessage(MPI_Status status, size_t recv_value)
boost::scoped_ptr< Sim_t > SimPtr_t
Expressions::Named_t constraints_
virtual const char * what() const