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 const std::unique_ptr<Opt_t> opt(
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 const std::unique_ptr< SampleWorker<Sim_t> > w(
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;
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,
262 size_t job_id = recv_value;
263 int opt_master_rank = this->
comm_->getLeader();
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>
Expression Expr_t
type of an expression
DVarContainer_t dvars_
design variables
virtual void sendNewJobToWorker(int worker)
int total_available_workers_
namedVariableCollection_t Param_t
int my_rank_in_worker_comm_
std::string input_file_
input file for simulation with embedded optimization problem
and that you know you can do these things To protect your we need to make restrictions that forbid anyone to deny you these rights or to ask you to surrender the rights These restrictions translate to certain responsibilities for you if you distribute copies of the or if you modify it For if you distribute copies of such a whether gratis or for a you must give the recipients all the rights that you have You must make sure that receive or can get the source code And you must show them these terms so they know their rights We protect your rights with two distribute and or modify the software for each author s protection and we want to make certain that everyone understands that there is no warranty for this free software If the software is modified by someone else and passed we want its recipients to know that what they have is not the so that any problems introduced by others will not reflect on the original authors reputations any free program is threatened constantly by software patents We wish to avoid the danger that redistributors of a free program will individually obtain patent in effect making the program proprietary To prevent this
virtual void postPoll()
executed after handling (if any) new request
std::vector< bool > is_worker_idle_
Expressions::Named_t objectives_
objectives
void parseInputFile(functionDictionary_t, bool isOptimizationRun)
std::unique_ptr< Trace > job_trace_
virtual void startPilot()
std::map< std::string, DVar_t > DVarContainer_t
Expressions::Named_t constraints_
constraints
void startWorker(const std::vector< std::string > &storeobjstr, const std::vector< std::string > &filesToKeep, const std::map< std::string, std::string > &userVariables)
Inform & endl(Inform &inf)
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
MPI_Comm worker_comm_
MPI communicator used for messages to/from worker.
std::string::iterator iterator
#define MPI_WORK_JOBID_TAG
unique id of the job
std::map< std::string, std::shared_ptr< SamplingMethod > > sampleMethods_m
#define MPI_OPT_JOB_FINISHED_TAG
pilot tells optimizer that results are ready to collect
void MPI_Send_reqvars(reqVarContainer_t reqvars, size_t pid, MPI_Comm comm)
std::shared_ptr< CmdArguments > CmdArguments_t
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)
std::map< std::string, client::function::type > functionDictionary_t
bool stop(bool isOpt=true)
#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
void MPI_Recv_reqvars(reqVarContainer_t &reqvars, size_t pid, MPI_Comm comm)
Jobs_t::iterator JobIter_t
void MPI_Send_params(Param_t params, size_t pid, MPI_Comm comm)
std::shared_ptr< Comm_t > comm_
MPI_Comm opt_comm_
MPI communicator used for messages to/from optimizer.
void MPI_Recv_params(Param_t ¶ms, size_t pid, MPI_Comm comm)
virtual bool onMessage(MPI_Status status, size_t recv_value)
virtual void startSampler()
std::map< std::string, reqVarInfo_t > reqVarContainer_t
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)