Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Convert MC config parameters to C++ API, and move their definitions to mc_config...
[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
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!)
28  */
29 int _sg_cfg_init_status = 0;
30
31 /* instruct the upper layer (simix or simdag) to exit as soon as possible */
32 int _sg_cfg_exit_asap = 0;
33
34 #define sg_cfg_exit_early() do { _sg_cfg_exit_asap = 1; return; } while (0)
35
36 /* Parse the command line, looking for options */
37 static void sg_config_cmd_line(int *argc, char **argv)
38 {
39   int shall_exit = 0;
40   int i;
41   int j;
42
43   for (j = i = 1; i < *argc; i++) {
44     if (not strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
45       char *opt = strchr(argv[i], '=');
46       opt++;
47
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);
52       shall_exit = 1;
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");
55       xbt_cfg_help();
56       printf(
57           "\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"
61           "\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"
68           "\n"
69         );
70       shall_exit = 1;
71     } else if (not strcmp(argv[i], "--help-aliases")) {
72       printf("Here is a list of all deprecated option names, with their replacement.\n");
73       xbt_cfg_aliases();
74       printf("Please consider using the recent names\n");
75       shall_exit = 1;
76     } else if (not strcmp(argv[i], "--help-models")) {
77       model_help("host", surf_host_model_description);
78       printf("\n");
79       model_help("CPU", surf_cpu_model_description);
80       printf("\n");
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++)
84         printf("  %s: %s\n",
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");
88       shall_exit = 1;
89     } else if (not strcmp(argv[i], "--help-tracing")) {
90       TRACE_help (1);
91       shall_exit = 1;
92     } else {
93       argv[j++] = argv[i];
94     }
95   }
96   if (j < *argc) {
97     argv[j] = nullptr;
98     *argc = j;
99   }
100   if (shall_exit)
101     sg_cfg_exit_early();
102 }
103
104 /* callback of the plugin variable */
105 static void _sg_cfg_cb__plugin(const std::string& value)
106 {
107   xbt_assert(_sg_cfg_init_status < 2, "Cannot load a plugin after the initialization");
108
109   if (value.empty())
110     return;
111
112   if (value == "help") {
113     model_help("plugin", surf_plugin_description);
114     sg_cfg_exit_early();
115   }
116
117   int plugin_id = find_model_description(surf_plugin_description, value);
118   surf_plugin_description[plugin_id].model_init_preparse();
119 }
120
121 /* callback of the host/model variable */
122 static void _sg_cfg_cb__host_model(const std::string& value)
123 {
124   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
125
126   if (value == "help") {
127     model_help("host", surf_host_model_description);
128     sg_cfg_exit_early();
129   }
130
131   /* Make sure that the model exists */
132   find_model_description(surf_host_model_description, value);
133 }
134
135 /* callback of the cpu/model variable */
136 static void _sg_cfg_cb__cpu_model(const std::string& value)
137 {
138   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
139
140   if (value == "help") {
141     model_help("CPU", surf_cpu_model_description);
142     sg_cfg_exit_early();
143   }
144
145   /* New Module missing */
146   find_model_description(surf_cpu_model_description, value);
147 }
148
149 /* callback of the cpu/model variable */
150 static void _sg_cfg_cb__optimization_mode(const std::string& value)
151 {
152   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
153
154   if (value == "help") {
155     model_help("optimization", surf_optimization_mode_description);
156     sg_cfg_exit_early();
157   }
158
159   /* New Module missing */
160   find_model_description(surf_optimization_mode_description, value);
161 }
162
163 /* callback of the cpu/model variable */
164 static void _sg_cfg_cb__storage_mode(const std::string& value)
165 {
166   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
167
168   if (value == "help") {
169     model_help("storage", surf_storage_model_description);
170     sg_cfg_exit_early();
171   }
172
173   find_model_description(surf_storage_model_description, value);
174 }
175
176 /* callback of the network_model variable */
177 static void _sg_cfg_cb__network_model(const std::string& value)
178 {
179   xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
180
181   if (value == "help") {
182     model_help("network", surf_network_model_description);
183     sg_cfg_exit_early();
184   }
185
186   /* New Module missing */
187   find_model_description(surf_network_model_description, value);
188 }
189
190 static void _sg_cfg_cb_contexts_parallel_mode(const std::string& mode_name)
191 {
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);
198   } else {
199     xbt_die("Command line setting of the parallel synchronization mode should "
200             "be one of \"posix\", \"futex\" or \"busy_wait\"");
201   }
202 }
203
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[],
207                            const char *name,
208                            const char *description)
209 {
210   result[0] = '\0';
211   char *p = result;
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);
217
218   xbt_assert(p<result+resultsize-1,"Buffer too small to display the model description of %s",name);
219 }
220
221 /* create the config set, register what should be and parse the command line*/
222 void sg_config_init(int *argc, char **argv)
223 {
224   const int descsize = 1024;
225   char description[descsize];
226
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");
230     return;
231   }
232
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);
236
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);
239
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);
242
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);
245
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);
249
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);
252
253   simgrid::config::bindFlag(sg_surf_precision, "surf/precision",
254                             "Numerical precision used when updating simulation times (in seconds)");
255
256   simgrid::config::bindFlag(sg_maxmin_precision, "maxmin/precision",
257                             "Numerical precision used when computing resource sharing (in flops/sec or bytes/sec)");
258
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)");
262
263   /* The parameters of network models */
264
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)");
268
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)");
273
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)");
278
279   /* Inclusion path */
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);
284                                             });
285
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)",
289                                      "no");
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)",
294                                      "no");
295   simgrid::config::alias("network/maxmin-selective-update", {"network/maxmin_selective_update"});
296
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");
299
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"});
303
304   /* guard size for contexts stacks in memory pages */
305 #if defined(_WIN32) || (PTH_STACKGROWTH != -1)
306   int default_guard_size = 0;
307 #else
308   int default_guard_size = 1;
309 #endif
310   simgrid::config::declareFlag<int>("contexts/guard-size", "Guard size for contexts stacks in memory pages",
311                                     default_guard_size,
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);
316
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"});
321
322   /* synchronization mode for parallel user contexts */
323 #if HAVE_FUTEX_H
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";
327 #endif
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);
331
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"});
341
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)",
349                                             "0.965;0.925;1.35");
350   simgrid::config::alias("smpi/IB-penalty-factors", {"smpi/IB_penalty_factors"});
351
352 #if HAVE_SMPI
353   simgrid::config::declareFlag<double>("smpi/host-speed", "Speed of the host running the simulation (in flop/s). "
354                                                           "Used to bench the operations.",
355                                        20000.0);
356   simgrid::config::alias("smpi/host-speed", {"smpi/running_power", "smpi/running-power"});
357
358   simgrid::config::declareFlag<bool>("smpi/keep-temps", "Whether we should keep the generated temporary files.", false);
359
360   simgrid::config::declareFlag<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::declareFlag<bool>("smpi/simulate-computation",
365                                      "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::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",
374                                        1UL << 20);
375   simgrid::config::declareFlag<std::string>("smpi/shared-malloc-hugepage",
376                                             "Path to a mounted hugetlbfs, to use huge pages with shared malloc.", "");
377
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"});
381
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"});
386
387   simgrid::config::declareFlag<bool>("smpi/trace-call-location",
388                                      "Should filename and linenumber of MPI calls be traced?", false);
389
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"});
395
396   const char* default_privatization = std::getenv("SMPI_PRIVATIZATION");
397   if (default_privatization == nullptr)
398     default_privatization = "no";
399
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"});
404
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.",
408                                      true);
409
410 #if HAVE_PAPI
411   simgrid::config::declareFlag<std::string>("smpi/papi-events",
412                                             "This switch enables tracking the specified counters with PAPI", "");
413 #endif
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");
422
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).",
427                                        1.0);
428
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", "");
443 #endif // HAVE_SMPI
444
445   /* Storage */
446
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");
450
451   /* Others */
452
453   simgrid::config::declareFlag<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::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.");
459
460   if (surf_path.empty())
461     xbt_cfg_setdefault_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 }