Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
42019689ae8da6c5a825cf110200736a9c3d7ad0
[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       xbt_cfg_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::declareFlag<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::declareFlag<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::declareFlag<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::declareFlag<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::declareFlag<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::declareFlag<std::string>("host/model", description, "default", &_sg_cfg_cb__host_model);
251
252   simgrid::config::bindFlag(sg_surf_precision, "surf/precision",
253                             "Numerical precision used when updating simulation times (in seconds)");
254
255   simgrid::config::bindFlag(sg_maxmin_precision, "maxmin/precision",
256                             "Numerical precision used when computing resource sharing (in flops/sec or bytes/sec)");
257
258   simgrid::config::bindFlag(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::bindFlag(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::bindFlag(
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::bindFlag(
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::declareFlag<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::declareFlag<bool>("cpu/maxmin-selective-update", "Update the constraint set propagating recursively "
286                                                                     "to others constraints (off by default unless "
287                                                                     "optim is set to lazy)",
288                                      "no");
289   simgrid::config::alias("cpu/maxmin-selective-update", {"cpu/maxmin_selective_update"});
290   simgrid::config::declareFlag<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::bindFlag(_sg_do_verbose_exit, "verbose-exit", "Activate the \"do nothing\" mode in Ctrl-C");
298
299   simgrid::config::declareFlag<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::declareFlag<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::declareFlag<int>("contexts/nthreads", "Number of parallel threads used to execute user contexts", 1,
314                                     &SIMIX_context_set_nthreads);
315
316   simgrid::config::declareFlag<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::declareFlag<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::declareFlag<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::declareFlag<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::declareFlag<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::declareFlag<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::declareFlag<bool>("smpi/keep-temps", "Whether we should keep the generated temporary files.", false);
358
359   simgrid::config::declareFlag<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::declareFlag<bool>("smpi/simulate-computation",
364                                      "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::declareFlag<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::declareFlag<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::declareFlag<std::string>("smpi/shared-malloc-hugepage",
375                                             "Path to a mounted hugetlbfs, to use huge pages with shared malloc.", "");
376
377   simgrid::config::declareFlag<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::declareFlag<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::declareFlag<bool>("smpi/trace-call-location",
387                                      "Should filename and linenumber of MPI calls be traced?", false);
388
389   simgrid::config::declareFlag<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::declareFlag<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::declareFlag<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::declareFlag<std::string>("smpi/papi-events",
411                                             "This switch enables tracking the specified counters with PAPI", "");
412 #endif
413   simgrid::config::declareFlag<std::string>("smpi/comp-adjustment-file",
414                                             "A file containing speedups or slowdowns for some parts of the code.", "");
415   simgrid::config::declareFlag<std::string>(
416       "smpi/os", "Small messages timings (MPI_Send minimum time for small messages)", "0:0:0:0:0");
417   simgrid::config::declareFlag<std::string>(
418       "smpi/ois", "Small messages timings (MPI_Isend minimum time for small messages)", "0:0:0:0:0");
419   simgrid::config::declareFlag<std::string>(
420       "smpi/or", "Small messages timings (MPI_Recv minimum time for small messages)", "0:0:0:0:0");
421
422   simgrid::config::declareFlag<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::declareFlag<std::string>("smpi/coll-selector", "Which collective selector to use", "default");
429   simgrid::config::alias("smpi/coll-selector", {"smpi/coll_selector"});
430   simgrid::config::declareFlag<std::string>("smpi/gather", "Which collective to use for gather", "");
431   simgrid::config::declareFlag<std::string>("smpi/allgather", "Which collective to use for allgather", "");
432   simgrid::config::declareFlag<std::string>("smpi/barrier", "Which collective to use for barrier", "");
433   simgrid::config::declareFlag<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::declareFlag<std::string>("smpi/scatter", "Which collective to use for scatter", "");
436   simgrid::config::declareFlag<std::string>("smpi/allgatherv", "Which collective to use for allgatherv", "");
437   simgrid::config::declareFlag<std::string>("smpi/allreduce", "Which collective to use for allreduce", "");
438   simgrid::config::declareFlag<std::string>("smpi/alltoall", "Which collective to use for alltoall", "");
439   simgrid::config::declareFlag<std::string>("smpi/alltoallv", "Which collective to use for alltoallv", "");
440   simgrid::config::declareFlag<std::string>("smpi/bcast", "Which collective to use for bcast", "");
441   simgrid::config::declareFlag<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::bindFlag(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::declareFlag<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::bindFlag(_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     xbt_cfg_setdefault_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   xbt_cfg_free(&simgrid_config);
475   _sg_cfg_init_status = 0;
476 }