1 /* Copyright (c) 2009-2018. 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 "instr/instr_interface.hpp"
10 #include "simgrid/instr.h"
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.h"
18 #include "xbt/config.hpp"
20 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf, "About the configuration of SimGrid");
23 /* 0: beginning of time (config cannot be changed yet);
24 * 1: initialized: cfg_set created (config can now be changed);
25 * 2: configured: command line parsed and config part of platform file was
26 * integrated also, platform construction ongoing or done.
27 * (Config cannot be changed anymore!)
29 int _sg_cfg_init_status = 0;
31 /* instruct the upper layer (simix or simdag) to exit as soon as possible */
32 int _sg_cfg_exit_asap = 0;
34 #define sg_cfg_exit_early() do { _sg_cfg_exit_asap = 1; return; } while (0)
36 /* Parse the command line, looking for options */
37 static void sg_config_cmd_line(int *argc, char **argv)
43 for (j = i = 1; i < *argc; i++) {
44 if (not strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
45 char *opt = strchr(argv[i], '=');
48 xbt_cfg_set_parse(opt);
49 XBT_DEBUG("Did apply '%s' as config setting", opt);
50 } else if (not strcmp(argv[i], "--version")) {
51 printf("%s\n", SIMGRID_VERSION_STRING);
53 } else if (not strcmp(argv[i], "--cfg-help") || not strcmp(argv[i], "--help")) {
54 printf("Description of the configuration accepted by this simulator:\n");
58 "Each of these configurations can be used by adding\n"
59 " --cfg=<option name>:<option value>\n"
60 "to the command line.\n"
62 "For more information, please refer to:\n"
63 " --help-aliases for the list of all option aliases.\n"
64 " --help-logs and --help-log-categories for the details of logging output.\n"
65 " --help-models for a list of all models known by this simulator.\n"
66 " --help-tracing for the details of all tracing options known by this simulator.\n"
67 " --version to get SimGrid version information.\n"
71 } else if (not strcmp(argv[i], "--help-aliases")) {
72 printf("Here is a list of all deprecated option names, with their replacement.\n");
74 printf("Please consider using the recent names\n");
76 } else if (not strcmp(argv[i], "--help-models")) {
77 model_help("host", surf_host_model_description);
79 model_help("CPU", surf_cpu_model_description);
81 model_help("network", surf_network_model_description);
82 printf("\nLong description of all optimization levels accepted by the models of this simulator:\n");
83 for (int k = 0; surf_optimization_mode_description[k].name; k++)
85 surf_optimization_mode_description[k].name,
86 surf_optimization_mode_description[k].description);
87 printf("Both network and CPU models have 'Lazy' as default optimization level\n\n");
89 } else if (not strcmp(argv[i], "--help-tracing")) {
104 /* callback of the plugin variable */
105 static void _sg_cfg_cb__plugin(const std::string& value)
107 xbt_assert(_sg_cfg_init_status < 2, "Cannot load a plugin after the initialization");
112 if (value == "help") {
113 model_help("plugin", surf_plugin_description);
117 int plugin_id = find_model_description(surf_plugin_description, value);
118 surf_plugin_description[plugin_id].model_init_preparse();
121 /* callback of the host/model variable */
122 static void _sg_cfg_cb__host_model(const std::string& value)
124 xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
126 if (value == "help") {
127 model_help("host", surf_host_model_description);
131 /* Make sure that the model exists */
132 find_model_description(surf_host_model_description, value);
135 /* callback of the cpu/model variable */
136 static void _sg_cfg_cb__cpu_model(const std::string& value)
138 xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
140 if (value == "help") {
141 model_help("CPU", surf_cpu_model_description);
145 /* New Module missing */
146 find_model_description(surf_cpu_model_description, value);
149 /* callback of the cpu/model variable */
150 static void _sg_cfg_cb__optimization_mode(const std::string& value)
152 xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
154 if (value == "help") {
155 model_help("optimization", surf_optimization_mode_description);
159 /* New Module missing */
160 find_model_description(surf_optimization_mode_description, value);
163 /* callback of the cpu/model variable */
164 static void _sg_cfg_cb__storage_mode(const std::string& value)
166 xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
168 if (value == "help") {
169 model_help("storage", surf_storage_model_description);
173 find_model_description(surf_storage_model_description, value);
176 /* callback of the network_model variable */
177 static void _sg_cfg_cb__network_model(const std::string& value)
179 xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
181 if (value == "help") {
182 model_help("network", surf_network_model_description);
186 /* New Module missing */
187 find_model_description(surf_network_model_description, value);
191 extern int _sg_do_model_check_record;
192 static void _sg_cfg_cb_model_check_record(const char *name) {
193 _sg_do_model_check_record = xbt_cfg_get_boolean(name);
197 static void _sg_cfg_cb_contexts_parallel_mode(const std::string& mode_name)
199 if (mode_name == "posix") {
200 SIMIX_context_set_parallel_mode(XBT_PARMAP_POSIX);
201 } else if (mode_name == "futex") {
202 SIMIX_context_set_parallel_mode(XBT_PARMAP_FUTEX);
203 } else if (mode_name == "busy_wait") {
204 SIMIX_context_set_parallel_mode(XBT_PARMAP_BUSY_WAIT);
206 xbt_die("Command line setting of the parallel synchronization mode should "
207 "be one of \"posix\", \"futex\" or \"busy_wait\"");
211 /* build description line with possible values */
212 static void describe_model(char *result,int resultsize,
213 const s_surf_model_description_t model_description[],
215 const char *description)
219 p += snprintf(result,resultsize-1, "%s. Possible values: %s", description,
220 model_description[0].name ? model_description[0].name : "n/a");
221 for (int i = 1; model_description[i].name; i++)
222 p += snprintf(p,resultsize-(p-result)-1, ", %s", model_description[i].name);
223 p += snprintf(p,resultsize-(p-result)-1, ".\n (use 'help' as a value to see the long description of each %s)", name);
225 xbt_assert(p<result+resultsize-1,"Buffer too small to display the model description of %s",name);
228 /* create the config set, register what should be and parse the command line*/
229 void sg_config_init(int *argc, char **argv)
231 const int descsize = 1024;
232 char description[descsize];
234 /* Create the configuration support */
235 if (_sg_cfg_init_status != 0) { /* Only create stuff if not already inited */
236 XBT_WARN("Call to sg_config_init() after initialization ignored");
240 /* Plugins configuration */
241 describe_model(description, descsize, surf_plugin_description, "plugin", "The plugins");
242 simgrid::config::declareFlag<std::string>("plugin", description, "", &_sg_cfg_cb__plugin);
244 describe_model(description, descsize, surf_cpu_model_description, "model", "The model to use for the CPU");
245 simgrid::config::declareFlag<std::string>("cpu/model", description, "Cas01", &_sg_cfg_cb__cpu_model);
247 describe_model(description, descsize, surf_storage_model_description, "model", "The model to use for the storage");
248 simgrid::config::declareFlag<std::string>("storage/model", description, "default", &_sg_cfg_cb__storage_mode);
250 describe_model(description, descsize, surf_network_model_description, "model", "The model to use for the network");
251 simgrid::config::declareFlag<std::string>("network/model", description, "LV08", &_sg_cfg_cb__network_model);
253 describe_model(description, descsize, surf_optimization_mode_description, "optimization mode",
254 "The optimization modes to use for the network");
255 simgrid::config::declareFlag<std::string>("network/optim", description, "Lazy", &_sg_cfg_cb__optimization_mode);
257 describe_model(description, descsize, surf_host_model_description, "model", "The model to use for the host");
258 simgrid::config::declareFlag<std::string>("host/model", description, "default", &_sg_cfg_cb__host_model);
260 simgrid::config::bindFlag(sg_surf_precision, "surf/precision",
261 "Numerical precision used when updating simulation times (in seconds)");
263 simgrid::config::bindFlag(sg_maxmin_precision, "maxmin/precision",
264 "Numerical precision used when computing resource sharing (in flops/sec or bytes/sec)");
266 simgrid::config::bindFlag(sg_concurrency_limit, "maxmin/concurrency-limit", {"maxmin/concurrency_limit"},
267 "Maximum number of concurrent variables in the maxmim system. Also limits the number of "
268 "processes on each host, at higher level. (default: -1 means no such limitation)");
270 /* The parameters of network models */
272 sg_latency_factor = 13.01; // comes from the default LV08 network model
273 simgrid::config::bindFlag(sg_latency_factor, "network/latency-factor", {"network/latency_factor"},
274 "Correction factor to apply to the provided latency (default value set by network model)");
276 sg_bandwidth_factor = 0.97; // comes from the default LV08 network model
277 simgrid::config::bindFlag(
278 sg_bandwidth_factor, "network/bandwidth-factor", {"network/bandwidth_factor"},
279 "Correction factor to apply to the provided bandwidth (default value set by network model)");
281 sg_weight_S_parameter = 20537; // comes from the default LV08 network model
282 simgrid::config::bindFlag(
283 sg_weight_S_parameter, "network/weight-S", {"network/weight_S"},
284 "Correction factor to apply to the weight of competing streams (default value set by network model)");
287 simgrid::config::declareFlag<std::string>("path", "Lookup path for inclusions in platform and deployment XML files",
288 "", [](std::string const& path) {
289 if (not path.empty())
290 surf_path.push_back(path);
293 simgrid::config::declareFlag<bool>("cpu/maxmin-selective-update", "Update the constraint set propagating recursively "
294 "to others constraints (off by default unless "
295 "optim is set to lazy)",
297 simgrid::config::alias("cpu/maxmin-selective-update", {"cpu/maxmin_selective_update"});
298 simgrid::config::declareFlag<bool>("network/maxmin-selective-update", "Update the constraint set propagating "
299 "recursively to others constraints (off by "
300 "default unless optim is set to lazy)",
302 simgrid::config::alias("network/maxmin-selective-update", {"network/maxmin_selective_update"});
303 /* Replay (this part is enabled even if MC it disabled) */
304 simgrid::config::bindFlag(MC_record_path, "model-check/replay",
305 "Model-check path to replay (as reported by SimGrid when a violation is reported)");
308 /* do model-checking-record */
309 xbt_cfg_register_boolean("model-check/record", "no", _sg_cfg_cb_model_check_record,
310 "Record the model-checking paths");
312 xbt_cfg_register_int("model-check/checkpoint", 0, _mc_cfg_cb_checkpoint,
313 "Specify the amount of steps between checkpoints during stateful model-checking (default: 0 => "
314 "stateless verification). "
315 "If value=1, one checkpoint is saved for each step => faster verification, but huge memory "
316 "consumption; higher values are good compromises between speed and memory consumption.");
318 xbt_cfg_register_boolean("model-check/sparse-checkpoint", "no", _mc_cfg_cb_sparse_checkpoint,
319 "Use sparse per-page snapshots.");
320 xbt_cfg_register_boolean("model-check/ksm", "no", _mc_cfg_cb_ksm, "Kernel same-page merging");
322 xbt_cfg_register_string("model-check/property", "", _mc_cfg_cb_property,
323 "Name of the file containing the property, as formatted by the ltl2ba program.");
324 xbt_cfg_register_boolean("model-check/communications-determinism", "no", _mc_cfg_cb_comms_determinism,
325 "Whether to enable the detection of communication determinism");
326 simgrid::config::alias("model-check/communications-determinism", {"model-check/communications_determinism"});
328 xbt_cfg_register_boolean("model-check/send-determinism", "no", _mc_cfg_cb_send_determinism,
329 "Enable/disable the detection of send-determinism in the communications schemes");
330 simgrid::config::alias("model-check/send-determinism", {"model-check/send_determinism"});
332 /* Specify the kind of model-checking reduction */
333 xbt_cfg_register_string("model-check/reduction", "dpor", _mc_cfg_cb_reduce,
334 "Specify the kind of exploration reduction (either none or DPOR)");
335 xbt_cfg_register_boolean("model-check/timeout", "no", _mc_cfg_cb_timeout,
336 "Whether to enable timeouts for wait requests");
338 xbt_cfg_register_boolean("model-check/hash", "no", _mc_cfg_cb_hash,
339 "Whether to enable state hash for state comparison (experimental)");
340 xbt_cfg_register_boolean("model-check/snapshot-fds", "no", _mc_cfg_cb_snapshot_fds,
341 "Whether file descriptors must be snapshoted (currently unusable)");
342 simgrid::config::alias("model-check/snapshot-fds", {"model-check/snapshot_fds"});
343 xbt_cfg_register_int("model-check/max-depth", 1000, _mc_cfg_cb_max_depth,
344 "Maximal exploration depth (default: 1000)");
345 simgrid::config::alias("model-check/max-depth", {"model-check/max_depth"});
346 xbt_cfg_register_int("model-check/visited", 0, _mc_cfg_cb_visited,
347 "Specify the number of visited state stored for state comparison reduction. If value=5, the "
348 "last 5 visited states are stored. If value=0 (the default), all states are stored.");
350 xbt_cfg_register_string("model-check/dot-output", "", _mc_cfg_cb_dot_output,
351 "Name of dot output file corresponding to graph state");
352 simgrid::config::alias("model-check/dot-output", {"model-check/dot_output"});
353 xbt_cfg_register_boolean("model-check/termination", "no", _mc_cfg_cb_termination,
354 "Whether to enable non progressive cycle detection");
357 extern bool _sg_do_verbose_exit;
358 simgrid::config::bindFlag(_sg_do_verbose_exit, "verbose-exit", "Activate the \"do nothing\" mode in Ctrl-C");
360 simgrid::config::declareFlag<int>("contexts/stack-size", "Stack size of contexts in KiB", 8 * 1024,
361 [](int value) { smx_context_stack_size = value * 1024; });
362 simgrid::config::alias("contexts/stack-size", {"contexts/stack_size"});
364 /* guard size for contexts stacks in memory pages */
365 #if defined(_WIN32) || (PTH_STACKGROWTH != -1)
366 int default_guard_size = 0;
368 int default_guard_size = 1;
370 simgrid::config::declareFlag<int>("contexts/guard-size", "Guard size for contexts stacks in memory pages",
372 [](int value) { smx_context_guard_size = value * xbt_pagesize; });
373 simgrid::config::alias("contexts/guard-size", {"contexts/guard_size"});
374 simgrid::config::declareFlag<int>("contexts/nthreads", "Number of parallel threads used to execute user contexts", 1,
375 &SIMIX_context_set_nthreads);
377 simgrid::config::declareFlag<int>("contexts/parallel-threshold",
378 "Minimal number of user contexts to be run in parallel (raw contexts only)", 2,
379 &SIMIX_context_set_parallel_threshold);
380 simgrid::config::alias("contexts/parallel-threshold", {"contexts/parallel_threshold"});
382 /* synchronization mode for parallel user contexts */
384 std::string default_synchro_mode = "futex";
385 #else //No futex on mac and posix is unimplememted yet
386 std::string default_synchro_mode = "busy_wait";
388 simgrid::config::declareFlag<std::string>("contexts/synchro", "Synchronization mode to use when running contexts in "
389 "parallel (either futex, posix or busy_wait)",
390 default_synchro_mode, &_sg_cfg_cb_contexts_parallel_mode);
392 // For smpi/bw-factor and smpi/lat-factor
393 // SMPI model can be used without enable_smpi, so keep this out of the ifdef.
394 simgrid::config::declareFlag<std::string>("smpi/bw-factor",
395 "Bandwidth factors for smpi. Format: "
396 "'threshold0:value0;threshold1:value1;...;thresholdN:valueN', "
397 "meaning if(size >=thresholdN ) return valueN.",
398 "65472:0.940694;15424:0.697866;9376:0.58729;5776:1.08739;3484:0.77493;"
399 "1426:0.608902;732:0.341987;257:0.338112;0:0.812084");
400 simgrid::config::alias("smpi/bw-factor", {"smpi/bw_factor"});
402 simgrid::config::declareFlag<std::string>("smpi/lat-factor", "Latency factors for smpi.",
403 "65472:11.6436;15424:3.48845;9376:2.59299;5776:2.18796;3484:1.88101;"
404 "1426:1.61075;732:1.9503;257:1.95341;0:2.01467");
405 simgrid::config::alias("smpi/lat-factor", {"smpi/lat_factor"});
406 simgrid::config::declareFlag<std::string>("smpi/IB-penalty-factors",
407 "Correction factor to communications using Infiniband model with "
408 "contention (default value based on Stampede cluster profiling)",
410 simgrid::config::alias("smpi/IB-penalty-factors", {"smpi/IB_penalty_factors"});
413 simgrid::config::declareFlag<double>("smpi/host-speed", "Speed of the host running the simulation (in flop/s). "
414 "Used to bench the operations.",
416 simgrid::config::alias("smpi/host-speed", {"smpi/running_power", "smpi/running-power"});
418 simgrid::config::declareFlag<bool>("smpi/keep-temps", "Whether we should keep the generated temporary files.", false);
420 simgrid::config::declareFlag<bool>("smpi/display-timing", "Whether we should display the timing after simulation.",
422 simgrid::config::alias("smpi/display-timing", {"smpi/display_timing"});
424 simgrid::config::declareFlag<bool>("smpi/simulate-computation",
425 "Whether the computational part of the simulated application should be simulated.",
427 simgrid::config::alias("smpi/simulate-computation", {"smpi/simulate_computation"});
429 simgrid::config::declareFlag<std::string>(
430 "smpi/shared-malloc", "Whether SMPI_SHARED_MALLOC is enabled. Disable it for debugging purposes.", "global");
431 simgrid::config::alias("smpi/shared-malloc", {"smpi/use_shared_malloc", "smpi/use-shared-malloc"});
432 simgrid::config::declareFlag<double>("smpi/shared-malloc-blocksize",
433 "Size of the bogus file which will be created for global shared allocations",
435 simgrid::config::declareFlag<std::string>("smpi/shared-malloc-hugepage",
436 "Path to a mounted hugetlbfs, to use huge pages with shared malloc.", "");
438 simgrid::config::declareFlag<double>(
439 "smpi/cpu-threshold", "Minimal computation time (in seconds) not discarded, or -1 for infinity.", 1e-6);
440 simgrid::config::alias("smpi/cpu-threshold", {"smpi/cpu_threshold"});
442 simgrid::config::declareFlag<int>(
443 "smpi/async-small-thresh",
444 "Maximal size of messages that are to be sent asynchronously, without waiting for the receiver", 0);
445 simgrid::config::alias("smpi/async-small-thresh", {"smpi/async_small_thres", "smpi/async_small_thresh"});
447 simgrid::config::declareFlag<bool>("smpi/trace-call-location",
448 "Should filename and linenumber of MPI calls be traced?", false);
450 simgrid::config::declareFlag<int>(
451 "smpi/send-is-detached-thresh",
452 "Threshold of message size where MPI_Send stops behaving like MPI_Isend and becomes MPI_Ssend", 65536);
453 simgrid::config::alias("smpi/send-is-detached-thresh",
454 {"smpi/send_is_detached_thres", "smpi/send_is_detached_thresh"});
456 const char* default_privatization = std::getenv("SMPI_PRIVATIZATION");
457 if (default_privatization == nullptr)
458 default_privatization = "no";
460 simgrid::config::declareFlag<std::string>(
461 "smpi/privatization", "How we should privatize global variable at runtime (no, yes, mmap, dlopen).",
462 default_privatization);
463 simgrid::config::alias("smpi/privatization", {"smpi/privatize_global_variables", "smpi/privatize-global-variables"});
465 simgrid::config::declareFlag<bool>("smpi/grow-injected-times",
466 "Whether we want to make the injected time in MPI_Iprobe and MPI_Test grow, to "
467 "allow faster simulation. This can make simulation less precise, though.",
471 simgrid::config::declareFlag<std::string>("smpi/papi-events",
472 "This switch enables tracking the specified counters with PAPI", "");
474 simgrid::config::declareFlag<std::string>("smpi/comp-adjustment-file",
475 "A file containing speedups or slowdowns for some parts of the code.", "");
476 simgrid::config::declareFlag<std::string>(
477 "smpi/os", "Small messages timings (MPI_Send minimum time for small messages)", "0:0:0:0:0");
478 simgrid::config::declareFlag<std::string>(
479 "smpi/ois", "Small messages timings (MPI_Isend minimum time for small messages)", "0:0:0:0:0");
480 simgrid::config::declareFlag<std::string>(
481 "smpi/or", "Small messages timings (MPI_Recv minimum time for small messages)", "0:0:0:0:0");
483 simgrid::config::declareFlag<double>("smpi/iprobe-cpu-usage",
484 "Maximum usage of CPUs by MPI_Iprobe() calls. We've observed that MPI_Iprobes "
485 "consume significantly less power than the maximum of a specific application. "
486 "This value is then (Iprobe_Usage/Max_Application_Usage).",
489 simgrid::config::declareFlag<std::string>("smpi/coll-selector", "Which collective selector to use", "default");
490 simgrid::config::alias("smpi/coll-selector", {"smpi/coll_selector"});
491 simgrid::config::declareFlag<std::string>("smpi/gather", "Which collective to use for gather", "");
492 simgrid::config::declareFlag<std::string>("smpi/allgather", "Which collective to use for allgather", "");
493 simgrid::config::declareFlag<std::string>("smpi/barrier", "Which collective to use for barrier", "");
494 simgrid::config::declareFlag<std::string>("smpi/reduce_scatter", "Which collective to use for reduce_scatter", "");
495 simgrid::config::alias("smpi/reduce_scatter", {"smpi/reduce-scatter"});
496 simgrid::config::declareFlag<std::string>("smpi/scatter", "Which collective to use for scatter", "");
497 simgrid::config::declareFlag<std::string>("smpi/allgatherv", "Which collective to use for allgatherv", "");
498 simgrid::config::declareFlag<std::string>("smpi/allreduce", "Which collective to use for allreduce", "");
499 simgrid::config::declareFlag<std::string>("smpi/alltoall", "Which collective to use for alltoall", "");
500 simgrid::config::declareFlag<std::string>("smpi/alltoallv", "Which collective to use for alltoallv", "");
501 simgrid::config::declareFlag<std::string>("smpi/bcast", "Which collective to use for bcast", "");
502 simgrid::config::declareFlag<std::string>("smpi/reduce", "Which collective to use for reduce", "");
507 sg_storage_max_file_descriptors = 1024;
508 simgrid::config::bindFlag(sg_storage_max_file_descriptors, "storage/max_file_descriptors",
509 "Maximum number of concurrently opened files per host. Default is 1024");
513 simgrid::config::declareFlag<bool>(
514 "exception/cutpath", "Whether to cut all path information from call traces, used e.g. in exceptions.", false);
516 extern bool _sg_do_clean_atexit;
517 simgrid::config::bindFlag(_sg_do_clean_atexit, "clean-atexit", {"clean_atexit"},
518 "Whether to cleanup SimGrid at exit. Disable it if your code segfaults after its end.");
520 if (surf_path.empty())
521 xbt_cfg_setdefault_string("path", "./");
523 _sg_cfg_init_status = 1;
525 sg_config_cmd_line(argc, argv);
527 xbt_mallocator_initialization_is_done(SIMIX_context_is_parallel());
530 void sg_config_finalize()
532 if (not _sg_cfg_init_status)
533 return; /* Not initialized yet. Nothing to do */
535 xbt_cfg_free(&simgrid_config);
536 _sg_cfg_init_status = 0;