Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Stop trying to build on native WIN32, it's broken anyway
[simgrid.git] / src / surf / surf_interface.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 <simgrid/s4u/Engine.hpp>
7 #include <xbt/module.h>
8
9 #include "mc/mc.h"
10 #include "simgrid/sg_config.hpp"
11 #include "src/kernel/resource/profile/FutureEvtSet.hpp"
12 #include "src/kernel/resource/profile/Profile.hpp"
13 #include "src/surf/HostImpl.hpp"
14 #include "src/surf/surf_interface.hpp"
15
16 #include <fstream>
17 #include <string>
18
19 XBT_LOG_NEW_CATEGORY(surf, "All SURF categories");
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_kernel, surf, "Logging specific to SURF (kernel)");
21
22 /*********
23  * Utils *
24  *********/
25
26 simgrid::kernel::profile::FutureEvtSet future_evt_set;
27 std::vector<std::string> surf_path;
28
29 const std::vector<surf_model_description_t> surf_network_model_description = {
30     {"LV08",
31      "Realistic network analytic model (slow-start modeled by multiplying latency by 13.01, bandwidth by .97; "
32      "bottleneck sharing uses a payload of S=20537 for evaluating RTT). ",
33      &surf_network_model_init_LegrandVelho},
34     {"Constant",
35      "Simplistic network model where all communication take a constant time (one second). This model "
36      "provides the lowest realism, but is (marginally) faster.",
37      &surf_network_model_init_Constant},
38     {"SMPI",
39      "Realistic network model specifically tailored for HPC settings (accurate modeling of slow start with "
40      "correction factors on three intervals: < 1KiB, < 64 KiB, >= 64 KiB)",
41      &surf_network_model_init_SMPI},
42     {"IB", "Realistic network model specifically tailored for HPC settings, with Infiniband contention model",
43      &surf_network_model_init_IB},
44     {"CM02",
45      "Legacy network analytic model (Very similar to LV08, but without corrective factors. The timings of "
46      "small messages are thus poorly modeled).",
47      &surf_network_model_init_CM02},
48     {"ns-3", "Network pseudo-model using the ns-3 tcp model instead of an analytic model",
49      &surf_network_model_init_NS3},
50 };
51
52 #if !HAVE_SMPI
53 void surf_network_model_init_IB()
54 {
55   xbt_die("Please activate SMPI support in cmake to use the IB network model.");
56 }
57 #endif
58 #if !SIMGRID_HAVE_NS3
59 void surf_network_model_init_NS3()
60 {
61   xbt_die("Please activate ns-3 support in cmake and install the dependencies to use the NS3 network model.");
62 }
63 #endif
64
65 const std::vector<surf_model_description_t> surf_cpu_model_description = {
66     {"Cas01", "Simplistic CPU model (time=size/speed).", &surf_cpu_model_init_Cas01},
67 };
68
69 const std::vector<surf_model_description_t> surf_disk_model_description = {
70     {"S19", "Simplistic disk model.", &surf_disk_model_init_S19},
71 };
72
73 const std::vector<surf_model_description_t> surf_host_model_description = {
74     {"default", "Default host model. Currently, CPU:Cas01, network:LV08 (with cross traffic enabled), and disk:S19",
75      &surf_host_model_init_current_default},
76     {"compound", "Host model that is automatically chosen if you change the CPU, network, and disk models",
77      &surf_host_model_init_compound},
78     {"ptask_L07", "Host model somehow similar to Cas01+CM02+S19 but allowing parallel tasks",
79      &surf_host_model_init_ptask_L07},
80 };
81
82 const std::vector<surf_model_description_t> surf_optimization_mode_description = {
83     {"Lazy", "Lazy action management (partial invalidation in lmm + heap in action remaining).", nullptr},
84     {"TI",
85      "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU "
86      "model for now).",
87      nullptr},
88     {"Full", "Full update of remaining and variables. Slow but may be useful when debugging.", nullptr},
89 };
90
91 /* returns whether #file_path is an absolute file path. Surprising, isn't it ? */
92 static bool is_absolute_file_path(const std::string& file_path)
93 {
94   return (file_path.c_str()[0] == '/');
95 }
96
97 std::ifstream* surf_ifsopen(const std::string& name)
98 {
99   xbt_assert(not name.empty());
100
101   auto* fs = new std::ifstream();
102   if (is_absolute_file_path(name)) { /* don't mess with absolute file names */
103     fs->open(name.c_str(), std::ifstream::in);
104   }
105
106   /* search relative files in the path */
107   for (auto const& path_elm : surf_path) {
108     std::string buff = path_elm + "/" + name;
109     fs->open(buff.c_str(), std::ifstream::in);
110
111     if (not fs->fail()) {
112       XBT_DEBUG("Found file at %s", buff.c_str());
113       return fs;
114     }
115   }
116
117   return fs;
118 }
119
120 FILE* surf_fopen(const std::string& name, const char* mode)
121 {
122   FILE* file = nullptr;
123
124   if (is_absolute_file_path(name)) /* don't mess with absolute file names */
125     return fopen(name.c_str(), mode);
126
127   /* search relative files in the path */
128   for (auto const& path_elm : surf_path) {
129     std::string buff = path_elm + "/" + name;
130     file             = fopen(buff.c_str(), mode);
131
132     if (file)
133       return file;
134   }
135   return nullptr;
136 }
137
138 /** Displays the long description of all registered models, and quit */
139 void model_help(const char* category, const std::vector<surf_model_description_t>& table)
140 {
141   XBT_HELP("Long description of the %s models accepted by this simulator:", category);
142   for (auto const& item : table)
143     XBT_HELP("  %s: %s", item.name, item.description);
144 }
145
146 const surf_model_description_t* find_model_description(const std::vector<surf_model_description_t>& table,
147                                                        const std::string& name)
148 {
149   if (auto pos = std::find_if(table.begin(), table.end(),
150                               [&name](const surf_model_description_t& item) { return item.name == name; });
151       pos != table.end())
152     return &*pos;
153
154   std::string sep;
155   std::string name_list;
156   for (auto const& item : table) {
157     name_list += sep + item.name;
158     sep = ", ";
159   }
160   xbt_die("Model '%s' is invalid! Valid models are: %s.", name.c_str(), name_list.c_str());
161 }