33#ifndef __SAMPLE_PILOT_H__
34#define __SAMPLE_PILOT_H__
43 ,
class SolPropagationGraph_t
48 SolPropagationGraph_t,
58 const std::map< std::string,
59 std::shared_ptr<SamplingMethod>
61 const std::vector<std::string> &storeobjstr,
62 const std::vector<std::string> &filesToKeep,
63 const std::map<std::string, std::string> &userVariables)
66 SolPropagationGraph_t,
85 this->
setup(known_expr_funcs, storeobjstr, filesToKeep, userVariables);
95 typedef std::map<size_t, Param_t >
Jobs_t;
103 const std::vector<std::string> &storeobjstr,
104 const std::vector<std::string> &filesToKeep,
105 const std::map<std::string, std::string> &userVariables)
111 MPI_Barrier(MPI_COMM_WORLD);
115 else if ( this->
comm_->isWorker() ) {
startWorker(storeobjstr, filesToKeep, userVariables); }
122 std::ostringstream os;
123 os <<
"\033[01;35m" <<
" " << this->
global_rank_ <<
" (PID: " << getpid() <<
") ▶ Sampler"
125 std::cout << os.str() << std::flush;
127 boost::scoped_ptr<Opt_t> opt(
129 this->
comm_->getBundle(), this->cmd_args_));
132 std::cout <<
"Stop Sampler.." <<
std::endl;
137 const std::vector<std::string> &filesToKeep,
138 const std::map<std::string, std::string> &userVariables)
140 std::ostringstream os;
141 os <<
"\033[01;35m" <<
" " << this->
global_rank_ <<
" (PID: " << getpid() <<
") ▶ Worker"
143 std::cout << os.str() << std::flush;
147 if (pos != std::string::npos)
149 pos = tmplfile.find(
".");
150 std::string simName = tmplfile.substr(0,pos);
152 boost::scoped_ptr< SampleWorker<Sim_t> > w(
154 this->
comm_->getBundle(), this->cmd_args_,
155 storeobjstr, filesToKeep, userVariables));
157 std::cout <<
"Stop Worker.." <<
std::endl;
166 bool all_worker_idle =
true;
186 MPI_Isend(&dummy, 1, MPI_INT, worker,
200 size_t jid = job->first;
202 Param_t job_params = job->second;
206 running_job_list_.insert(std::pair<
size_t,
207 Param_t >(job->first, job->second));
211 std::ostringstream dump;
212 dump <<
"sent job with ID " << jid <<
" to worker " << worker
227 size_t job_id = recv_value;
230 MPI_Send(&dummy, 1, MPI_UNSIGNED_LONG, status.MPI_SOURCE,
239 std::ostringstream dump;
240 dump <<
"worker finished job with ID " << job_id <<
std::endl;
247 int opt_master_rank = this->
comm_->getLeader();
248 MPI_Send(&job_id, 1, MPI_UNSIGNED_LONG, opt_master_rank,
254 if (!request_queue_.empty())
262 size_t job_id = recv_value;
263 int opt_master_rank = this->
comm_->getLeader();
268 request_queue_.insert(
269 std::pair<size_t, Param_t >(
270 job_id, job_params));
272 std::ostringstream dump;
273 dump <<
"new opt job with ID " << job_id <<
std::endl;
289 std::string msg =
"(Pilot) Error: unexpected MPI_TAG: ";
290 msg += status.MPI_TAG;
297 std::map< std::string,
298 std::shared_ptr<SamplingMethod>
Inform & endl(Inform &inf)
#define MPI_WORK_JOBID_TAG
unique id of the job
#define MPI_OPT_JOB_FINISHED_TAG
pilot tells optimizer that results are ready to collect
@ WORKER_STATUSUPDATE_TAG
#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 (
void MPI_Send_reqvars(reqVarContainer_t reqvars, size_t pid, MPI_Comm comm)
void MPI_Send_params(Param_t params, size_t pid, MPI_Comm comm)
void MPI_Recv_reqvars(reqVarContainer_t &reqvars, size_t pid, MPI_Comm comm)
void MPI_Recv_params(Param_t ¶ms, size_t pid, MPI_Comm comm)
std::map< std::string, DVar_t > DVarContainer_t
std::map< std::string, reqVarInfo_t > reqVarContainer_t
namedVariableCollection_t Param_t
boost::shared_ptr< CmdArguments > CmdArguments_t
std::map< std::string, client::function::type > functionDictionary_t
Representation objects and parsers for attribute expressions.
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
Expression Expr_t
type of an expression
std::string::iterator iterator
virtual void setup(functionDictionary_t known_expr_funcs, const std::vector< std::string > &storeobjstr, const std::vector< std::string > &filesToKeep, const std::map< std::string, std::string > &userVariables)
std::map< std::string, std::shared_ptr< SamplingMethod > > sampleMethods_m
std::map< size_t, Param_t > Jobs_t
keep track of requests and running jobs
virtual void postPoll()
executed after handling (if any) new request
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, const std::map< std::string, std::string > &userVariables)
virtual void sendNewJobToWorker(int worker)
virtual bool onMessage(MPI_Status status, size_t recv_value)
Jobs_t::iterator JobIter_t
virtual void startSampler()
void startWorker(const std::vector< std::string > &storeobjstr, const std::vector< std::string > &filesToKeep, const std::map< std::string, std::string > &userVariables)
int total_available_workers_
boost::shared_ptr< Comm_t > comm_
std::string input_file_
input file for simulation with embedded optimization problem
std::vector< bool > is_worker_idle_
virtual void startPilot()
bool stop(bool isOpt=true)
int my_rank_in_worker_comm_
Expressions::Named_t constraints_
constraints
MPI_Comm opt_comm_
MPI communicator used for messages to/from optimizer.
boost::scoped_ptr< Trace > job_trace_
Expressions::Named_t objectives_
objectives
MPI_Comm worker_comm_
MPI communicator used for messages to/from worker.
DVarContainer_t dvars_
design variables
void parseInputFile(functionDictionary_t, bool isOptimizationRun)