97 ,
class SolPropagationGraph_t
122 setup(known_expr_funcs);
130 std::vector<double> hypervolRef = {},
131 bool isOptimizerRun =
true,
132 const std::map<std::string, std::string> &userVariables = {})
142 setup(known_expr_funcs, userVariables);
173 typedef MasterNode<
typename Opt_t::SolutionState_t,
194 typedef std::map<size_t, std::pair<Param_t, reqVarContainer_t> >
Jobs_t;
204 const std::map<std::string, std::string> &userVariables) {
209 std::cout <<
" _ _ _ _ " << std::endl;
210 std::cout <<
" | | (_) | | | " << std::endl;
211 std::cout <<
" ___ _ __ | |_ ______ _ __ _| | ___ | |_ " << std::endl;
212 std::cout <<
" / _ \\| '_ \\| __|______| '_ \\| | |/ _ \\| __|" << std::endl;
213 std::cout <<
"| (_) | |_) | |_ | |_) | | | (_) | |_ " << std::endl;
214 std::cout <<
" \\___/| .__/ \\__| | .__/|_|_|\\___/ \\__|" << std::endl;
215 std::cout <<
" | | | | " << std::endl;
216 std::cout <<
" |_| |_| " << std::endl;
221 std::cout << std::endl;
224 MPI_Barrier(MPI_COMM_WORLD);
240 std::cout <<
"Could not find 'inputfile' in arguments.. Aborting."
247 "No objectives or dvars specified");
251 std::ostringstream os;
254 <<
" objectives" << std::endl;
255 if (isOptimizationRun) {
257 <<
" constraints" << std::endl;
259 os <<
" ✔ " <<
dvars_.size()
260 <<
" dvars" << std::endl;
263 std::cout << os.str() << std::flush;
266 MPI_Barrier(MPI_COMM_WORLD);
272 std::ostringstream os;
275 std::cout << os.str() << std::flush;
277 const std::unique_ptr<Opt_t> opt(
282 std::cout <<
"Stop Opt.." << std::endl;
286 void startWorker(
const std::map<std::string, std::string> &userVariables) {
288 std::ostringstream os;
291 std::cout << os.str() << std::flush;
295 if(pos != std::string::npos)
297 pos = tmplfile.find(
".");
298 std::string simName = tmplfile.substr(0,pos);
300 const std::unique_ptr< Worker<Sim_t> > w(
304 std::cout <<
"Stop Worker.." << std::endl;
310 std::ostringstream os;
313 std::cout << os.str() << std::flush;
316 std::ostringstream trace_filename;
317 trace_filename <<
"pilot.trace." <<
comm_->getBundle().island_id;
320 std::shared_ptr<TraceComponent>(
new FileSink(trace_filename.str())));
341 int alpha =
cmd_args_->getArg<
int>(
"initialPopulation",
false);
344 size_t upperbound_buffer_size =
345 sizeof(double) * alpha * (1 + opt_size) * 1000
348 new MasterNode<
typename Opt_t::SolutionState_t,
349 SolPropagationGraph_t >(
351 comm_->getBundle().island_id));
358 std::cout <<
"Stop Pilot.." << std::endl;
378 bool all_worker_idle =
true;
398 MPI_Isend(&dummy, 1, MPI_INT, worker,
412 size_t jid = job->first;
414 Param_t job_params = job->second.first;
422 std::pair<Param_t, reqVarContainer_t> >(job->first, job->second));
426 std::ostringstream dump;
427 dump <<
"sent job with ID " << jid <<
" to worker " << worker
442 size_t job_id = recv_value;
445 MPI_Send(&dummy, 1, MPI_UNSIGNED_LONG, status.MPI_SOURCE,
454 std::ostringstream dump;
455 dump <<
"worker finished job with ID " << job_id << std::endl;
462 int opt_master_rank =
comm_->getLeader();
463 MPI_Send(&job_id, 1, MPI_UNSIGNED_LONG, opt_master_rank,
477 size_t job_id = recv_value;
478 int opt_master_rank =
comm_->getLeader();
486 std::pair<Param_t, reqVarContainer_t> job =
487 std::pair<Param_t, reqVarContainer_t>(job_params, reqVars);
489 std::pair<
size_t, std::pair<Param_t, reqVarContainer_t> >(
492 std::ostringstream dump;
493 dump <<
"new opt job with ID " << job_id << std::endl;
503 std::ostringstream dump;
504 dump <<
"starting solution exchange.. " << status.MPI_SOURCE << std::endl;
508 size_t buffer_size = recv_value;
509 int opt_master_rank = status.MPI_SOURCE;
511 char *buffer =
new char[buffer_size];
512 MPI_Recv(buffer, buffer_size, MPI_CHAR, opt_master_rank,
518 dump.str(std::string());
519 dump <<
"getting " << buffer_size <<
" bytes from OPT "
520 << opt_master_rank << std::endl;
524 std::ostringstream states;
526 buffer_size = states.str().length();
529 dump.str(std::string());
530 dump <<
"collected solution states of other PILOTS: "
531 << buffer_size <<
" bytes" << std::endl;
535 MPI_Send(&buffer_size, 1, MPI_UNSIGNED_LONG, opt_master_rank,
538 buffer =
new char[buffer_size];
539 std::memcpy(buffer, states.str().c_str(), buffer_size);
540 MPI_Send(buffer, buffer_size, MPI_CHAR, opt_master_rank,
544 dump.str(std::string());
545 dump <<
"sent set of new solutions to OPT" << std::endl;
563 std::string msg =
"(Pilot) Error: unexpected MPI_TAG: ";
564 msg += status.MPI_TAG;
580 if(! isOpt)
return true;
583 if(!
cmd_args_->getArg<
bool>(
"one-pilot-converge",
false,
false))
591 if(i == my_rank)
continue;
605 MPI_Request opt_request;
606 MPI_Request worker_request;
609 size_t recv_value_worker = 0;
610 size_t recv_value_opt = 0;
614 MPI_Irecv(&recv_value_opt, 1, MPI_UNSIGNED_LONG, MPI_ANY_SOURCE,
616 MPI_Irecv(&recv_value_worker, 1, MPI_UNSIGNED_LONG, MPI_ANY_SOURCE,
619 bool pending_opt_request =
true;
620 bool pending_worker_request =
true;
621 bool pending_pilot_request =
false;
623 MPI_Request pilot_request;
624 size_t recv_value_pilot = 0;
625 if(
cmd_args_->getArg<
bool>(
"one-pilot-converge",
false,
false)) {
626 MPI_Irecv(&recv_value_pilot, 1, MPI_UNSIGNED_LONG, MPI_ANY_SOURCE,
628 pending_pilot_request =
true;
635 if(opt_request != MPI_REQUEST_NULL) {
636 MPI_Test(&opt_request, &flag, &status);
638 pending_opt_request =
false;
643 MPI_Irecv(&recv_value_opt, 1, MPI_UNSIGNED_LONG,
646 pending_opt_request =
true;
653 if(worker_request != MPI_REQUEST_NULL) {
654 MPI_Test(&worker_request, &flag, &status);
656 pending_worker_request =
false;
660 if(
onMessage(status, recv_value_worker)) {
661 MPI_Irecv(&recv_value_worker, 1,
662 MPI_UNSIGNED_LONG, MPI_ANY_SOURCE, MPI_ANY_TAG,
664 pending_worker_request =
true;
671 if(
cmd_args_->getArg<
bool>(
"one-pilot-converge",
false,
false)) {
672 if(pilot_request != MPI_REQUEST_NULL) {
673 MPI_Test(&pilot_request, &flag, &status);
675 pending_pilot_request =
false;
679 MPI_Irecv(&recv_value_pilot, 1,
680 MPI_UNSIGNED_LONG, MPI_ANY_SOURCE, MPI_ANY_TAG,
682 pending_pilot_request =
true;
691 if(pending_opt_request) MPI_Cancel( &opt_request );
692 if(pending_worker_request) MPI_Cancel( &worker_request );
693 if(pending_pilot_request) MPI_Cancel( &pilot_request );
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_EXCHANGE_SOL_STATE_DATA_TAG
#define MPI_OPT_JOB_FINISHED_TAG
pilot tells optimizer that results are ready to collect
#define MPI_EXCHANGE_SOL_STATE_RES_SIZE_TAG
#define MPI_EXCHANGE_SOL_STATE_RES_TAG
@ 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 (
std::map< std::string, Expressions::Expr_t * > Named_t
type of an expressions with a name
constexpr char BoldMagenta[]
int total_available_workers_
MPI_Comm coworker_comm_
MPI communicator used for messages between all pilots.
void setup(functionDictionary_t known_expr_funcs, const std::map< std::string, std::string > &userVariables)
std::string input_file_
input file for simulation with embedded optimization problem
std::map< size_t, std::pair< Param_t, reqVarContainer_t > > Jobs_t
keep track of requests and running jobs
virtual void setupPoll()
executed before starting polling loop
std::vector< bool > is_worker_idle_
virtual void startPilot()
virtual void startWorker(const std::map< std::string, std::string > &userVariables)
virtual void startOptimizer()
bool stop(bool isOpt=true)
virtual void prePoll()
executed before checking for new request
Jobs_t::iterator JobIter_t
int my_rank_in_worker_comm_
std::unique_ptr< Trace > job_trace_
Expressions::Named_t constraints_
constraints
virtual void onStop()
enable implementation to react to STOP tag
virtual void sendNewJobToWorker(int worker)
std::unique_ptr< MasterNode_t > master_node_
MasterNode< typename Opt_t::SolutionState_t, SolPropagationGraph_t > MasterNode_t
Pilot(CmdArguments_t args, std::shared_ptr< Comm_t > comm, const DVarContainer_t &dvar)
std::vector< double > hypervolRef_
hypervolume reference point
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.
virtual void postPoll()
executed after handling (if any) new request
DVarContainer_t dvars_
design variables
virtual bool onMessage(MPI_Status status, size_t recv_value)
Pilot(CmdArguments_t args, std::shared_ptr< Comm_t > comm, functionDictionary_t known_expr_funcs)
void parseInputFile(functionDictionary_t, bool isOptimizationRun)
Pilot(CmdArguments_t args, std::shared_ptr< Comm_t > comm, functionDictionary_t known_expr_funcs, const DVarContainer_t &dvar, const Expressions::Named_t &obj, const Expressions::Named_t &cons, std::vector< double > hypervolRef={}, bool isOptimizerRun=true, const std::map< std::string, std::string > &userVariables={})
MPI_Comm comm_m
communicator the poller listens to requests