1 #ifndef __SAMPLE_PILOT_H__
2 #define __SAMPLE_PILOT_H__
30 ,
class SolPropagationGraph_t
35 SolPropagationGraph_t,
45 const std::map< std::string,
46 std::shared_ptr<SamplingMethod>
48 const std::vector<std::string> &storeobjstr,
49 const std::vector<std::string> &filesToKeep)
52 SolPropagationGraph_t,
63 if (obj.size() == 0) {
70 this->
setup(known_expr_funcs, storeobjstr, filesToKeep);
80 typedef std::map<size_t, Param_t >
Jobs_t;
88 const std::vector<std::string> &storeobjstr,
89 const std::vector<std::string> &filesToKeep)
95 MPI_Barrier(MPI_COMM_WORLD);
99 else if ( this->
comm_->isWorker() ) {
startWorker(storeobjstr, filesToKeep); }
106 std::ostringstream os;
107 os <<
"\033[01;35m" <<
" " << this->
global_rank_ <<
" (PID: " << getpid() <<
") ▶ Sampler"
109 std::cout << os.str() << std::flush;
111 boost::scoped_ptr<Opt_t> opt(
116 std::cout <<
"Stop Sampler.." <<
std::endl;
121 const std::vector<std::string> &filesToKeep)
123 std::ostringstream os;
124 os <<
"\033[01;35m" <<
" " << this->
global_rank_ <<
" (PID: " << getpid() <<
") ▶ Worker"
126 std::cout << os.str() << std::flush;
130 if (pos != std::string::npos)
132 pos = tmplfile.find(
".");
133 std::string simName = tmplfile.substr(0,pos);
135 boost::scoped_ptr< SampleWorker<Sim_t> > w(
138 storeobjstr, filesToKeep));
140 std::cout <<
"Stop Worker.." <<
std::endl;
149 bool all_worker_idle =
true;
169 MPI_Isend(&dummy, 1, MPI_INT, worker,
183 size_t jid = job->first;
185 Param_t job_params = job->second;
190 Param_t >(job->first, job->second));
194 std::ostringstream dump;
195 dump <<
"sent job with ID " << jid <<
" to worker " << worker
210 size_t job_id = recv_value;
213 MPI_Send(&dummy, 1, MPI_UNSIGNED_LONG, status.MPI_SOURCE,
222 std::ostringstream dump;
223 dump <<
"worker finished job with ID " << job_id <<
std::endl;
230 int opt_master_rank = this->
comm_->getLeader();
231 MPI_Send(&job_id, 1, MPI_UNSIGNED_LONG, opt_master_rank,
245 size_t job_id = recv_value;
246 int opt_master_rank = this->
comm_->getLeader();
252 std::pair<size_t, Param_t >(
253 job_id, job_params));
255 std::ostringstream dump;
256 dump <<
"new opt job with ID " << job_id <<
std::endl;
272 std::string msg =
"(Pilot) Error: unexpected MPI_TAG: ";
273 msg += status.MPI_TAG;
280 std::map< std::string,
281 std::shared_ptr<SamplingMethod>
std::map< std::string, reqVarInfo_t > reqVarContainer_t
void parseInputFile(functionDictionary_t known_expr_funcs, bool isOptimizationRun)
boost::scoped_ptr< Trace > job_trace_
std::string input_file_
input file for simulation with embedded optimization problem
MPI_Comm worker_comm_
MPI communicator used for messages to/from worker.
void startWorker(const std::vector< std::string > &storeobjstr, const std::vector< std::string > &filesToKeep)
virtual void startSampler()
virtual void startWorker()
SamplePilot(CmdArguments_t args, boost::shared_ptr< Comm_t > comm, functionDictionary_t known_expr_funcs, const DVarContainer_t &dvar, const Expressions::Named_t &obj, const std::map< std::string, std::shared_ptr< SamplingMethod > > &sampleMethods, const std::vector< std::string > &storeobjstr, const std::vector< std::string > &filesToKeep)
boost::shared_ptr< CmdArguments > CmdArguments_t
#define MPI_WORKER_FINISHED_ACK_TAG
pilot notifies worker that he is ready to collect the results
void MPI_Send_reqvars(reqVarContainer_t reqvars, size_t pid, MPI_Comm comm)
virtual void postPoll()
executed after handling (if any) new request
Expressions::Named_t objectives_
objectives
std::map< std::string, std::shared_ptr< SamplingMethod > > sampleMethods_m
sampleMethods_m(sampleMethods)
namedVariableCollection_t Param_t
Expression Expr_t
type of an expression
virtual void setup(functionDictionary_t known_expr_funcs, const std::vector< std::string > &storeobjstr, const std::vector< std::string > &filesToKeep)
virtual void startPilot()
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.
Jobs_t::iterator JobIter_t
int total_available_workers_
#define MPI_WORK_JOBID_TAG
unique id of the job
Expressions::Named_t constraints_
constraints
virtual void sendNewJobToWorker(int worker)
void MPI_Recv_params(Param_t ¶ms, size_t pid, MPI_Comm comm)
DVarContainer_t dvars_
design variables
std::map< std::string, DVar_t > DVarContainer_t
void MPI_Send_params(Param_t params, size_t pid, MPI_Comm comm)
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
virtual bool onMessage(MPI_Status status, size_t recv_value)
boost::shared_ptr< Comm_t > comm_
void MPI_Recv_reqvars(reqVarContainer_t &reqvars, size_t pid, MPI_Comm comm)
The sample Pilot (Master): Coordinates requests by sampler to workers.
int my_rank_in_worker_comm_
std::vector< bool > is_worker_idle_
std::string::iterator iterator
std::map< size_t, Param_t > Jobs_t
keep track of requests and running jobs
bool stop(bool isOpt=true)
#define MPI_OPT_JOB_FINISHED_TAG
pilot tells optimizer that results are ready to collect
std::map< std::string, client::function::type > functionDictionary_t
MPI_Comm opt_comm_
MPI communicator used for messages to/from optimizer.
The Optimization Pilot (Master): Coordinates requests by optimizer to workers and reports results bac...
Inform & endl(Inform &inf)
#define MPI_STOP_TAG
global stop tag to exit poll loop (