Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
More doc for SMPI
[simgrid.git] / src / smpi / colls / smpi_coll.cpp
index b9d1680..cf22e98 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,29 @@ 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) << '\n';
+  for (auto const& [coll, algos] : smpi_coll_descriptions) {
+    std::string line = "Collective: \"" + coll + "\"";
+    oss << 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 << '\n';
+  }
+  oss << "Please see https://simgrid.org/doc/latest/app_smpi.html#available-algorithms for more information.\n";
+  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);
@@ -258,7 +284,8 @@ static s_mpi_coll_description_t* find_coll_description(const std::string& collec
   std::string name_list = table->at(0).name;
   for (unsigned long i = 1; i < table->size(); i++)
     name_list = name_list + ", " + table->at(i).name;
-  xbt_die("Collective '%s' has no algorithm '%s'! Valid algorithms: %s.", collective.c_str(), algo.c_str(), name_list.c_str());
+  xbt_die("Collective '%s' has no algorithm '%s'! Valid algorithms: %s. Please use --help-coll for details.",
+          collective.c_str(), algo.c_str(), name_list.c_str());
 }
 
 int (*colls::gather)(const void* send_buff, int send_count, MPI_Datatype send_type, void* recv_buff, int recv_count,