Logo AND Algorithmique Numérique Distribuée

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