Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Constify pointer and reference local variables in src/smpi/.
[simgrid.git] / src / smpi / internals / smpi_deployment.cpp
index d2dd6b4..7bbf747 100644 (file)
@@ -33,8 +33,7 @@ public:
   }
 
   const std::string name_;
-  int size_;
-  std::vector<simgrid::s4u::ActorPtr> present_processes_;
+  unsigned int size_;
   unsigned int finalized_ranks_ = 0;
   MPI_Comm comm_world_;
 };
@@ -61,33 +60,23 @@ void SMPI_app_instance_register(const char *name, xbt_main_func_t code, int num_
   if (code != nullptr) // When started with smpirun, we will not execute a function
     simgrid::s4u::Engine::get_instance()->register_function(name, code);
 
-  static bool already_called = false;
-  if (not already_called) {
-    already_called = true;
-    for (auto const& host : simgrid::s4u::Engine::get_instance()->get_all_hosts())
-      host->extension_set(new simgrid::smpi::Host(host));
-  }
-
   Instance instance(std::string(name), num_processes, MPI_COMM_NULL);
 
   smpi_instances.insert(std::pair<std::string, Instance>(name, instance));
 }
 
-void smpi_deployment_register_process(const std::string& instance_id, int rank, simgrid::s4u::ActorPtr actor)
+void smpi_deployment_register_process(const std::string& instance_id, int rank, simgrid::s4u::Actor* actor)
 {
-  Instance& instance = smpi_instances.at(instance_id);
-
-  instance.present_processes_.push_back(actor);
+  const Instance& instance = smpi_instances.at(instance_id);
   instance.comm_world_->group()->set_mapping(actor, rank);
 }
 
 void smpi_deployment_unregister_process(const std::string& instance_id)
 {
   Instance& instance = smpi_instances.at(instance_id);
-
   instance.finalized_ranks_++;
-  if (instance.finalized_ranks_ == instance.present_processes_.size()) {
-    instance.present_processes_.clear();
+
+  if (instance.finalized_ranks_ == instance.size_) {
     simgrid::smpi::Comm::destroy(instance.comm_world_);
     smpi_instances.erase(instance_id);
   }
@@ -95,7 +84,8 @@ void smpi_deployment_unregister_process(const std::string& instance_id)
 
 MPI_Comm* smpi_deployment_comm_world(const std::string& instance_id)
 {
-  if (smpi_instances.empty()) { // no instance registered, we probably used smpirun.
+  if (smpi_instances
+          .empty()) { // no instance registered, we probably used smpirun. (FIXME: I guess this never happens for real)
     return nullptr;
   }
   Instance& instance = smpi_instances.at(instance_id);
@@ -106,7 +96,6 @@ void smpi_deployment_cleanup_instances(){
   for (auto const& item : smpi_instances) {
     XBT_CINFO(smpi, "Stalling SMPI instance: %s. Do all your MPI ranks call MPI_Finalize()?", item.first.c_str());
     Instance instance = item.second;
-    instance.present_processes_.clear();
     simgrid::smpi::Comm::destroy(instance.comm_world_);
   }
   smpi_instances.clear();