Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Objectify the model containers
[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_network_model_description("network model");
55 simgrid::ModuleGroup surf_disk_model_description("disk model");
56 simgrid::ModuleGroup surf_host_model_description("host model");
57
58 void simgrid_create_models()
59 {
60   surf_network_model_description
61       .add("LV08",
62            "Realistic network analytic model (slow-start modeled by multiplying latency by 13.01, bandwidth by .97; "
63            "bottleneck sharing uses a payload of S=20537 for evaluating RTT). ",
64            &surf_network_model_init_LegrandVelho)
65       .add("Constant",
66            "Simplistic network model where all communication take a constant time (one second). This model "
67            "provides the lowest realism, but is (marginally) faster.",
68            &surf_network_model_init_Constant)
69       .add("SMPI",
70            "Realistic network model specifically tailored for HPC settings (accurate modeling of slow start with "
71            "correction factors on three intervals: < 1KiB, < 64 KiB, >= 64 KiB)",
72            &surf_network_model_init_SMPI)
73       .add("IB",
74 #if HAVE_SMPI
75            "Realistic network model specifically tailored for HPC settings, with Infiniband contention model",
76 #else
77            "(Infiniband model is only enabled when SMPI is)",
78 #endif
79            &surf_network_model_init_IB)
80       .add("CM02",
81            "Legacy network analytic model (Very similar to LV08, but without corrective factors. The timings of "
82            "small messages are thus poorly modeled).",
83            &surf_network_model_init_CM02)
84       .add("ns-3",
85 #if SIMGRID_HAVE_NS3
86            "Network pseudo-model using the ns-3 tcp model instead of an analytic model",
87 #else
88            "(ns-3 pseudo-model is only activated when ns-3 support was compiled it)",
89 #endif
90            &surf_network_model_init_NS3);
91
92   surf_cpu_model_description.add("Cas01", "Simplistic CPU model (time=size/speed).", &surf_cpu_model_init_Cas01);
93   surf_disk_model_description.add("S19", "Simplistic disk model.", &surf_disk_model_init_S19);
94
95   surf_host_model_description
96       .add("default",
97            "Default host model. Currently, CPU:Cas01, network:LV08 (with cross traffic enabled), and disk:S19",
98            &surf_host_model_init_current_default)
99       .add("compound", "Host model that is automatically chosen if you change the CPU, network, and disk models",
100            &surf_host_model_init_compound)
101       .add("ptask_L07", "Host model somehow similar to Cas01+CM02+S19 but allowing parallel tasks",
102            &surf_host_model_init_ptask_L07);
103
104   surf_optimization_mode_description
105       .add("Lazy", "Lazy action management (partial invalidation in lmm + heap in action remaining).", nullptr)
106       .add("TI",
107            "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU "
108            "model for now).",
109            nullptr)
110       .add("Full", "Full update of remaining and variables. Slow but may be useful when debugging.", nullptr);
111 }
112
113 #if !HAVE_SMPI
114 void surf_network_model_init_IB()
115 {
116   xbt_die("Please activate SMPI support in cmake to use the IB network model.");
117 }
118 #endif
119 #if !SIMGRID_HAVE_NS3
120 void surf_network_model_init_NS3()
121 {
122   xbt_die("Please activate ns-3 support in cmake and install the dependencies to use the NS3 network model.");
123 }
124 #endif