Logo AND Algorithmique Numérique Distribuée

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