X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/97e476dc536bfd9fada85509d1c1f93714d46a10..e9b99cc75875aaffe31d627aceb45a3583770d55:/src/smpi/internals/smpi_deployment.cpp diff --git a/src/smpi/internals/smpi_deployment.cpp b/src/smpi/internals/smpi_deployment.cpp index 929a7bee35..e73865cc55 100644 --- a/src/smpi/internals/smpi_deployment.cpp +++ b/src/smpi/internals/smpi_deployment.cpp @@ -1,4 +1,4 @@ -/* 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 @@ -13,9 +13,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(smpi); -namespace simgrid { -namespace smpi { -namespace app { +namespace simgrid::smpi::app { static int universe_size = 0; @@ -33,9 +31,7 @@ public: unsigned int finalized_ranks_ = 0; MPI_Comm comm_world_; }; -} -} -} +} // namespace simgrid::smpi::app using simgrid::smpi::app::Instance; @@ -56,9 +52,28 @@ 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); - Instance instance(num_processes); + smpi_instances.try_emplace(name, num_processes); +} +void SMPI_app_instance_start(const char* name, const std::function& code, + std::vector 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()); - smpi_instances.insert(std::pair(name, instance)); + rank++; + } } void smpi_deployment_register_process(const std::string& instance_id, int rank, const simgrid::s4u::Actor* actor) @@ -86,18 +101,13 @@ 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. (FIXME: I guess this never happens for real) - return nullptr; - } Instance& instance = smpi_instances.at(instance_id); return &instance.comm_world_; } void smpi_deployment_cleanup_instances(){ - for (auto const& item : smpi_instances) { - XBT_INFO("Stalling SMPI instance: %s. Do all your MPI ranks call MPI_Finalize()?", item.first.c_str()); - Instance instance = item.second; + for (auto const& [name, instance] : smpi_instances) { + XBT_INFO("Stalling SMPI instance: %s. Do all your MPI ranks call MPI_Finalize()?", name.c_str()); simgrid::smpi::Comm::destroy(instance.comm_world_); } smpi_instances.clear();