Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of https://framagit.org/simgrid/simgrid
[simgrid.git] / src / simgrid / module.cpp
1 /* Copyright (c) 2004-2023. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #include <xbt/asserts.h>
7 #include <xbt/log.h>
8
9 #include "src/simgrid/module.hpp"
10 #include "src/surf/surf_interface.hpp"
11
12 #include <sstream>
13
14 XBT_LOG_NEW_CATEGORY(plugin, "Common category for the logging of all plugins");
15 XBT_LOG_EXTERNAL_CATEGORY(xbt_help);
16
17 using namespace simgrid;
18
19 ModuleGroup& ModuleGroup::add(const char* id, const char* desc, std::function<void()> init)
20 {
21   table_.emplace_back(Module(id, desc, init));
22   return *this;
23 }
24
25 Module const& ModuleGroup::by_name(const std::string& name) const
26 {
27   if (auto pos = std::find_if(table_.begin(), table_.end(), [&name](const Module& item) { return item.name_ == name; });
28       pos != table_.end())
29     return *pos;
30
31   xbt_die("Unable to find %s '%s'. Valid values are: %s.", kind_.c_str(), name.c_str(), existing_values().c_str());
32 }
33 /** Displays the long description of all registered models, and quit */
34 void ModuleGroup::help() const
35 {
36   XBT_HELP("Long description of the %s accepted by this simulator:", kind_.c_str());
37   for (auto const& item : table_)
38     XBT_HELP("  %s: %s", item.name_, item.description_);
39 }
40 std::string ModuleGroup::existing_values() const
41 {
42   std::stringstream ss;
43   std::string sep;
44   for (auto const& item : table_) {
45     ss << sep + item.name_;
46     sep = ", ";
47   }
48   return ss.str();
49 }
50
51 /* -------------------------------------------------------------------------------------------------------------- */
52 simgrid::ModuleGroup surf_optimization_mode_description("optimization mode");
53 simgrid::ModuleGroup surf_cpu_model_description("CPU model");
54 simgrid::ModuleGroup surf_disk_model_description("disk model");
55 simgrid::ModuleGroup surf_host_model_description("host model");
56
57 void simgrid_create_models()
58 {
59   surf_cpu_model_description.add("Cas01", "Simplistic CPU model (time=size/speed).", &surf_cpu_model_init_Cas01);
60   surf_disk_model_description.add("S19", "Simplistic disk model.", &surf_disk_model_init_S19);
61
62   surf_host_model_description
63       .add("default",
64            "Default host model. Currently, CPU:Cas01, network:LV08 (with cross traffic enabled), and disk:S19",
65            &surf_host_model_init_current_default)
66       .add("compound", "Host model that is automatically chosen if you change the CPU, network, and disk models",
67            &surf_host_model_init_compound)
68       .add("ptask_L07", "Host model somehow similar to Cas01+CM02+S19 but allowing parallel tasks",
69            &surf_host_model_init_ptask_L07);
70
71   surf_optimization_mode_description
72       .add("Lazy", "Lazy action management (partial invalidation in lmm + heap in action remaining).", nullptr)
73       .add("TI",
74            "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU "
75            "model for now).",
76            nullptr)
77       .add("Full", "Full update of remaining and variables. Slow but may be useful when debugging.", nullptr);
78 }