Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Explicit cast when loosing precision (C++ examples).
[simgrid.git] / examples / smpi / smpi_s4u_masterslave / masterslave_mailbox_smpi.cpp
index 1e583cee66a57be9754c55b347efd8a8f69efaa3..6ed9f330e97fd623ee5a1f1c14f25e7554f3bed2 100644 (file)
@@ -14,9 +14,9 @@ static void master(std::vector<std::string> args)
 {
   xbt_assert(args.size() > 4, "The master function expects at least 3 arguments");
 
-  long tasks_count          = std::stol(args[1]);
-  double compute_cost       = std::stod(args[2]);
-  double communication_cost = std::stod(args[3]);
+  long tasks_count        = std::stol(args[1]);
+  double compute_cost     = std::stod(args[2]);
+  long communication_cost = std::stol(args[3]);
   std::vector<simgrid::s4u::Mailbox*> workers;
   for (unsigned int i = 4; i < args.size(); i++)
     workers.push_back(simgrid::s4u::Mailbox::by_name(args[i]));
@@ -56,13 +56,12 @@ static void worker(std::vector<std::string> args)
 
     if (compute_cost > 0) /* If compute_cost is valid, execute a computation of that cost */
       simgrid::s4u::this_actor::execute(compute_cost);
-
   } while (compute_cost > 0); /* Stop when receiving an invalid compute_cost */
 
   XBT_INFO("Exiting now.");
 }
 
-static int master_mpi(int argc, char* argv[])
+static void master_mpi(int argc, char* argv[])
 {
   MPI_Init(&argc, &argv);
 
@@ -79,10 +78,9 @@ static int master_mpi(int argc, char* argv[])
   MPI_Finalize();
 
   XBT_INFO("After finalize %d %d", rank, test[0]);
-  return 0;
 }
 
-static int alltoall_mpi(int argc, char* argv[])
+static void alltoall_mpi(int argc, char* argv[])
 {
   MPI_Init(&argc, &argv);
 
@@ -91,15 +89,12 @@ static int alltoall_mpi(int argc, char* argv[])
   MPI_Comm_rank(MPI_COMM_WORLD, &rank);
   MPI_Comm_size(MPI_COMM_WORLD, &size);
   XBT_INFO("alltoall for rank %d", rank);
-  int* out = new int[1000 * size];
-  int* in  = new int[1000 * size];
-  MPI_Alltoall(out, 1000, MPI_INT, in, 1000, MPI_INT, MPI_COMM_WORLD);
+  std::vector<int> out(1000 * size);
+  std::vector<int> in(1000 * size);
+  MPI_Alltoall(out.data(), 1000, MPI_INT, in.data(), 1000, MPI_INT, MPI_COMM_WORLD);
 
   XBT_INFO("after alltoall %d", rank);
-  delete[] out;
-  delete[] in;
   MPI_Finalize();
-  return 0;
 }
 
 int main(int argc, char* argv[])