Logo AND Algorithmique Numérique Distribuée

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