Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Implement smpirun --help-coll.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 13 Jun 2023 08:49:01 +0000 (10:49 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 13 Jun 2023 09:36:26 +0000 (11:36 +0200)
src/smpi/colls/smpi_coll.cpp
src/smpi/include/smpi_coll.hpp
src/smpi/internals/smpi_global.cpp
src/smpi/smpirun.in
teshsuite/smpi/CMakeLists.txt

index b9d1680..4daa1d5 100644 (file)
 #include "smpi_request.hpp"
 #include "xbt/config.hpp"
 
+#include <iomanip>
 #include <map>
+#include <numeric>
+#include <sstream>
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_coll, smpi, "Logging specific to SMPI collectives.");
 
@@ -242,6 +245,28 @@ std::vector<s_mpi_coll_description_t>* colls::get_smpi_coll_descriptions(const s
   return &iter->second;
 }
 
+std::string colls::get_smpi_coll_help()
+{
+  size_t max_name_len =
+      std::accumulate(begin(smpi_coll_descriptions), end(smpi_coll_descriptions), 0, [](auto len, auto const& coll) {
+        return std::max(len, std::accumulate(begin(coll.second), end(coll.second), 0, [](auto len, auto const& descr) {
+                          return std::max<size_t>(len, descr.name.length());
+                        }));
+      });
+  std::ostringstream oss;
+  std::string title = "Available collective algorithms (select them with \"smpi/collective_name:algo_name\"):";
+  oss << title << '\n' << std::setfill('=') << std::setw(title.length() + 1);
+  for (auto const& [coll, algos] : smpi_coll_descriptions) {
+    std::string line = "Collective: \"" + coll + "\"";
+    oss << '\n' << line << '\n' << std::setfill('-') << std::setw(line.length() + 1) << '\n';
+    oss << std::setfill(' ') << std::left;
+    for (auto const& [name, descr, _] : algos)
+      oss << "  " << std::setw(max_name_len) << name << " " << descr << "\n";
+    oss << std::right;
+  }
+  return oss.str();
+}
+
 static s_mpi_coll_description_t* find_coll_description(const std::string& collective, const std::string& algo)
 {
   std::vector<s_mpi_coll_description_t>* table = colls::get_smpi_coll_descriptions(collective);
index b882209..786a5e8 100644 (file)
@@ -57,6 +57,7 @@ struct s_mpi_coll_description_t {
 namespace colls {
 void set_collectives();
 XBT_PUBLIC std::vector<s_mpi_coll_description_t>* get_smpi_coll_descriptions(const std::string& name);
+std::string get_smpi_coll_help();
 
 void set_gather(const std::string& name);
 void set_allgather(const std::string& name);
index b7d4dce..36a3e39 100644 (file)
@@ -520,6 +520,10 @@ int smpi_main(const char* executable, int argc, char* argv[])
      * configuration tools */
     return 0;
   }
+  if (argv[0] == std::string("--help-coll")) {
+    std::cerr << simgrid::smpi::colls::get_smpi_coll_help();
+    return 0;
+  }
 
   smpi_init_options_internal(true);
   simgrid::s4u::Engine engine(&argc, argv);
index 2e94996..b52c5e1 100755 (executable)
@@ -240,6 +240,10 @@ while true; do
             usage
             exit 0
             ;;
+        "--help-coll")
+            ${WRAPPER} "@SMPIMAIN@" --help-coll
+            exit 0
+            ;;
         "-version" | "--version" | "-v")
             printf '%b\n' "$SIMGRID_VERSION"
             exit 0
index ce735ed..25b8ce3 100644 (file)
@@ -57,6 +57,8 @@ set(bin_files       ${bin_files}    ${CMAKE_CURRENT_SOURCE_DIR}/hostfile
 
 
 if(enable_smpi)
+  ADD_TEST(test-smpi-help-coll ${CMAKE_BINARY_DIR}/smpi_script/bin/smpirun -wrapper "${VALGRIND_WRAPPER_NO_LEAK_CHECK}" --help-coll)
+
   ADD_TESH_FACTORIES(tesh-smpi-macro-shared "*" --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/smpi/macro-shared --cd ${CMAKE_BINARY_DIR}/teshsuite/smpi/macro-shared ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/macro-shared/macro-shared.tesh)
   ADD_TESH_FACTORIES(tesh-smpi-auto-shared "*" --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/smpi/auto-shared --cd ${CMAKE_BINARY_DIR}/teshsuite/smpi/auto-shared ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/auto-shared/auto-shared.tesh)
   ADD_TESH_FACTORIES(tesh-smpi-macro-partial-shared "*" --setenv platfdir=${CMAKE_HOME_DIRECTORY}/examples/platforms --setenv bindir=${CMAKE_BINARY_DIR}/teshsuite/smpi/macro-partial-shared --cd ${CMAKE_BINARY_DIR}/teshsuite/smpi/macro-partial-shared ${CMAKE_HOME_DIRECTORY}/teshsuite/smpi/macro-partial-shared/macro-partial-shared.tesh)