X-Git-Url: http://bilbo.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/3a1ea70a418f393ca1677074e928c664022295bd..2ef958bf49890e4ac8fbe179f1d339b923fb67a8:/examples/smpi/smpi_s4u_masterworker/masterworker_mailbox_smpi.cpp diff --git a/examples/smpi/smpi_s4u_masterworker/masterworker_mailbox_smpi.cpp b/examples/smpi/smpi_s4u_masterworker/masterworker_mailbox_smpi.cpp index 76afde33f8..d81d9fa2bd 100644 --- a/examples/smpi/smpi_s4u_masterworker/masterworker_mailbox_smpi.cpp +++ b/examples/smpi/smpi_s4u_masterworker/masterworker_mailbox_smpi.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2010-2020. The SimGrid Team. All rights reserved. */ +/* Copyright (c) 2010-2023. The SimGrid Team. All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it * under the terms of the license (GNU LGPL) which comes with this package. */ @@ -6,9 +6,10 @@ #include "mpi.h" #include "simgrid/s4u.hpp" +#include #include /* snprintf */ -XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example"); +XBT_LOG_NEW_DEFAULT_CATEGORY(smpi_masterworkers, "Messages specific for this example"); static void master(std::vector args) { @@ -50,9 +51,8 @@ static void worker(std::vector args) double compute_cost; do { - const auto* msg = static_cast(mailbox->get()); - compute_cost = *msg; - delete msg; + auto msg = mailbox->get_unique(); + compute_cost = *msg; if (compute_cost > 0) /* If compute_cost is valid, execute a computation of that cost */ simgrid::s4u::this_actor::execute(compute_cost); @@ -68,11 +68,11 @@ static void master_mpi(int argc, char* argv[]) int rank; MPI_Comm_rank(MPI_COMM_WORLD, &rank); XBT_INFO("here for rank %d", rank); - int test[1000] = {rank}; + std::array test{{rank}}; if (rank == 0) - MPI_Send(&test, 1000, MPI_INT, 1, 1, MPI_COMM_WORLD); + MPI_Send(test.data(), 1000, MPI_INT, 1, 1, MPI_COMM_WORLD); else - MPI_Recv(&test, 1000, MPI_INT, 0, 1, MPI_COMM_WORLD, MPI_STATUSES_IGNORE); + MPI_Recv(test.data(), 1000, MPI_INT, 0, 1, MPI_COMM_WORLD, MPI_STATUSES_IGNORE); XBT_INFO("After comm %d", rank); MPI_Finalize(); @@ -80,9 +80,9 @@ static void master_mpi(int argc, char* argv[]) XBT_INFO("After finalize %d %d", rank, test[0]); } -static void alltoall_mpi(int argc, char* argv[]) +static void alltoall_mpi() { - MPI_Init(&argc, &argv); + MPI_Init(); int rank; int size; @@ -105,7 +105,7 @@ int main(int argc, char* argv[]) xbt_assert(argc > 2, "Usage: %s platform_file deployment_file\n" - "\nexample: %s msg_platform.xml msg_deployment.xml\n", + "\nexample: %s platform.xml deployment.xml\n", argv[0], argv[0]); e.load_platform(argv[1]); @@ -114,13 +114,26 @@ int main(int argc, char* argv[]) e.register_function("worker", worker); // launch two MPI applications as well, one using master_mpi function as main on 2 nodes SMPI_app_instance_register("master_mpi", master_mpi, 2); - // the second performing an alltoall on 4 nodes - SMPI_app_instance_register("alltoall_mpi", alltoall_mpi, 4); e.load_deployment(argv[2]); + // the second performing an alltoall on 4 nodes, started directly, not from the deployment file + SMPI_app_instance_start("alltoall_mpi", alltoall_mpi, + {e.host_by_name_or_null("Ginette"), e.host_by_name_or_null("Bourassa"), + e.host_by_name_or_null("Jupiter"), e.host_by_name_or_null("Fafard")}); + + // Start a third MPI application, from a S4U actor after a delay of 10 sec + simgrid::s4u::Actor::create("launcher", e.host_by_name_or_null("Ginette"), [&e]() { + simgrid::s4u::this_actor::sleep_for(10); + XBT_INFO("Start another alltoall_mpi instance"); + SMPI_app_instance_start("alltoall_mpi", alltoall_mpi, + {e.host_by_name_or_null("Ginette"), e.host_by_name_or_null("Bourassa"), + e.host_by_name_or_null("Jupiter"), e.host_by_name_or_null("Fafard")}); + SMPI_app_instance_join("alltoall_mpi"); + XBT_INFO("This other alltoall_mpi instance terminated."); + }); e.run(); - XBT_INFO("Simulation time %g", e.get_clock()); + XBT_INFO("Simulation time %g", simgrid::s4u::Engine::get_clock()); SMPI_finalize(); return 0;