30 #ifndef __SAMPLE_WORKER_H__
31 #define __SAMPLE_WORKER_H__
35 template <
class Sim_t>
45 const std::vector<std::string> &storeobjstr,
46 const std::vector<std::string> &filesToKeep,
47 const std::map<std::string, std::string> &userVariables)
48 :
Worker<Sim_t>(objectives, constraints, simName, comms, args, userVariables, false)
77 MPI_Send(&job_id, 1, MPI_UNSIGNED_LONG, i, tag, this->
coworker_comm_);
91 MPI_Irecv(&job_id, 1, MPI_UNSIGNED_LONG, this->
leader_pid_,
102 if(stop_req != MPI_REQUEST_NULL) {
105 MPI_Test(&stop_req, &flag, &status);
119 sim->setFilename(job_id);
123 std::cout <<
"Exception while running simulation: "
126 MPI_Irecv(&job_id, 1, MPI_UNSIGNED_LONG, this->
leader_pid_,
139 bool onMessage(MPI_Status status,
size_t recv_value)
override {
144 size_t job_id = recv_value;
166 sim->setFilename(job_id);
177 sim->collectResults();
178 requested_results = sim->getResults();
189 std::cout <<
"Exception while running simulation: "
193 MPI_Send(&job_id, 1, MPI_UNSIGNED_LONG, this->pilot_rank_,
197 MPI_Recv(&dummy, 1, MPI_UNSIGNED_LONG, this->pilot_rank_,
206 std::stringstream os;
207 os <<
"Unexpected MPI_TAG: " << status.MPI_TAG;
208 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_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
const std::vector< std::string > statVariablesToStore_m
bool onMessage(MPI_Status status, size_t recv_value) override
void notifyCoWorkers(size_t job_id, int tag)
notify coworkers of incoming broadcast
const std::vector< std::string > filesToKeep_m
SampleWorker(Expressions::Named_t objectives, Expressions::Named_t constraints, std::string simName, Comm::Bundle_t comms, CmdArguments_t args, const std::vector< std::string > &storeobjstr, const std::vector< std::string > &filesToKeep, const std::map< std::string, std::string > &userVariables)
bundles all communicators for a specific role/pid
MPI_Comm comm_m
communicator the poller listens to requests
Expressions::Named_t objectives_
std::string simulation_name_
const std::map< std::string, std::string > userVariables_
boost::scoped_ptr< Sim_t > SimPtr_t
Expressions::Named_t constraints_
virtual const char * what() const