Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Remove old deprecated aliases for runtime options.
[simgrid.git] / src / smpi / internals / smpi_config.cpp
1 /* Copyright (c) 2008-2020. 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 #include "smpi_config.hpp"
6 #include "include/xbt/config.hpp"
7 #include "mc/mc.h"
8 #include "private.hpp"
9 #include "smpi_coll.hpp"
10 #include "src/simix/smx_private.hpp"
11 #include "xbt/parse_units.hpp"
12
13 #include <cfloat> /* DBL_MAX */
14 #include <boost/algorithm/string.hpp> /* trim */
15 #include <boost/tokenizer.hpp>
16
17 #if SIMGRID_HAVE_MC
18 #include "src/mc/mc_config.hpp"
19 #endif
20
21 #if defined(__APPLE__)
22 # include <AvailabilityMacros.h>
23 # ifndef MAC_OS_X_VERSION_10_12
24 #   define MAC_OS_X_VERSION_10_12 101200
25 # endif
26 constexpr bool HAVE_WORKING_MMAP = (MAC_OS_X_VERSION_MIN_REQUIRED >= MAC_OS_X_VERSION_10_12);
27 #elif defined(__FreeBSD__) || defined(__FreeBSD_kernel__) || defined(__sun) || defined(__HAIKU__)
28 constexpr bool HAVE_WORKING_MMAP = false;
29 #else
30 constexpr bool HAVE_WORKING_MMAP = true;
31 #endif
32
33 bool _smpi_options_initialized=false;
34 SharedMallocType _smpi_cfg_shared_malloc = SharedMallocType::GLOBAL;
35 SmpiPrivStrategies _smpi_cfg_privatization = SmpiPrivStrategies::NONE;
36 double _smpi_cfg_host_speed;
37
38 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_config, smpi, "Logging specific to SMPI (config)");
39
40 simgrid::config::Flag<std::string> _smpi_cfg_host_speed_string{
41     "smpi/host-speed",
42     "Speed of the host running the simulation (in flop/s). "
43     "Used to bench the operations.",
44     "20000f", [](const std::string& str) {
45       _smpi_cfg_host_speed = xbt_parse_get_speed("smpi/host-speed", 1, str.c_str(), "option", "smpi/host-speed");
46       xbt_assert(_smpi_cfg_host_speed > 0.0, "Invalid value (%s) for 'smpi/host-speed': it must be positive.",
47                  _smpi_cfg_host_speed_string.get().c_str());
48     }};
49
50 simgrid::config::Flag<bool> _smpi_cfg_simulate_computation{
51   "smpi/simulate-computation", "Whether the computational part of the simulated application should be simulated.",
52    true};
53 simgrid::config::Flag<std::string> _smpi_cfg_shared_malloc_string{
54   "smpi/shared-malloc", "Whether SMPI_SHARED_MALLOC is enabled. Disable it for debugging purposes.", "global", 
55   [](const std::string& val) {   
56     if ((val == "yes") || (val == "1") || (val == "on") || (val == "global")) {
57       _smpi_cfg_shared_malloc = SharedMallocType::GLOBAL;
58     } else if (val == "local") {
59       _smpi_cfg_shared_malloc = SharedMallocType::LOCAL;
60     } else if ((val == "no") || (val == "0") || (val == "off")) {
61       _smpi_cfg_shared_malloc = SharedMallocType::NONE;
62     } else {
63       xbt_die("Invalid value '%s' for option smpi/shared-malloc. Possible values: 'on' or 'global', 'local', 'off'",
64       val.c_str());
65     } 
66   } };
67
68 simgrid::config::Flag<double> _smpi_cfg_cpu_threshold{
69   "smpi/cpu-threshold", "Minimal computation time (in seconds) not discarded, or -1 for infinity.", 1e-6,
70   [](const double& val){
71     if (val < 0)
72       _smpi_cfg_cpu_threshold = DBL_MAX;
73   }};
74
75 simgrid::config::Flag<int> _smpi_cfg_async_small_thresh{"smpi/async-small-thresh",
76                                                         "Maximal size of messages that are to be sent asynchronously, without waiting for the receiver",
77                                                         0};
78 simgrid::config::Flag<int> _smpi_cfg_detached_send_thresh{"smpi/send-is-detached-thresh",
79                                                           "Threshold of message size where MPI_Send stops behaving like MPI_Isend and becomes MPI_Ssend", 
80                                                           65536};
81 simgrid::config::Flag<bool> _smpi_cfg_grow_injected_times{"smpi/grow-injected-times",
82                                                           "Whether we want to make the injected time in MPI_Iprobe and MPI_Test grow, to "
83                                                           "allow faster simulation. This can make simulation less precise, though.",
84                                                           true};
85 simgrid::config::Flag<double> _smpi_cfg_iprobe_cpu_usage{"smpi/iprobe-cpu-usage",
86                                                         "Maximum usage of CPUs by MPI_Iprobe() calls. We've observed that MPI_Iprobes "
87                                                         "consume significantly less power than the maximum of a specific application. "
88                                                         "This value is then (Iprobe_Usage/Max_Application_Usage).",
89                                                         1.0};
90
91 simgrid::config::Flag<bool>  _smpi_cfg_trace_call_location{"smpi/trace-call-location",
92                                                            "Should filename and linenumber of MPI calls be traced?", false};
93 simgrid::config::Flag<bool> _smpi_cfg_trace_call_use_absolute_path{"smpi/trace-call-use-absolute-path",
94                                                                    "Should filenames for trace-call tracing be absolute or not?", false};
95 simgrid::config::Flag<std::string> _smpi_cfg_comp_adjustment_file{"smpi/comp-adjustment-file",
96     "A file containing speedups or slowdowns for some parts of the code.", 
97     "", [](const std::string& filename){
98       if (not filename.empty()) {
99         std::ifstream fstream(filename);
100         xbt_assert(fstream.is_open(), "Could not open file %s. Does it exist?", filename.c_str());
101         std::string line;
102         using Tokenizer = boost::tokenizer<boost::escaped_list_separator<char>>;
103         std::getline(fstream, line); // Skip the header line
104         while (std::getline(fstream, line)) {
105           Tokenizer tok(line);
106           Tokenizer::iterator it  = tok.begin();
107           Tokenizer::iterator end = std::next(tok.begin());
108           std::string location = *it;
109           boost::trim(location);
110           location2speedup.insert(std::pair<std::string, double>(location, std::stod(*end)));
111         }
112       }
113     }};
114     
115 #if HAVE_PAPI
116   simgrid::config::Flag<std::string> _smpi_cfg_papi_events_file{"smpi/papi-events",
117                                                                 "This switch enables tracking the specified counters with PAPI", ""};
118 #endif
119
120 simgrid::config::Flag<double> _smpi_cfg_auto_shared_malloc_thresh("smpi/auto-shared-malloc-thresh",
121                                                                   "Threshold size for the automatic sharing of memory", 
122                                                                   0);
123
124 double smpi_cfg_host_speed(){
125   return _smpi_cfg_host_speed;
126 }
127
128 bool smpi_cfg_simulate_computation(){
129   return _smpi_cfg_simulate_computation;
130 }
131
132 SharedMallocType smpi_cfg_shared_malloc(){
133   return _smpi_cfg_shared_malloc;
134 }
135
136 double smpi_cfg_cpu_thresh(){
137   return _smpi_cfg_cpu_threshold;
138 }
139
140 SmpiPrivStrategies smpi_cfg_privatization(){
141   return _smpi_cfg_privatization;
142 }
143
144 int smpi_cfg_async_small_thresh(){
145   return _smpi_cfg_async_small_thresh;
146 }
147
148 int smpi_cfg_detached_send_thresh(){
149   return _smpi_cfg_detached_send_thresh;
150 }
151
152 bool smpi_cfg_grow_injected_times(){
153   return _smpi_cfg_grow_injected_times;
154 }
155
156 double smpi_cfg_iprobe_cpu_usage(){
157   return _smpi_cfg_iprobe_cpu_usage;
158 }
159
160 bool smpi_cfg_trace_call_location(){
161   return _smpi_cfg_trace_call_location;
162 }
163
164 bool smpi_cfg_trace_call_use_absolute_path(){
165   return _smpi_cfg_trace_call_use_absolute_path;
166 }
167
168 std::string smpi_cfg_comp_adjustment_file(){
169   return _smpi_cfg_comp_adjustment_file;
170 }
171 #if HAVE_PAPI
172 std::string smpi_cfg_papi_events_file(){
173   return _smpi_cfg_papi_events_file;
174 }
175 #endif
176 double smpi_cfg_auto_shared_malloc_thresh(){
177   return _smpi_cfg_auto_shared_malloc_thresh;
178 }
179
180 void smpi_init_options(){
181   // return if already called
182   if(_smpi_options_initialized)
183     return;
184   simgrid::config::declare_flag<bool>("smpi/display-timing", "Whether we should display the timing after simulation.", false);
185   simgrid::config::declare_flag<bool>("smpi/keep-temps", "Whether we should keep the generated temporary files.", false);
186   simgrid::config::declare_flag<std::string>("smpi/tmpdir", "tmp dir for dlopen files", "/tmp");
187
188   simgrid::config::declare_flag<std::string>("smpi/coll-selector", "Which collective selector to use", "default");
189   simgrid::config::declare_flag<std::string>("smpi/gather", "Which collective to use for gather", "");
190   simgrid::config::declare_flag<std::string>("smpi/allgather", "Which collective to use for allgather", "");
191   simgrid::config::declare_flag<std::string>("smpi/barrier", "Which collective to use for barrier", "");
192   simgrid::config::declare_flag<std::string>("smpi/reduce_scatter", "Which collective to use for reduce_scatter", "");
193   simgrid::config::declare_flag<std::string>("smpi/scatter", "Which collective to use for scatter", "");
194   simgrid::config::declare_flag<std::string>("smpi/allgatherv", "Which collective to use for allgatherv", "");
195   simgrid::config::declare_flag<std::string>("smpi/allreduce", "Which collective to use for allreduce", "");
196   simgrid::config::declare_flag<std::string>("smpi/alltoall", "Which collective to use for alltoall", "");
197   simgrid::config::declare_flag<std::string>("smpi/alltoallv", "Which collective to use for alltoallv", "");
198   simgrid::config::declare_flag<std::string>("smpi/bcast", "Which collective to use for bcast", "");
199   simgrid::config::declare_flag<std::string>("smpi/reduce", "Which collective to use for reduce", "");
200
201   const char* default_privatization = std::getenv("SMPI_PRIVATIZATION");
202   if (default_privatization == nullptr)
203     default_privatization = "no";
204
205
206   simgrid::config::declare_flag<std::string>( "smpi/privatization", 
207     "How we should privatize global variable at runtime (no, yes, mmap, dlopen).",
208     default_privatization, [](const std::string& smpi_privatize_option){
209       if (smpi_privatize_option == "no" || smpi_privatize_option == "0")
210         _smpi_cfg_privatization = SmpiPrivStrategies::NONE;
211       else if (smpi_privatize_option == "yes" || smpi_privatize_option == "1")
212         _smpi_cfg_privatization = SmpiPrivStrategies::DEFAULT;
213       else if (smpi_privatize_option == "mmap")
214         _smpi_cfg_privatization = SmpiPrivStrategies::MMAP;
215       else if (smpi_privatize_option == "dlopen")
216         _smpi_cfg_privatization = SmpiPrivStrategies::DLOPEN;
217       else
218         xbt_die("Invalid value for smpi/privatization: '%s'", smpi_privatize_option.c_str());
219         
220       if (not SMPI_switch_data_segment) {
221         XBT_DEBUG("Running without smpi_main(); disable smpi/privatization.");
222         _smpi_cfg_privatization = SmpiPrivStrategies::NONE;
223       }
224       if (not HAVE_WORKING_MMAP && _smpi_cfg_privatization == SmpiPrivStrategies::MMAP) {
225         XBT_INFO("mmap privatization is broken on this platform, switching to dlopen privatization instead.");
226         _smpi_cfg_privatization = SmpiPrivStrategies::DLOPEN;
227       }
228     });
229
230   simgrid::config::declare_flag<std::string>("smpi/privatize-libs", 
231                                             "Add libraries (; separated) to privatize (libgfortran for example)."
232                                             "You need to provide the full names of the files (libgfortran.so.4), or its full path", 
233                                             "");
234   simgrid::config::declare_flag<double>("smpi/shared-malloc-blocksize",
235                                         "Size of the bogus file which will be created for global shared allocations", 
236                                         1UL << 20);
237   simgrid::config::declare_flag<std::string>("smpi/shared-malloc-hugepage",
238                                              "Path to a mounted hugetlbfs, to use huge pages with shared malloc.", 
239                                              "");
240
241   simgrid::config::declare_flag<std::string>(
242       "smpi/os", "Small messages timings (MPI_Send minimum time for small messages)", "0:0:0:0:0");
243   simgrid::config::declare_flag<std::string>(
244       "smpi/ois", "Small messages timings (MPI_Isend minimum time for small messages)", "0:0:0:0:0");
245   simgrid::config::declare_flag<std::string>(
246       "smpi/or", "Small messages timings (MPI_Recv minimum time for small messages)", "0:0:0:0:0");
247   _smpi_options_initialized=true;
248 }
249
250 void smpi_check_options()
251 {
252 #if SIMGRID_HAVE_MC
253   if (MC_is_active()) {
254     if (_sg_mc_buffering == "zero")
255       simgrid::config::set_value<int>("smpi/send-is-detached-thresh", 0);
256     else if (_sg_mc_buffering == "infty")
257       simgrid::config::set_value<int>("smpi/send-is-detached-thresh", INT_MAX);
258     else
259       THROW_IMPOSSIBLE;
260   }
261 #endif
262
263   xbt_assert(smpi_cfg_async_small_thresh() <= smpi_cfg_detached_send_thresh(),
264              "smpi/async-small-thresh (=%d) should be smaller or equal to smpi/send-is-detached-thresh (=%d)",
265              smpi_cfg_async_small_thresh(),
266              smpi_cfg_detached_send_thresh());
267
268   if (simgrid::config::is_default("smpi/host-speed") && not MC_is_active()) {
269     XBT_INFO("You did not set the power of the host running the simulation.  "
270              "The timings will certainly not be accurate.  "
271              "Use the option \"--cfg=smpi/host-speed:<flops>\" to set its value.  "
272              "Check "
273              "https://simgrid.org/doc/latest/Configuring_SimGrid.html#automatic-benchmarking-of-smpi-code for more "
274              "information.");
275   }
276
277   simgrid::smpi::colls::set_collectives();
278   simgrid::smpi::colls::smpi_coll_cleanup_callback = nullptr;
279 }
280