42 template <
class Sim_t>
69 const std::map<std::string, std::string> &userVariables,
70 bool isOptimizer =
true)
85 if (!isOptimizer)
return;
114 MPI_Request stop_req;
115 size_t stop_value = 0;
117 MPI_Irecv(&stop_value, 1, MPI_UNSIGNED_LONG,
leader_pid_,
128 if(stop_req != MPI_REQUEST_NULL) {
131 MPI_Test(&stop_req, &flag, &status);
146 std::cout <<
"Exception while running simulation: "
149 MPI_Irecv(&stop_value, 1, MPI_UNSIGNED_LONG,
leader_pid_,
186 MPI_Send(&dummy, 1, MPI_UNSIGNED_LONG,
pilot_rank_,
201 virtual bool onMessage(MPI_Status status,
size_t recv_value) {
206 size_t job_id = recv_value;
230 sim->collectResults();
232 requested_results = sim->getResults();
234 std::cout <<
"Exception while running simulation: "
238 MPI_Send(&job_id, 1, MPI_UNSIGNED_LONG, pilot_rank_,
242 MPI_Recv(&dummy, 1, MPI_UNSIGNED_LONG, pilot_rank_,
251 std::stringstream os;
252 os <<
"Unexpected MPI_TAG: " << status.MPI_TAG;
253 std::cout <<
"(Worker) Error: " << os.str() <<
std::endl;
namedVariableCollection_t Param_t
#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 postPoll()
executed after handling (if any) new request
virtual const char * what() const
void setupPoll()
executed before starting polling loop
MPI_Comm comm_m
communicator the poller listens to requests
Inform & endl(Inform &inf)
Worker(Expressions::Named_t constraints, std::string simName, Comm::Bundle_t comms, CmdArguments_t args)
void MPI_Bcast_params(Param_t ¶ms, size_t root, MPI_Comm comm)
broadcast params to all entities in comm
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
void notifyCoWorkers(int tag)
notify coworkers of incoming broadcast
#define MPI_WORK_JOBID_TAG
unique id of the job
void prePoll()
executed before checking for new request
void MPI_Send_reqvars(reqVarContainer_t reqvars, size_t pid, MPI_Comm comm)
std::shared_ptr< CmdArguments > CmdArguments_t
const std::map< std::string, std::string > userVariables_
Expressions::Named_t constraints_
#define MPI_STOP_TAG
global stop tag to exit poll loop (
#define MPI_WORKER_FINISHED_ACK_TAG
pilot notifies worker that he is ready to collect the results
virtual bool onMessage(MPI_Status status, size_t recv_value)
std::string simulation_name_
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)
bundles all communicators for a specific role/pid
#define MPI_COWORKER_NEW_JOB_TAG
notifies coworkers about new jobs
const std::unique_ptr< Sim_t > SimPtr_t
Expressions::Named_t objectives_
void MPI_Recv_params(Param_t ¶ms, size_t pid, MPI_Comm comm)
std::map< std::string, reqVarInfo_t > reqVarContainer_t
void onStop()
enable implementation to react to STOP tag