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