1212BendersMpi::BendersMpi (const BendersBaseOptions& options,
1313 std::shared_ptr<ILogger> logger,
1414 std::shared_ptr<Output::OutputWriter> writer,
15- mpi::communicator& world,
15+ std::shared_ptr< mpi::communicator> world,
1616 std::shared_ptr<MathLoggerDriver> mathLoggerDriver):
1717 BendersBase(options, std::move(logger), std::move(writer), std::move(mathLoggerDriver)),
18- _world(world)
18+ _world(std::move( world) )
1919{
2020}
2121
@@ -35,8 +35,8 @@ void BendersMpi::InitializeProblems()
3535 int current_problem_id = 0 ;
3636 for (auto it = coupling_map_.begin (); it != coupling_map_.end ();)
3737 {
38- auto process_to_feed = current_problem_id % _world. size ();
39- if (process_to_feed != _world. rank ())
38+ auto process_to_feed = current_problem_id % _world-> size ();
39+ if (process_to_feed != _world-> rank ())
4040 {
4141 it = coupling_map_.erase (it);
4242 }
@@ -54,8 +54,8 @@ void BendersMpi::InitializeProblems()
5454 for (const auto & problem: coupling_map_)
5555 {
5656 // In case there are more subproblems than process
57- if (auto process_to_feed = current_problem_id % _world. size ();
58- process_to_feed == _world. rank ())
57+ if (auto process_to_feed = current_problem_id % _world-> size ();
58+ process_to_feed == _world-> rank ())
5959 { // Assign [problemNumber % processCount] to processID
6060
6161 const auto subProblemFilePath = GetSubproblemPath (problem.first );
@@ -71,7 +71,7 @@ void BendersMpi::InitializeProblems()
7171
7272void BendersMpi::BroadCastVariablesIndices ()
7373{
74- if (_world. rank () == rank_0)
74+ if (_world-> rank () == rank_0)
7575 {
7676 SetSubproblemsVariablesIndices ();
7777 }
@@ -80,7 +80,7 @@ void BendersMpi::BroadCastVariablesIndices()
8080
8181void BendersMpi::BuildMasterProblem ()
8282{
83- if (_world. rank () == rank_0)
83+ if (_world-> rank () == rank_0)
8484 {
8585 std::shared_ptr<IBendersProblemProvider>
8686 benders_problem_provider = std::make_shared<BendersProblemFromFile>(get_master_path ());
@@ -127,7 +127,7 @@ void BendersMpi::step_1_solve_master()
127127
128128void BendersMpi::check_convergence ()
129129{
130- step_4_update_best_solution (_world. rank ());
130+ step_4_update_best_solution (_world-> rank ());
131131}
132132
133133Point BendersMpi::get_master_x () const
@@ -147,7 +147,7 @@ void BendersMpi::BuildCut()
147147
148148void BendersMpi::do_solve_master_create_trace_and_update_cuts ()
149149{
150- if (_world. rank () == rank_0)
150+ if (_world-> rank () == rank_0)
151151 {
152152 if (SwitchToIntegerMaster (_data.is_in_initial_relaxation ))
153153 {
@@ -164,7 +164,7 @@ void BendersMpi::BroadcastXCut()
164164 if (!exception_raised_)
165165 {
166166 Point x_cut = get_x_cut ();
167- mpi::broadcast (_world, x_cut, rank_0);
167+ mpi::broadcast (* _world, x_cut, rank_0);
168168 set_x_cut (x_cut);
169169 }
170170}
@@ -228,7 +228,7 @@ void BendersMpi::gather_subproblems_cut_package_and_build_cuts(
228228void BendersMpi::GatherCuts (const SubProblemDataMap& subproblem_data_map, const Timer& walltime)
229229{
230230 std::vector<SubProblemDataMap> gathered_subproblem_map;
231- mpi::gather (_world, subproblem_data_map, gathered_subproblem_map, rank_0);
231+ mpi::gather (* _world, subproblem_data_map, gathered_subproblem_map, rank_0);
232232 _data.subproblems_walltime = walltime.elapsed ();
233233 double cumulative_subproblems_timer_per_iter (0 );
234234 Reduce (_data.subproblems_cputime ,
@@ -243,7 +243,7 @@ void BendersMpi::GatherCuts(const SubProblemDataMap& subproblem_data_map, const
243243 {
244244 ComputeSubproblemsContributionToCriteria (subproblem_data_map);
245245
246- if (_world. rank () == rank_0)
246+ if (_world-> rank () == rank_0)
247247 {
248248 criteria_vector_for_each_iteration_.push_back (
249249 _data.criteria_current_iteration_data .criteria );
@@ -323,7 +323,7 @@ void BendersMpi::master_build_cuts(const std::vector<SubProblemDataMap>& gathere
323323
324324 _data.ub = 0 ;
325325
326- if (_world. rank () == rank_0)
326+ if (_world-> rank () == rank_0)
327327 {
328328 // TODO: In Benders MPI the subproblem split can be done once as it is the same at each
329329 // iteration
@@ -360,7 +360,7 @@ void BendersMpi::SetSubproblemDataCostAndSimplexIter(
360360void BendersMpi::check_if_some_proc_had_a_failure (int success)
361361{
362362 int global_success;
363- mpi::all_reduce (_world, success, global_success, mpi::bitwise_and<int >());
363+ mpi::all_reduce (* _world, success, global_success, mpi::bitwise_and<int >());
364364 if (global_success == 0 )
365365 {
366366 exception_raised_ = true ;
@@ -394,15 +394,15 @@ void BendersMpi::step_4_update_best_solution(int rank)
394394 */
395395void BendersMpi::free ()
396396{
397- if (_world. rank () == rank_0)
397+ if (_world-> rank () == rank_0)
398398 {
399399 free_master ();
400400 }
401401 else
402402 {
403403 free_subproblems ();
404404 }
405- _world. barrier ();
405+ _world-> barrier ();
406406}
407407
408408/* !
@@ -442,40 +442,40 @@ void BendersMpi::Run()
442442
443443 if (!exception_raised_)
444444 {
445- step_4_update_best_solution (_world. rank ());
445+ step_4_update_best_solution (_world-> rank ());
446446 }
447447 _data.stop |= exception_raised_;
448448
449- broadcast (_world, _data.is_in_initial_relaxation , rank_0);
450- broadcast (_world, _data.stop , rank_0);
449+ broadcast (* _world, _data.is_in_initial_relaxation , rank_0);
450+ broadcast (* _world, _data.stop , rank_0);
451451
452452 if (Rank () == rank_0)
453453 {
454454 mathLoggerDriver_->Print (_data);
455455 SaveCurrentBendersData ();
456456 }
457457 }
458- if (_world. rank () == rank_0)
458+ if (_world-> rank () == rank_0)
459459 {
460460 CloseCsvFile ();
461461 EndWritingInOutputFile ();
462462 write_basis ();
463463 }
464- _world. barrier ();
464+ _world-> barrier ();
465465}
466466
467467void BendersMpi::PreRunInitialization ()
468468{
469469 init_data ();
470470
471- if (_world. rank () == rank_0)
471+ if (_world-> rank () == rank_0)
472472 {
473473 HandleInitialMasterRelaxation ();
474474 }
475475
476- _world. barrier ();
476+ _world-> barrier ();
477477
478- if (_world. rank () == rank_0)
478+ if (_world-> rank () == rank_0)
479479 {
480480 ChecksResumeMode ();
481481 if (is_trace ())
@@ -498,7 +498,7 @@ void BendersMpi::launch()
498498 {
499499 InitializeProblems ();
500500 }
501- _world. barrier ();
501+ _world-> barrier ();
502502
503503 try
504504 {
@@ -518,13 +518,13 @@ void BendersMpi::launch()
518518 write_exception_message (ex);
519519 }
520520
521- _world. barrier ();
521+ _world-> barrier ();
522522
523523 post_run_actions ();
524524
525525 if (free_problems_)
526526 {
527527 free ();
528528 }
529- _world. barrier ();
529+ _world-> barrier ();
530530}
0 commit comments