Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Further factorization: introduce ModuleGroup::init_from_flag_value()
authorMartin Quinson <martin.quinson@ens-rennes.fr>
Wed, 15 Feb 2023 23:21:52 +0000 (00:21 +0100)
committerMartin Quinson <martin.quinson@ens-rennes.fr>
Wed, 15 Feb 2023 23:21:52 +0000 (00:21 +0100)
src/kernel/routing/NetZoneImpl.cpp
src/simgrid/module.cpp
src/simgrid/module.hpp
src/surf/host_clm03.cpp

index 8791ad7..404709e 100644 (file)
@@ -27,9 +27,7 @@ namespace simgrid::kernel::routing {
 /* Pick the right models for CPU, net and host, and call their model_init_preparse */
 static void surf_config_models_setup()
 {
-  std::string host_model_name = simgrid::config::get_value<std::string>("host/model");
-
-  simgrid_host_models().by_name(host_model_name).init();
+  simgrid_host_models().init_from_flag_value();
 
   XBT_DEBUG("Call vm_model_init");
   /* TODO: ideally we should get back the pointer to CpuModel from init(), but this
index 70b857f..28647f3 100644 (file)
@@ -20,6 +20,7 @@ using namespace simgrid;
 void ModuleGroup::create_flag(const std::string& opt_name, const std::string& descr, const std::string& default_value,
                               bool init_now)
 {
+  opt_name_               = opt_name;
   std::string description = descr + ". Possible values (other compilation flags may activate more " + get_kind() +
                             "s): " + existing_values() +
                             ".\n       (use 'help' as a value to see the long description of each one)";
@@ -42,6 +43,10 @@ void ModuleGroup::create_flag(const std::string& opt_name, const std::string& de
           by_name(value); // Simply ensure that this value exists, it will be picked up later
       });
 }
+void ModuleGroup::init_from_flag_value()
+{
+  by_name(simgrid::config::get_value<std::string>(opt_name_)).init();
+}
 
 ModuleGroup& ModuleGroup::add(const char* id, const char* desc, std::function<void()> init)
 {
index 148daf1..ab175ad 100644 (file)
@@ -27,6 +27,8 @@ struct Module {
 class ModuleGroup {
   std::vector<Module> table_;
   const std::string kind_; // either 'plugin' or 'CPU model' or whatever. Used in error messages only
+  std::string opt_name_;
+
 public:
   ModuleGroup(const std::string& kind) : kind_(kind) {}
 
@@ -37,6 +39,7 @@ public:
   std::string existing_values() const;
   void create_flag(const std::string& opt_name, const std::string& descr, const std::string& default_value,
                    bool init_now);
+  void init_from_flag_value();
 };
 
 }; // namespace simgrid
index fd55f13..5fc1594 100644 (file)
@@ -22,12 +22,9 @@ SIMGRID_REGISTER_HOST_MODEL(
       engine->add_model(host_model);
       engine->get_netzone_root()->set_host_model(host_model);
 
-      std::string network_model_name = simgrid::config::get_value<std::string>("network/model");
-      std::string cpu_model_name     = simgrid::config::get_value<std::string>("cpu/model");
-      std::string disk_model_name    = simgrid::config::get_value<std::string>("disk/model");
-      simgrid_cpu_models().by_name(cpu_model_name).init();
-      simgrid_disk_models().by_name(disk_model_name).init();
-      simgrid_network_models().by_name(network_model_name).init();
+      simgrid_cpu_models().init_from_flag_value();
+      simgrid_disk_models().init_from_flag_value();
+      simgrid_network_models().init_from_flag_value();
     });
 
 namespace simgrid::kernel::resource {