Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use 'std::vector' instead of a C-style array.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 11 Jun 2021 08:20:04 +0000 (10:20 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 11 Jun 2021 08:20:04 +0000 (10:20 +0200)
src/smpi/include/private.hpp
src/smpi/internals/smpi_deployment.cpp
src/smpi/internals/smpi_global.cpp

index 08e6cf3..03f9c70 100644 (file)
@@ -85,7 +85,8 @@ XBT_PRIVATE void smpi_deployment_unregister_process(const std::string& instance_
 XBT_PRIVATE MPI_Comm* smpi_deployment_comm_world(const std::string& instance_id);
 XBT_PRIVATE void smpi_deployment_cleanup_instances();
 XBT_PRIVATE int smpi_deployment_smpirun(const simgrid::s4u::Engine* e, const std::string& hostfile, int np,
-                                        const std::string& replayfile, int map, int argc, char* argv[]);
+                                        const std::string& replayfile, int map,
+                                        const std::vector<const char*>& run_args);
 
 XBT_PRIVATE void smpi_comm_copy_buffer_callback(simgrid::kernel::activity::CommImpl* comm, void* buff,
                                                 size_t buff_size);
index 12688f0..576176b 100644 (file)
@@ -141,20 +141,16 @@ static std::vector<std::string> smpi_read_replay(const std::string& replayfile)
 }
 
 /** @brief Build argument vector to pass to process */
-static std::vector<std::string> smpi_deployment_get_args(int rank_id, const std::vector<std::string>& replay, int argc,
-                                                         char* argv[])
+static std::vector<std::string> smpi_deployment_get_args(int rank_id, const std::vector<std::string>& replay,
+                                                         const std::vector<const char*>& run_args)
 {
   std::vector<std::string> args{std::to_string(rank_id)};
   // pass arguments to process only if not a replay execution
-  if (replay.empty()) {
-    for (int i = 0; i < argc; i++) {
-      args.emplace_back(argv[i]);
-    }
-  }
+  if (replay.empty())
+    args.insert(args.end(), begin(run_args), end(run_args));
   /* one trace per process */
-  if (replay.size() > 1) {
+  if (replay.size() > 1)
     args.emplace_back(replay[rank_id]);
-  }
   return args;
 }
 
@@ -165,7 +161,7 @@ static std::vector<std::string> smpi_deployment_get_args(int rank_id, const std:
  * If hostfile isn't provided, get the list of hosts from engine.
  */
 int smpi_deployment_smpirun(const simgrid::s4u::Engine* e, const std::string& hostfile, int np,
-                            const std::string& replayfile, int map, int argc, char* argv[])
+                            const std::string& replayfile, int map, const std::vector<const char*>& run_args)
 {
   auto hosts     = smpi_get_hosts(e, hostfile);
   auto replay    = smpi_read_replay(replayfile);
@@ -182,7 +178,7 @@ int smpi_deployment_smpirun(const simgrid::s4u::Engine* e, const std::string& ho
   for (int i = 0; i < np; i++) {
     simgrid::s4u::Host* host = hosts[i % hosts_size];
     std::string rank_id      = std::to_string(i);
-    auto args                = smpi_deployment_get_args(i, replay, argc, argv);
+    auto args                = smpi_deployment_get_args(i, replay, run_args);
     auto actor               = simgrid::s4u::Actor::create(rank_id, host, rank_id, args);
     /* keeping the same behavior as done in smpirun script, print mapping rank/process */
     if (map != 0) {
index d2d7f1b..ee5fd23 100644 (file)
@@ -565,8 +565,9 @@ int smpi_main(const char* executable, int argc, char* argv[])
   
   SMPI_init();
 
-  int rank_counts = smpi_deployment_smpirun(engine, smpi_hostfile.get(), smpi_np.get(), smpi_replay.get(),
-                                            smpi_map.get(), argc - 2, argv + 2);
+  const std::vector<const char*> args(argv + 2, argv + argc);
+  int rank_counts =
+      smpi_deployment_smpirun(engine, smpi_hostfile.get(), smpi_np.get(), smpi_replay.get(), smpi_map.get(), args);
 
   SMPI_app_instance_register(smpi_default_instance_name.c_str(), nullptr, rank_counts);
   MPI_COMM_WORLD = *smpi_deployment_comm_world(smpi_default_instance_name);