Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' into CRTP
[simgrid.git] / src / simgrid / sg_config.cpp
1 /* Copyright (c) 2009-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
6 /* sg_config: configuration infrastructure for the simulation world         */
7
8 #include "simgrid/sg_config.hpp"
9 #include "simgrid/instr.h"
10 #include "src/instr/instr_private.hpp"
11 #include "src/internal_config.h"
12 #include "src/kernel/lmm/maxmin.hpp"
13 #include "src/mc/mc_config.hpp"
14 #include "src/mc/mc_replay.hpp"
15 #include "src/surf/surf_interface.hpp"
16 #include "surf/surf.hpp"
17 #include "xbt/config.hpp"
18
19 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf, "About the configuration of SimGrid");
20
21 static simgrid::config::Flag<bool> cfg_continue_after_help
22   {"help-nostop", "Do not stop the execution when --help is found", false};
23
24 /** @brief Allow other libraries to react to the --help flag, too
25  *
26  * When finding --help on the command line, simgrid usually stops right after displaying its help message.
27  * If you are writing a library using simgrid, you may want to display your own help message before everything stops.
28  * If so, just call this function before having simgrid parsing the command line, and you will be given the control
29  * even if the user is asking for help.
30  */
31 void sg_config_continue_after_help()
32 {
33   cfg_continue_after_help = true;
34 }
35
36 /* 0: beginning of time (config cannot be changed yet)
37  * 1: initialized: cfg_set created (config can now be changed)
38  * 2: configured: command line parsed and config part of platform file was
39  *    integrated also, platform construction ongoing or done.
40  *    (Config cannot be changed anymore!)
41  */
42 int _sg_cfg_init_status = 0;
43
44 /* Parse the command line, looking for options */
45 static void sg_config_cmd_line(int *argc, char **argv)
46 {
47   bool shall_exit = false;
48   int i;
49   int j;
50   bool parse_args = true; // Stop parsing the parameters once we found '--'
51
52   for (j = i = 1; i < *argc; i++) {
53     if (not strcmp("--", argv[i])) {
54       parse_args = false;
55       // Remove that '--' from the arguments
56     } else if (parse_args && not strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
57       char *opt = strchr(argv[i], '=');
58       opt++;
59
60       simgrid::config::set_parse(opt);
61       XBT_DEBUG("Did apply '%s' as config setting", opt);
62     } else if (parse_args && not strcmp(argv[i], "--version")) {
63       sg_version();
64       shall_exit = true;
65     } else if (parse_args && (not strcmp(argv[i], "--cfg-help") || not strcmp(argv[i], "--help"))) {
66       XBT_HELP("Description of the configuration accepted by this simulator:");
67       simgrid::config::help();
68       XBT_HELP("\n"
69                "Each of these configurations can be used by adding\n"
70                "    --cfg=<option name>:<option value>\n"
71                "to the command line. Try passing \"help\" as a value\n"
72                "to get the list of values accepted by a given option.\n"
73                "For example, \"--cfg=plugin:help\" gives you the list of\n"
74                "plugins available in your installation of SimGrid.\n"
75                "\n"
76                "For more information, please refer to:\n"
77                "   --help-aliases for the list of all option aliases.\n"
78                "   --help-logs and --help-log-categories for the details of logging output.\n"
79                "   --help-models for a list of all models known by this simulator.\n"
80                "   --help-tracing for the details of all tracing options known by this simulator.\n"
81                "   --version to get SimGrid version information.\n");
82       shall_exit = not cfg_continue_after_help;
83       argv[j++]  = argv[i]; // Preserve the --help in argv just in case someone else wants to see it
84     } else if (parse_args && not strcmp(argv[i], "--help-aliases")) {
85       XBT_HELP("Here is a list of all deprecated option names, with their replacement.");
86       simgrid::config::show_aliases();
87       XBT_HELP("Please consider using the recent names");
88       shall_exit = true;
89     } else if (parse_args && not strcmp(argv[i], "--help-models")) {
90       model_help("host", surf_host_model_description);
91       XBT_HELP("%s", "");
92       model_help("CPU", surf_cpu_model_description);
93       XBT_HELP("%s", "");
94       model_help("network", surf_network_model_description);
95       XBT_HELP("\nLong description of all optimization levels accepted by the models of this simulator:");
96       for (auto const& item : surf_optimization_mode_description)
97         XBT_HELP("  %s: %s", item.name, item.description);
98       XBT_HELP("Both network and CPU models have 'Lazy' as default optimization level\n");
99       shall_exit = true;
100     } else if (parse_args && not strcmp(argv[i], "--help-tracing")) {
101       TRACE_help();
102       shall_exit = true;
103     } else {
104       argv[j++] = argv[i];
105     }
106   }
107   if (j < *argc) {
108     argv[j] = nullptr;
109     *argc = j;
110   }
111   if (shall_exit)
112     exit(0);
113 }
114
115 /* callback of the plugin variable */
116 static void _sg_cfg_cb__plugin(const std::string& value)
117 {
118   xbt_assert(_sg_cfg_init_status < 2, "Cannot load a plugin after the initialization");
119
120   if (value.empty())
121     return;
122
123   if (value == "help") {
124     model_help("plugin", *surf_plugin_description);
125     exit(0);
126   }
127
128   int plugin_id = find_model_description(*surf_plugin_description, value);
129   (*surf_plugin_description)[plugin_id].model_init_preparse();
130 }
131
132 /* callback of the host/model variable */
133 static void _sg_cfg_cb__host_model(const std::string& value)
134 {
135   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
136
137   if (value == "help") {
138     model_help("host", surf_host_model_description);
139     exit(0);
140   }
141
142   /* Make sure that the model exists */
143   find_model_description(surf_host_model_description, value);
144 }
145
146 /* callback of the cpu/model variable */
147 static void _sg_cfg_cb__cpu_model(const std::string& value)
148 {
149   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
150
151   if (value == "help") {
152     model_help("CPU", surf_cpu_model_description);
153     exit(0);
154   }
155
156   /* New Module missing */
157   find_model_description(surf_cpu_model_description, value);
158 }
159
160 /* callback of the cpu/model variable */
161 static void _sg_cfg_cb__optimization_mode(const std::string& value)
162 {
163   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
164
165   if (value == "help") {
166     model_help("optimization", surf_optimization_mode_description);
167     exit(0);
168   }
169
170   /* New Module missing */
171   find_model_description(surf_optimization_mode_description, value);
172 }
173
174 static void _sg_cfg_cb__disk_model(const std::string& value)
175 {
176   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
177
178   if (value == "help") {
179     model_help("disk", surf_disk_model_description);
180     exit(0);
181   }
182
183   find_model_description(surf_disk_model_description, value);
184 }
185
186 /* callback of the cpu/model variable */
187 static void _sg_cfg_cb__storage_model(const std::string& value)
188 {
189   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
190
191   if (value == "help") {
192     model_help("storage", surf_storage_model_description);
193     exit(0);
194   }
195
196   find_model_description(surf_storage_model_description, value);
197 }
198
199 /* callback of the network_model variable */
200 static void _sg_cfg_cb__network_model(const std::string& value)
201 {
202   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
203
204   if (value == "help") {
205     model_help("network", surf_network_model_description);
206     exit(0);
207   }
208
209   /* New Module missing */
210   find_model_description(surf_network_model_description, value);
211 }
212
213 static void _sg_cfg_cb_contexts_parallel_mode(const std::string& mode_name)
214 {
215   if (mode_name == "posix") {
216     SIMIX_context_set_parallel_mode(XBT_PARMAP_POSIX);
217   } else if (mode_name == "futex") {
218     SIMIX_context_set_parallel_mode(XBT_PARMAP_FUTEX);
219   } else if (mode_name == "busy_wait") {
220     SIMIX_context_set_parallel_mode(XBT_PARMAP_BUSY_WAIT);
221   } else {
222     xbt_die("Command line setting of the parallel synchronization mode should "
223             "be one of \"posix\", \"futex\" or \"busy_wait\"");
224   }
225 }
226
227 /* build description line with possible values */
228 static void declare_model_flag(const std::string& name, const std::string& value,
229                                const std::function<void(std::string const&)>& callback,
230                                const std::vector<surf_model_description_t>& model_description, const std::string& type,
231                                const std::string& descr)
232 {
233   std::string description = descr + ". Possible values: ";
234   std::string sep         = "";
235   for (auto const& item : model_description) {
236     description += sep + item.name;
237     sep = ", ";
238   }
239   description += ".\n       (use 'help' as a value to see the long description of each " + type + ")";
240   simgrid::config::declare_flag<std::string>(name, description, value, callback);
241 }
242
243 /* create the config set, register what should be and parse the command line*/
244 void sg_config_init(int *argc, char **argv)
245 {
246   /* Create the configuration support */
247   if (_sg_cfg_init_status != 0) { /* Only create stuff if not already inited */
248     XBT_WARN("Call to sg_config_init() after initialization ignored");
249     return;
250   }
251
252   /* Plugins configuration */
253   declare_model_flag("plugin", "", &_sg_cfg_cb__plugin, *surf_plugin_description, "plugin", "The plugins");
254
255   declare_model_flag("cpu/model", "Cas01", &_sg_cfg_cb__cpu_model, surf_cpu_model_description, "model",
256                      "The model to use for the CPU");
257
258   declare_model_flag("disk/model", "default", &_sg_cfg_cb__disk_model, surf_disk_model_description, "model",
259                      "The model to use for the disk");
260
261   declare_model_flag("storage/model", "default", &_sg_cfg_cb__storage_model, surf_storage_model_description, "model",
262                      "The model to use for the storage");
263
264   declare_model_flag("network/model", "LV08", &_sg_cfg_cb__network_model, surf_network_model_description, "model",
265                      "The model to use for the network");
266
267   declare_model_flag("network/optim", "Lazy", &_sg_cfg_cb__optimization_mode, surf_optimization_mode_description,
268                      "optimization mode", "The optimization modes to use for the network");
269
270   declare_model_flag("host/model", "default", &_sg_cfg_cb__host_model, surf_host_model_description, "model",
271                      "The model to use for the host");
272
273   simgrid::config::bind_flag(sg_surf_precision, "surf/precision",
274                              "Numerical precision used when updating simulation times (in seconds)");
275
276   simgrid::config::bind_flag(sg_maxmin_precision, "maxmin/precision",
277                              "Numerical precision used when computing resource sharing (in flops/sec or bytes/sec)");
278
279   simgrid::config::bind_flag(sg_concurrency_limit, "maxmin/concurrency-limit", {"maxmin/concurrency_limit"},
280                              "Maximum number of concurrent variables in the maxmim system. Also limits the number of "
281                              "processes on each host, at higher level. (default: -1 means no such limitation)");
282
283   /* The parameters of network models */
284
285   sg_latency_factor = 13.01; // comes from the default LV08 network model
286   simgrid::config::bind_flag(sg_latency_factor, "network/latency-factor", {"network/latency_factor"},
287                              "Correction factor to apply to the provided latency (default value set by network model)");
288
289   sg_bandwidth_factor = 0.97; // comes from the default LV08 network model
290   simgrid::config::bind_flag(
291       sg_bandwidth_factor, "network/bandwidth-factor", {"network/bandwidth_factor"},
292       "Correction factor to apply to the provided bandwidth (default value set by network model)");
293
294   sg_weight_S_parameter = 20537; // comes from the default LV08 network model
295   simgrid::config::bind_flag(
296       sg_weight_S_parameter, "network/weight-S", {"network/weight_S"},
297       "Correction factor to apply to the weight of competing streams (default value set by network model)");
298
299   /* Inclusion path */
300   simgrid::config::declare_flag<std::string>("path", "Lookup path for inclusions in platform and deployment XML files",
301                                              "", [](std::string const& path) {
302                                                if (not path.empty())
303                                                  surf_path.push_back(path);
304                                              });
305
306   simgrid::config::declare_flag<bool>("cpu/maxmin-selective-update",
307                                       "Update the constraint set propagating recursively to others constraints "
308                                       "(off by default unless optim is set to lazy)",
309                                       "no");
310   simgrid::config::alias("cpu/maxmin-selective-update", {"cpu/maxmin_selective_update"});
311   simgrid::config::declare_flag<bool>("network/maxmin-selective-update", "Update the constraint set propagating "
312                                                                          "recursively to others constraints (off by "
313                                                                          "default unless optim is set to lazy)",
314                                       "no");
315   simgrid::config::alias("network/maxmin-selective-update", {"network/maxmin_selective_update"});
316
317   simgrid::config::declare_flag<int>("contexts/stack-size", "Stack size of contexts in KiB (not with threads)",
318                                      8 * 1024, [](int value) { smx_context_stack_size = value * 1024; });
319   simgrid::config::alias("contexts/stack-size", {"contexts/stack_size"});
320
321   /* guard size for contexts stacks in memory pages */
322 #if defined(_WIN32) || (PTH_STACKGROWTH != -1)
323   int default_guard_size = 0;
324 #else
325   int default_guard_size = 1;
326 #endif
327   simgrid::config::declare_flag<int>("contexts/guard-size", "Guard size for contexts stacks in memory pages",
328                                      default_guard_size,
329                                      [](int value) { smx_context_guard_size = value * xbt_pagesize; });
330   simgrid::config::alias("contexts/guard-size", {"contexts/guard_size"});
331   simgrid::config::declare_flag<int>("contexts/nthreads", "Number of parallel threads used to execute user contexts", 1,
332                                      &SIMIX_context_set_nthreads);
333
334   simgrid::config::declare_flag<int>("contexts/parallel-threshold",
335                                      "Minimal number of user contexts to be run in parallel (raw contexts only)", 2,
336                                      &SIMIX_context_set_parallel_threshold);
337   simgrid::config::alias("contexts/parallel-threshold", {"contexts/parallel_threshold"});
338
339   /* synchronization mode for parallel user contexts */
340 #if HAVE_FUTEX_H
341   std::string default_synchro_mode = "futex";
342 #else // No futex on mac and posix is unimplemented yet
343   std::string default_synchro_mode = "busy_wait";
344 #endif
345   simgrid::config::declare_flag<std::string>("contexts/synchro", "Synchronization mode to use when running contexts in "
346                                                                  "parallel (either futex, posix or busy_wait)",
347                                              default_synchro_mode, &_sg_cfg_cb_contexts_parallel_mode);
348
349   // For smpi/bw-factor and smpi/lat-factor
350   // SMPI model can be used without enable_smpi, so keep this out of the ifdef.
351   simgrid::config::declare_flag<std::string>("smpi/bw-factor",
352                                              "Bandwidth factors for smpi. Format: "
353                                              "'threshold0:value0;threshold1:value1;...;thresholdN:valueN', "
354                                              "meaning if(size >=thresholdN ) return valueN.",
355                                              "65472:0.940694;15424:0.697866;9376:0.58729;5776:1.08739;3484:0.77493;"
356                                              "1426:0.608902;732:0.341987;257:0.338112;0:0.812084");
357   simgrid::config::alias("smpi/bw-factor", {"smpi/bw_factor"});
358
359   simgrid::config::declare_flag<std::string>("smpi/lat-factor", "Latency factors for smpi.",
360                                              "65472:11.6436;15424:3.48845;9376:2.59299;5776:2.18796;3484:1.88101;"
361                                              "1426:1.61075;732:1.9503;257:1.95341;0:2.01467");
362   simgrid::config::alias("smpi/lat-factor", {"smpi/lat_factor"});
363   simgrid::config::declare_flag<std::string>("smpi/IB-penalty-factors",
364                                              "Correction factor to communications using Infiniband model with "
365                                              "contention (default value based on Stampede cluster profiling)",
366                                              "0.965;0.925;1.35");
367   simgrid::config::alias("smpi/IB-penalty-factors", {"smpi/IB_penalty_factors"});
368
369 #if HAVE_SMPI
370   simgrid::config::declare_flag<double>("smpi/host-speed", "Speed of the host running the simulation (in flop/s). "
371                                                            "Used to bench the operations.",
372                                         20000.0, [](const double& val) {
373       xbt_assert(val > 0.0, "Invalid value (%f) for 'smpi/host-speed': it must be positive.", val);
374     });
375   simgrid::config::alias("smpi/host-speed", {"smpi/running_power", "smpi/running-power"});
376
377   simgrid::config::declare_flag<bool>("smpi/keep-temps", "Whether we should keep the generated temporary files.",
378                                       false);
379
380   simgrid::config::declare_flag<bool>("smpi/display-timing", "Whether we should display the timing after simulation.",
381                                       false);
382   simgrid::config::alias("smpi/display-timing", {"smpi/display_timing"});
383
384   simgrid::config::declare_flag<bool>(
385       "smpi/simulate-computation", "Whether the computational part of the simulated application should be simulated.",
386       true);
387   simgrid::config::alias("smpi/simulate-computation", {"smpi/simulate_computation"});
388
389   simgrid::config::declare_flag<std::string>(
390       "smpi/shared-malloc", "Whether SMPI_SHARED_MALLOC is enabled. Disable it for debugging purposes.", "global");
391   simgrid::config::alias("smpi/shared-malloc", {"smpi/use_shared_malloc", "smpi/use-shared-malloc"});
392   simgrid::config::declare_flag<double>("smpi/shared-malloc-blocksize",
393                                         "Size of the bogus file which will be created for global shared allocations",
394                                         1UL << 20);
395   simgrid::config::declare_flag<std::string>("smpi/shared-malloc-hugepage",
396                                              "Path to a mounted hugetlbfs, to use huge pages with shared malloc.", "");
397
398   simgrid::config::declare_flag<double>(
399       "smpi/cpu-threshold", "Minimal computation time (in seconds) not discarded, or -1 for infinity.", 1e-6);
400   simgrid::config::alias("smpi/cpu-threshold", {"smpi/cpu_threshold"});
401
402   simgrid::config::declare_flag<int>(
403       "smpi/async-small-thresh",
404       "Maximal size of messages that are to be sent asynchronously, without waiting for the receiver", 0);
405   simgrid::config::alias("smpi/async-small-thresh", {"smpi/async_small_thres", "smpi/async_small_thresh"});
406
407   simgrid::config::declare_flag<bool>("smpi/trace-call-location",
408                                       "Should filename and linenumber of MPI calls be traced?", false);
409   simgrid::config::declare_flag<bool>("smpi/trace-call-use-absolute-path",
410                                       "Should filenames for trace-call tracing be absolute or not?", false);
411   simgrid::config::declare_flag<int>(
412       "smpi/send-is-detached-thresh",
413       "Threshold of message size where MPI_Send stops behaving like MPI_Isend and becomes MPI_Ssend", 65536);
414   simgrid::config::alias("smpi/send-is-detached-thresh",
415                          {"smpi/send_is_detached_thres", "smpi/send_is_detached_thresh"});
416
417   const char* default_privatization = std::getenv("SMPI_PRIVATIZATION");
418   if (default_privatization == nullptr)
419     default_privatization = "no";
420
421   simgrid::config::declare_flag<std::string>(
422       "smpi/privatization", "How we should privatize global variable at runtime (no, yes, mmap, dlopen).",
423       default_privatization);
424   simgrid::config::alias("smpi/privatization", {"smpi/privatize_global_variables", "smpi/privatize-global-variables"});
425
426   simgrid::config::declare_flag<std::string>(
427       "smpi/privatize-libs", "Add libraries (; separated) to privatize (libgfortran for example). You need to provide the full names of the files (libgfortran.so.4), or its full path", "");
428
429   simgrid::config::declare_flag<bool>("smpi/grow-injected-times",
430                                       "Whether we want to make the injected time in MPI_Iprobe and MPI_Test grow, to "
431                                       "allow faster simulation. This can make simulation less precise, though.",
432                                       true);
433
434 #if HAVE_PAPI
435   simgrid::config::declare_flag<std::string>("smpi/papi-events",
436                                              "This switch enables tracking the specified counters with PAPI", "");
437 #endif
438   simgrid::config::declare_flag<std::string>("smpi/comp-adjustment-file",
439                                              "A file containing speedups or slowdowns for some parts of the code.", "");
440   simgrid::config::declare_flag<std::string>(
441       "smpi/os", "Small messages timings (MPI_Send minimum time for small messages)", "0:0:0:0:0");
442   simgrid::config::declare_flag<std::string>(
443       "smpi/ois", "Small messages timings (MPI_Isend minimum time for small messages)", "0:0:0:0:0");
444   simgrid::config::declare_flag<std::string>(
445       "smpi/or", "Small messages timings (MPI_Recv minimum time for small messages)", "0:0:0:0:0");
446
447   simgrid::config::declare_flag<double>("smpi/iprobe-cpu-usage",
448                                         "Maximum usage of CPUs by MPI_Iprobe() calls. We've observed that MPI_Iprobes "
449                                         "consume significantly less power than the maximum of a specific application. "
450                                         "This value is then (Iprobe_Usage/Max_Application_Usage).",
451                                         1.0);
452
453   simgrid::config::declare_flag<std::string>("smpi/coll-selector", "Which collective selector to use", "default");
454   simgrid::config::alias("smpi/coll-selector", {"smpi/coll_selector"});
455   simgrid::config::declare_flag<std::string>("smpi/gather", "Which collective to use for gather", "");
456   simgrid::config::declare_flag<std::string>("smpi/allgather", "Which collective to use for allgather", "");
457   simgrid::config::declare_flag<std::string>("smpi/barrier", "Which collective to use for barrier", "");
458   simgrid::config::declare_flag<std::string>("smpi/reduce_scatter", "Which collective to use for reduce_scatter", "");
459   simgrid::config::alias("smpi/reduce_scatter", {"smpi/reduce-scatter"});
460   simgrid::config::declare_flag<std::string>("smpi/scatter", "Which collective to use for scatter", "");
461   simgrid::config::declare_flag<std::string>("smpi/allgatherv", "Which collective to use for allgatherv", "");
462   simgrid::config::declare_flag<std::string>("smpi/allreduce", "Which collective to use for allreduce", "");
463   simgrid::config::declare_flag<std::string>("smpi/alltoall", "Which collective to use for alltoall", "");
464   simgrid::config::declare_flag<std::string>("smpi/alltoallv", "Which collective to use for alltoallv", "");
465   simgrid::config::declare_flag<std::string>("smpi/bcast", "Which collective to use for bcast", "");
466   simgrid::config::declare_flag<std::string>("smpi/reduce", "Which collective to use for reduce", "");
467 #endif // HAVE_SMPI
468
469   /* Others */
470
471   simgrid::config::declare_flag<bool>(
472       "exception/cutpath", "Whether to cut all path information from call traces, used e.g. in exceptions.", false);
473
474   if (surf_path.empty())
475     simgrid::config::set_default<std::string>("path", "./");
476
477   _sg_cfg_init_status = 1;
478
479   sg_config_cmd_line(argc, argv);
480
481   xbt_mallocator_initialization_is_done(SIMIX_context_is_parallel());
482 }
483
484 void sg_config_finalize()
485 {
486   simgrid::config::finalize();
487   _sg_cfg_init_status = 0;
488 }