Logo AND Algorithmique Numérique Distribuée

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