Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Introduce SMPI_app_instance_join()
[simgrid.git] / src / smpi / internals / smpi_deployment.cpp
index 5e36060..c39bbd5 100644 (file)
@@ -54,6 +54,38 @@ void SMPI_app_instance_register(const char *name, xbt_main_func_t code, int num_
 
   smpi_instances.try_emplace(name, num_processes);
 }
+void SMPI_app_instance_start(const char* name, const std::function<void()>& code,
+                             std::vector<simgrid::s4u::Host*> const& hosts)
+{
+  xbt_assert(not hosts.empty(), "Cannot start a SMPI instance on 0 hosts");
+
+  auto [_, inserted] = smpi_instances.try_emplace(name, hosts.size());
+  xbt_assert(inserted, "Cannot start two MPI applications of the same name '%s'", name);
+
+  int rank = 0;
+  for (auto* host : hosts) {
+    auto rank_str = std::to_string(rank);
+    auto actor    = simgrid::s4u::Actor::init(std::string(name) + "#" + rank_str, host);
+    actor->set_property("instance_id", name);
+    actor->set_property("rank", rank_str);
+    actor->start(code);
+
+    smpi_deployment_register_process(name, rank, actor.get());
+
+    rank++;
+  }
+}
+void SMPI_app_instance_join(const std::string& instance_id)
+{
+  std::vector<simgrid::s4u::ActorPtr> actors =
+      simgrid::s4u::Engine::get_instance()->get_filtered_actors([instance_id](simgrid::s4u::ActorPtr act) {
+        auto* actor_instance = act->get_property("instance_id");
+        return actor_instance != nullptr && strcmp(actor_instance, instance_id.c_str()) == 0;
+      });
+
+  for (auto& act : actors)
+    act->join();
+}
 
 void smpi_deployment_register_process(const std::string& instance_id, int rank, const simgrid::s4u::Actor* actor)
 {