Logo AND Algorithmique Numérique Distribuée

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