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);
190 static void _sg_cfg_cb_contexts_parallel_mode(const std::string& mode_name)
192 if (mode_name == "posix") {
193 SIMIX_context_set_parallel_mode(XBT_PARMAP_POSIX);
194 } else if (mode_name == "futex") {
195 SIMIX_context_set_parallel_mode(XBT_PARMAP_FUTEX);
196 } else if (mode_name == "busy_wait") {
197 SIMIX_context_set_parallel_mode(XBT_PARMAP_BUSY_WAIT);
199 xbt_die("Command line setting of the parallel synchronization mode should "
200 "be one of \"posix\", \"futex\" or \"busy_wait\"");
204 /* build description line with possible values */
205 static void describe_model(char *result,int resultsize,
206 const s_surf_model_description_t model_description[],
208 const char *description)
212 p += snprintf(result,resultsize-1, "%s. Possible values: %s", description,
213 model_description[0].name ? model_description[0].name : "n/a");
214 for (int i = 1; model_description[i].name; i++)
215 p += snprintf(p,resultsize-(p-result)-1, ", %s", model_description[i].name);
216 p += snprintf(p,resultsize-(p-result)-1, ".\n (use 'help' as a value to see the long description of each %s)", name);
218 xbt_assert(p<result+resultsize-1,"Buffer too small to display the model description of %s",name);
221 /* create the config set, register what should be and parse the command line*/
222 void sg_config_init(int *argc, char **argv)
224 const int descsize = 1024;
225 char description[descsize];
227 /* Create the configuration support */
228 if (_sg_cfg_init_status != 0) { /* Only create stuff if not already inited */
229 XBT_WARN("Call to sg_config_init() after initialization ignored");
233 /* Plugins configuration */
234 describe_model(description, descsize, surf_plugin_description, "plugin", "The plugins");
235 simgrid::config::declareFlag<std::string>("plugin", description, "", &_sg_cfg_cb__plugin);
237 describe_model(description, descsize, surf_cpu_model_description, "model", "The model to use for the CPU");
238 simgrid::config::declareFlag<std::string>("cpu/model", description, "Cas01", &_sg_cfg_cb__cpu_model);
240 describe_model(description, descsize, surf_storage_model_description, "model", "The model to use for the storage");
241 simgrid::config::declareFlag<std::string>("storage/model", description, "default", &_sg_cfg_cb__storage_mode);
243 describe_model(description, descsize, surf_network_model_description, "model", "The model to use for the network");
244 simgrid::config::declareFlag<std::string>("network/model", description, "LV08", &_sg_cfg_cb__network_model);
246 describe_model(description, descsize, surf_optimization_mode_description, "optimization mode",
247 "The optimization modes to use for the network");
248 simgrid::config::declareFlag<std::string>("network/optim", description, "Lazy", &_sg_cfg_cb__optimization_mode);
250 describe_model(description, descsize, surf_host_model_description, "model", "The model to use for the host");
251 simgrid::config::declareFlag<std::string>("host/model", description, "default", &_sg_cfg_cb__host_model);
253 simgrid::config::bindFlag(sg_surf_precision, "surf/precision",
254 "Numerical precision used when updating simulation times (in seconds)");
256 simgrid::config::bindFlag(sg_maxmin_precision, "maxmin/precision",
257 "Numerical precision used when computing resource sharing (in flops/sec or bytes/sec)");
259 simgrid::config::bindFlag(sg_concurrency_limit, "maxmin/concurrency-limit", {"maxmin/concurrency_limit"},
260 "Maximum number of concurrent variables in the maxmim system. Also limits the number of "
261 "processes on each host, at higher level. (default: -1 means no such limitation)");
263 /* The parameters of network models */
265 sg_latency_factor = 13.01; // comes from the default LV08 network model
266 simgrid::config::bindFlag(sg_latency_factor, "network/latency-factor", {"network/latency_factor"},
267 "Correction factor to apply to the provided latency (default value set by network model)");
269 sg_bandwidth_factor = 0.97; // comes from the default LV08 network model
270 simgrid::config::bindFlag(
271 sg_bandwidth_factor, "network/bandwidth-factor", {"network/bandwidth_factor"},
272 "Correction factor to apply to the provided bandwidth (default value set by network model)");
274 sg_weight_S_parameter = 20537; // comes from the default LV08 network model
275 simgrid::config::bindFlag(
276 sg_weight_S_parameter, "network/weight-S", {"network/weight_S"},
277 "Correction factor to apply to the weight of competing streams (default value set by network model)");
280 simgrid::config::declareFlag<std::string>("path", "Lookup path for inclusions in platform and deployment XML files",
281 "", [](std::string const& path) {
282 if (not path.empty())
283 surf_path.push_back(path);
286 simgrid::config::declareFlag<bool>("cpu/maxmin-selective-update", "Update the constraint set propagating recursively "
287 "to others constraints (off by default unless "
288 "optim is set to lazy)",
290 simgrid::config::alias("cpu/maxmin-selective-update", {"cpu/maxmin_selective_update"});
291 simgrid::config::declareFlag<bool>("network/maxmin-selective-update", "Update the constraint set propagating "
292 "recursively to others constraints (off by "
293 "default unless optim is set to lazy)",
295 simgrid::config::alias("network/maxmin-selective-update", {"network/maxmin_selective_update"});
297 extern bool _sg_do_verbose_exit;
298 simgrid::config::bindFlag(_sg_do_verbose_exit, "verbose-exit", "Activate the \"do nothing\" mode in Ctrl-C");
300 simgrid::config::declareFlag<int>("contexts/stack-size", "Stack size of contexts in KiB", 8 * 1024,
301 [](int value) { smx_context_stack_size = value * 1024; });
302 simgrid::config::alias("contexts/stack-size", {"contexts/stack_size"});
304 /* guard size for contexts stacks in memory pages */
305 #if defined(_WIN32) || (PTH_STACKGROWTH != -1)
306 int default_guard_size = 0;
308 int default_guard_size = 1;
310 simgrid::config::declareFlag<int>("contexts/guard-size", "Guard size for contexts stacks in memory pages",
312 [](int value) { smx_context_guard_size = value * xbt_pagesize; });
313 simgrid::config::alias("contexts/guard-size", {"contexts/guard_size"});
314 simgrid::config::declareFlag<int>("contexts/nthreads", "Number of parallel threads used to execute user contexts", 1,
315 &SIMIX_context_set_nthreads);
317 simgrid::config::declareFlag<int>("contexts/parallel-threshold",
318 "Minimal number of user contexts to be run in parallel (raw contexts only)", 2,
319 &SIMIX_context_set_parallel_threshold);
320 simgrid::config::alias("contexts/parallel-threshold", {"contexts/parallel_threshold"});
322 /* synchronization mode for parallel user contexts */
324 std::string default_synchro_mode = "futex";
325 #else //No futex on mac and posix is unimplememted yet
326 std::string default_synchro_mode = "busy_wait";
328 simgrid::config::declareFlag<std::string>("contexts/synchro", "Synchronization mode to use when running contexts in "
329 "parallel (either futex, posix or busy_wait)",
330 default_synchro_mode, &_sg_cfg_cb_contexts_parallel_mode);
332 // For smpi/bw-factor and smpi/lat-factor
333 // SMPI model can be used without enable_smpi, so keep this out of the ifdef.
334 simgrid::config::declareFlag<std::string>("smpi/bw-factor",
335 "Bandwidth factors for smpi. Format: "
336 "'threshold0:value0;threshold1:value1;...;thresholdN:valueN', "
337 "meaning if(size >=thresholdN ) return valueN.",
338 "65472:0.940694;15424:0.697866;9376:0.58729;5776:1.08739;3484:0.77493;"
339 "1426:0.608902;732:0.341987;257:0.338112;0:0.812084");
340 simgrid::config::alias("smpi/bw-factor", {"smpi/bw_factor"});
342 simgrid::config::declareFlag<std::string>("smpi/lat-factor", "Latency factors for smpi.",
343 "65472:11.6436;15424:3.48845;9376:2.59299;5776:2.18796;3484:1.88101;"
344 "1426:1.61075;732:1.9503;257:1.95341;0:2.01467");
345 simgrid::config::alias("smpi/lat-factor", {"smpi/lat_factor"});
346 simgrid::config::declareFlag<std::string>("smpi/IB-penalty-factors",
347 "Correction factor to communications using Infiniband model with "
348 "contention (default value based on Stampede cluster profiling)",
350 simgrid::config::alias("smpi/IB-penalty-factors", {"smpi/IB_penalty_factors"});
353 simgrid::config::declareFlag<double>("smpi/host-speed", "Speed of the host running the simulation (in flop/s). "
354 "Used to bench the operations.",
356 simgrid::config::alias("smpi/host-speed", {"smpi/running_power", "smpi/running-power"});
358 simgrid::config::declareFlag<bool>("smpi/keep-temps", "Whether we should keep the generated temporary files.", false);
360 simgrid::config::declareFlag<bool>("smpi/display-timing", "Whether we should display the timing after simulation.",
362 simgrid::config::alias("smpi/display-timing", {"smpi/display_timing"});
364 simgrid::config::declareFlag<bool>("smpi/simulate-computation",
365 "Whether the computational part of the simulated application should be simulated.",
367 simgrid::config::alias("smpi/simulate-computation", {"smpi/simulate_computation"});
369 simgrid::config::declareFlag<std::string>(
370 "smpi/shared-malloc", "Whether SMPI_SHARED_MALLOC is enabled. Disable it for debugging purposes.", "global");
371 simgrid::config::alias("smpi/shared-malloc", {"smpi/use_shared_malloc", "smpi/use-shared-malloc"});
372 simgrid::config::declareFlag<double>("smpi/shared-malloc-blocksize",
373 "Size of the bogus file which will be created for global shared allocations",
375 simgrid::config::declareFlag<std::string>("smpi/shared-malloc-hugepage",
376 "Path to a mounted hugetlbfs, to use huge pages with shared malloc.", "");
378 simgrid::config::declareFlag<double>(
379 "smpi/cpu-threshold", "Minimal computation time (in seconds) not discarded, or -1 for infinity.", 1e-6);
380 simgrid::config::alias("smpi/cpu-threshold", {"smpi/cpu_threshold"});
382 simgrid::config::declareFlag<int>(
383 "smpi/async-small-thresh",
384 "Maximal size of messages that are to be sent asynchronously, without waiting for the receiver", 0);
385 simgrid::config::alias("smpi/async-small-thresh", {"smpi/async_small_thres", "smpi/async_small_thresh"});
387 simgrid::config::declareFlag<bool>("smpi/trace-call-location",
388 "Should filename and linenumber of MPI calls be traced?", false);
390 simgrid::config::declareFlag<int>(
391 "smpi/send-is-detached-thresh",
392 "Threshold of message size where MPI_Send stops behaving like MPI_Isend and becomes MPI_Ssend", 65536);
393 simgrid::config::alias("smpi/send-is-detached-thresh",
394 {"smpi/send_is_detached_thres", "smpi/send_is_detached_thresh"});
396 const char* default_privatization = std::getenv("SMPI_PRIVATIZATION");
397 if (default_privatization == nullptr)
398 default_privatization = "no";
400 simgrid::config::declareFlag<std::string>(
401 "smpi/privatization", "How we should privatize global variable at runtime (no, yes, mmap, dlopen).",
402 default_privatization);
403 simgrid::config::alias("smpi/privatization", {"smpi/privatize_global_variables", "smpi/privatize-global-variables"});
405 simgrid::config::declareFlag<bool>("smpi/grow-injected-times",
406 "Whether we want to make the injected time in MPI_Iprobe and MPI_Test grow, to "
407 "allow faster simulation. This can make simulation less precise, though.",
411 simgrid::config::declareFlag<std::string>("smpi/papi-events",
412 "This switch enables tracking the specified counters with PAPI", "");
414 simgrid::config::declareFlag<std::string>("smpi/comp-adjustment-file",
415 "A file containing speedups or slowdowns for some parts of the code.", "");
416 simgrid::config::declareFlag<std::string>(
417 "smpi/os", "Small messages timings (MPI_Send minimum time for small messages)", "0:0:0:0:0");
418 simgrid::config::declareFlag<std::string>(
419 "smpi/ois", "Small messages timings (MPI_Isend minimum time for small messages)", "0:0:0:0:0");
420 simgrid::config::declareFlag<std::string>(
421 "smpi/or", "Small messages timings (MPI_Recv minimum time for small messages)", "0:0:0:0:0");
423 simgrid::config::declareFlag<double>("smpi/iprobe-cpu-usage",
424 "Maximum usage of CPUs by MPI_Iprobe() calls. We've observed that MPI_Iprobes "
425 "consume significantly less power than the maximum of a specific application. "
426 "This value is then (Iprobe_Usage/Max_Application_Usage).",
429 simgrid::config::declareFlag<std::string>("smpi/coll-selector", "Which collective selector to use", "default");
430 simgrid::config::alias("smpi/coll-selector", {"smpi/coll_selector"});
431 simgrid::config::declareFlag<std::string>("smpi/gather", "Which collective to use for gather", "");
432 simgrid::config::declareFlag<std::string>("smpi/allgather", "Which collective to use for allgather", "");
433 simgrid::config::declareFlag<std::string>("smpi/barrier", "Which collective to use for barrier", "");
434 simgrid::config::declareFlag<std::string>("smpi/reduce_scatter", "Which collective to use for reduce_scatter", "");
435 simgrid::config::alias("smpi/reduce_scatter", {"smpi/reduce-scatter"});
436 simgrid::config::declareFlag<std::string>("smpi/scatter", "Which collective to use for scatter", "");
437 simgrid::config::declareFlag<std::string>("smpi/allgatherv", "Which collective to use for allgatherv", "");
438 simgrid::config::declareFlag<std::string>("smpi/allreduce", "Which collective to use for allreduce", "");
439 simgrid::config::declareFlag<std::string>("smpi/alltoall", "Which collective to use for alltoall", "");
440 simgrid::config::declareFlag<std::string>("smpi/alltoallv", "Which collective to use for alltoallv", "");
441 simgrid::config::declareFlag<std::string>("smpi/bcast", "Which collective to use for bcast", "");
442 simgrid::config::declareFlag<std::string>("smpi/reduce", "Which collective to use for reduce", "");
447 sg_storage_max_file_descriptors = 1024;
448 simgrid::config::bindFlag(sg_storage_max_file_descriptors, "storage/max_file_descriptors",
449 "Maximum number of concurrently opened files per host. Default is 1024");
453 simgrid::config::declareFlag<bool>(
454 "exception/cutpath", "Whether to cut all path information from call traces, used e.g. in exceptions.", false);
456 extern bool _sg_do_clean_atexit;
457 simgrid::config::bindFlag(_sg_do_clean_atexit, "clean-atexit", {"clean_atexit"},
458 "Whether to cleanup SimGrid at exit. Disable it if your code segfaults after its end.");
460 if (surf_path.empty())
461 xbt_cfg_setdefault_string("path", "./");
463 _sg_cfg_init_status = 1;
465 sg_config_cmd_line(argc, argv);
467 xbt_mallocator_initialization_is_done(SIMIX_context_is_parallel());
470 void sg_config_finalize()
472 if (not _sg_cfg_init_status)
473 return; /* Not initialized yet. Nothing to do */
475 xbt_cfg_free(&simgrid_config);
476 _sg_cfg_init_status = 0;