-/* Copyright (c) 2004-2022. The SimGrid Team.
+/* Copyright (c) 2004-2023. The SimGrid Team.
* All rights reserved. */
/* This program is free software; you can redistribute it and/or modify it
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_deployment_register_process(const std::string& instance_id, int rank, const simgrid::s4u::Actor* actor)
{
MPI_Comm* smpi_deployment_comm_world(const std::string& instance_id)
{
- 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);
return &instance.comm_world_;
}