33#ifndef __SAMPLE_PILOT_H__
34#define __SAMPLE_PILOT_H__
44 ,
class SolPropagationGraph_t
49 SolPropagationGraph_t,
59 const std::map< std::string,
60 std::shared_ptr<SamplingMethod>
62 const std::vector<std::string> &storeobjstr,
63 const std::vector<std::string> &filesToKeep,
64 const std::map<std::string, std::string> &userVariables)
67 SolPropagationGraph_t,
86 this->
setup(known_expr_funcs, storeobjstr, filesToKeep, userVariables);
96 typedef std::map<size_t, Param_t >
Jobs_t;
104 const std::vector<std::string> &storeobjstr,
105 const std::vector<std::string> &filesToKeep,
106 const std::map<std::string, std::string> &userVariables)
112 MPI_Barrier(MPI_COMM_WORLD);
116 else if ( this->
comm_->isWorker() ) {
startWorker(storeobjstr, filesToKeep, userVariables); }
123 std::ostringstream os;
126 std::cout << os.str() << std::flush;
128 const std::unique_ptr<Opt_t> opt(
130 this->
comm_->getBundle(), this->cmd_args_));
133 std::cout <<
"Stop Sampler.." << std::endl;
138 const std::vector<std::string> &filesToKeep,
139 const std::map<std::string, std::string> &userVariables)
141 std::ostringstream os;
144 std::cout << os.str() << std::flush;
148 if (pos != std::string::npos)
150 pos = tmplfile.find(
".");
151 std::string simName = tmplfile.substr(0,pos);
153 const std::unique_ptr< SampleWorker<Sim_t> > w(
155 this->
comm_->getBundle(), this->cmd_args_,
156 storeobjstr, filesToKeep, userVariables));
158 std::cout <<
"Stop Worker.." << std::endl;
167 bool all_worker_idle =
true;
187 MPI_Isend(&dummy, 1, MPI_INT, worker,
201 size_t jid = job->first;
203 Param_t job_params = job->second;
207 running_job_list_.insert(std::pair<
size_t,
208 Param_t >(job->first, job->second));
212 std::ostringstream dump;
213 dump <<
"sent job with ID " << jid <<
" to worker " << worker
228 size_t job_id = recv_value;
231 MPI_Send(&dummy, 1, MPI_UNSIGNED_LONG, status.MPI_SOURCE,
240 std::ostringstream dump;
241 dump <<
"worker finished job with ID " << job_id << std::endl;
248 int opt_master_rank = this->
comm_->getLeader();
249 MPI_Send(&job_id, 1, MPI_UNSIGNED_LONG, opt_master_rank,
255 if (!request_queue_.empty())
263 size_t job_id = recv_value;
264 int opt_master_rank = this->
comm_->getLeader();
269 request_queue_.insert(
270 std::pair<size_t, Param_t >(
271 job_id, job_params));
273 std::ostringstream dump;
274 dump <<
"new opt job with ID " << job_id << std::endl;
290 std::string msg =
"(Pilot) Error: unexpected MPI_TAG: ";
291 msg += status.MPI_TAG;
298 std::map< std::string,
299 std::shared_ptr<SamplingMethod>
std::map< std::string, client::function::type > functionDictionary_t
std::map< std::string, DVar_t > DVarContainer_t
std::map< std::string, reqVarInfo_t > reqVarContainer_t
namedVariableCollection_t Param_t
void MPI_Send_reqvars(reqVarContainer_t reqvars, std::size_t pid, MPI_Comm comm)
void MPI_Send_params(Param_t params, std::size_t pid, MPI_Comm comm)
void MPI_Recv_reqvars(reqVarContainer_t &reqvars, std::size_t pid, MPI_Comm comm)
void MPI_Recv_params(Param_t ¶ms, std::size_t pid, MPI_Comm comm)
std::shared_ptr< CmdArguments > CmdArguments_t
#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 (
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
constexpr char BoldMagenta[]
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, std::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_
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_
std::unique_ptr< Trace > job_trace_
Expressions::Named_t constraints_
constraints
MPI_Comm opt_comm_
MPI communicator used for messages to/from optimizer.
Expressions::Named_t objectives_
objectives
std::shared_ptr< Comm_t > comm_
MPI_Comm worker_comm_
MPI communicator used for messages to/from worker.
DVarContainer_t dvars_
design variables
void parseInputFile(functionDictionary_t, bool isOptimizationRun)