Logo AND Algorithmique Numérique Distribuée

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