Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use Mailbox::get_unique<>(), and save a few delete.
[simgrid.git] / examples / smpi / smpi_s4u_masterworker / masterworker_mailbox_smpi.cpp
index 76afde33f88e427b5e9c0386fe44f37321d31c62..ae85a9a86e8a1945f61ceebde25d1b2f6fe75a65 100644 (file)
@@ -6,6 +6,7 @@
 #include "mpi.h"
 #include "simgrid/s4u.hpp"
 
+#include <array>
 #include <cstdio> /* snprintf */
 
 XBT_LOG_NEW_DEFAULT_CATEGORY(msg_test, "Messages specific for this msg example");
@@ -50,9 +51,8 @@ static void worker(std::vector<std::string> args)
 
   double compute_cost;
   do {
-    const auto* msg   = static_cast<double*>(mailbox->get());
-    compute_cost      = *msg;
-    delete msg;
+    auto msg     = mailbox->get_unique<double>();
+    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<int, 1000> 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();