Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of scm.gforge.inria.fr:/gitroot/simgrid/simgrid
[simgrid.git] / src / simgrid / sg_config.c
1 /* Copyright (c) 2009-2010, 2012-2015. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 /* sg_config: configuration infrastructure for the simulation world       */
8
9 #include "xbt/misc.h"
10 #include "xbt/config.h"
11 #include "xbt/log.h"
12 #include "xbt/mallocator.h"
13 #include "xbt/str.h"
14 #include "xbt/lib.h"
15 #include "xbt/sysdep.h"
16 #include "surf/surf.h"
17 #include "surf/maxmin.h"
18 #include "instr/instr_interface.h"
19 #include "simgrid/simix.h"
20 #include "simgrid/sg_config.h"
21 #include "simgrid_config.h" /* what was compiled in? */
22 #ifdef HAVE_SMPI
23 #include "smpi/smpi_interface.h"
24 #endif
25 #include "mc/mc.h"
26 #include "src/mc/mc_record.h"
27 #include "simgrid/instr.h"
28 #include "src/mc/mc_replay.h"
29
30 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf,
31                                 "About the configuration of SimGrid");
32
33 xbt_cfg_t _sg_cfg_set = NULL;
34
35 /* 0: beginning of time (config cannot be changed yet);
36  * 1: initialized: cfg_set created (config can now be changed);
37  * 2: configured: command line parsed and config part of platform file was
38  *    integrated also, platform construction ongoing or done.
39  *    (Config cannot be changed anymore!)
40  */
41 int _sg_cfg_init_status = 0;
42
43 /* instruct the upper layer (simix or simdag) to exit as soon as possible */
44 int _sg_cfg_exit_asap = 0;
45
46 #define sg_cfg_exit_early() do { _sg_cfg_exit_asap = 1; return; } while (0)
47
48 /* Parse the command line, looking for options */
49 static void sg_config_cmd_line(int *argc, char **argv)
50 {
51   int shall_exit = 0;
52   int i, j;
53   char *opt;
54
55   for (j = i = 1; i < *argc; i++) {
56     if (!strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
57       opt = strchr(argv[i], '=');
58       opt++;
59
60       xbt_cfg_set_parse(_sg_cfg_set, opt);
61       XBT_DEBUG("Did apply '%s' as config setting", opt);
62     } else if (!strcmp(argv[i], "--version")) {
63       printf("%s\n", SIMGRID_VERSION_STRING);
64       shall_exit = 1;
65     } else if (!strcmp(argv[i], "--cfg-help") || !strcmp(argv[i], "--help")) {
66       printf("Description of the configuration accepted by this simulator:\n");
67       xbt_cfg_help(_sg_cfg_set);
68       printf(
69           "\n"
70           "Each of these configurations can be used by adding\n"
71           "    --cfg=<option name>:<option value>\n"
72           "to the command line.\n"
73           "\n"
74           "For more information, please refer to:\n"
75           "   --help-aliases for the list of all option aliases.\n"
76           "   --help-logs and --help-log-categories for the details of logging output.\n"
77           "   --help-models for a list of all models known by this simulator.\n"
78           "   --help-tracing for the details of all tracing options known by this simulator.\n"
79           "   --version to get SimGrid version information.\n"
80           "\n"
81         );
82       shall_exit = 1;
83     } else if (!strcmp(argv[i], "--help-aliases")) {
84       printf("Here is a list of all deprecated option names, with their replacement.\n");
85       xbt_cfg_aliases(_sg_cfg_set);
86       printf("Please consider using the recent names\n");
87       shall_exit = 1;
88     } else if (!strcmp(argv[i], "--help-models")) {
89       int k;
90
91       model_help("host", surf_host_model_description);
92       printf("\n");
93       model_help("CPU", surf_cpu_model_description);
94       printf("\n");
95       model_help("network", surf_network_model_description);
96       printf("\nLong description of all optimization levels accepted by the models of this simulator:\n");
97       for (k = 0; surf_optimization_mode_description[k].name; k++)
98         printf("  %s: %s\n",
99                surf_optimization_mode_description[k].name,
100                surf_optimization_mode_description[k].description);
101       printf("Both network and CPU models have 'Lazy' as default optimization level\n\n");
102       shall_exit = 1;
103     } else if (!strcmp(argv[i], "--help-tracing")) {
104       TRACE_help (1);
105       shall_exit = 1;
106     } else {
107       argv[j++] = argv[i];
108     }
109   }
110   if (j < *argc) {
111     argv[j] = NULL;
112     *argc = j;
113   }
114   if (shall_exit)
115     sg_cfg_exit_early();
116 }
117
118 /* callback of the plugin variable */
119 static void _sg_cfg_cb__plugin(const char *name, int pos)
120 {
121   char *val;
122
123   XBT_VERB("PLUGIN");
124   xbt_assert(_sg_cfg_init_status < 2,
125               "Cannot load a plugin after the initialization");
126
127   val = xbt_cfg_get_string(_sg_cfg_set, name);
128
129   if (!strcmp(val, "help")) {
130     model_help("plugin", surf_plugin_description);
131     sg_cfg_exit_early();
132   }
133
134   /* New Module missing */
135   int plugin_id = find_model_description(surf_plugin_description, val);
136   surf_plugin_description[plugin_id].model_init_preparse();
137 }
138
139 /* callback of the host/model variable */
140 static void _sg_cfg_cb__host_model(const char *name, int pos)
141 {
142   char *val;
143
144   xbt_assert(_sg_cfg_init_status < 2,
145               "Cannot change the model after the initialization");
146
147   val = xbt_cfg_get_string(_sg_cfg_set, name);
148
149   if (!strcmp(val, "help")) {
150     model_help("host", surf_host_model_description);
151     sg_cfg_exit_early();
152   }
153
154   /* Make sure that the model exists */
155   find_model_description(surf_host_model_description, val);
156 }
157
158 /* callback of the vm/model variable */
159 static void _sg_cfg_cb__vm_model(const char *name, int pos)
160 {
161   char *val;
162
163   xbt_assert(_sg_cfg_init_status < 2,
164               "Cannot change the model after the initialization");
165
166   val = xbt_cfg_get_string(_sg_cfg_set, name);
167
168   if (!strcmp(val, "help")) {
169     model_help("vm", surf_vm_model_description);
170     sg_cfg_exit_early();
171   }
172
173   /* Make sure that the model exists */
174   find_model_description(surf_vm_model_description, val);
175 }
176
177 /* callback of the cpu/model variable */
178 static void _sg_cfg_cb__cpu_model(const char *name, int pos)
179 {
180   char *val;
181
182   xbt_assert(_sg_cfg_init_status < 2,
183               "Cannot change the model after the initialization");
184
185   val = xbt_cfg_get_string(_sg_cfg_set, name);
186
187   if (!strcmp(val, "help")) {
188     model_help("CPU", surf_cpu_model_description);
189     sg_cfg_exit_early();
190   }
191
192   /* New Module missing */
193   find_model_description(surf_cpu_model_description, val);
194 }
195
196 /* callback of the cpu/model variable */
197 static void _sg_cfg_cb__optimization_mode(const char *name, int pos)
198 {
199   char *val;
200
201   xbt_assert(_sg_cfg_init_status < 2,
202               "Cannot change the model after the initialization");
203
204   val = xbt_cfg_get_string(_sg_cfg_set, name);
205
206   if (!strcmp(val, "help")) {
207     model_help("optimization", surf_optimization_mode_description);
208     sg_cfg_exit_early();
209   }
210
211   /* New Module missing */
212   find_model_description(surf_optimization_mode_description, val);
213 }
214
215 /* callback of the cpu/model variable */
216 static void _sg_cfg_cb__storage_mode(const char *name, int pos)
217 {
218   char *val;
219
220   xbt_assert(_sg_cfg_init_status < 2,
221               "Cannot change the model after the initialization");
222
223   val = xbt_cfg_get_string(_sg_cfg_set, name);
224
225   if (!strcmp(val, "help")) {
226     model_help("storage", surf_storage_model_description);
227     sg_cfg_exit_early();
228   }
229
230   /* New Module missing */
231   find_model_description(surf_storage_model_description, val);
232 }
233
234 /* callback of the network_model variable */
235 static void _sg_cfg_cb__network_model(const char *name, int pos)
236 {
237   char *val;
238
239   xbt_assert(_sg_cfg_init_status < 2,
240               "Cannot change the model after the initialization");
241
242   val = xbt_cfg_get_string(_sg_cfg_set, name);
243
244   if (!strcmp(val, "help")) {
245     model_help("network", surf_network_model_description);
246     sg_cfg_exit_early();
247   }
248
249   /* New Module missing */
250   find_model_description(surf_network_model_description, val);
251 }
252
253 /* callbacks of the network models values */
254 static void _sg_cfg_cb__tcp_gamma(const char *name, int pos)
255 {
256   sg_tcp_gamma = xbt_cfg_get_double(_sg_cfg_set, name);
257 }
258
259 static void _sg_cfg_cb__maxmin_precision(const char* name, int pos)
260 {
261   sg_maxmin_precision = xbt_cfg_get_double(_sg_cfg_set, name);
262 }
263
264 static void _sg_cfg_cb__surf_precision(const char* name, int pos)
265 {
266   sg_surf_precision = xbt_cfg_get_double(_sg_cfg_set, name);
267 }
268
269 static void _sg_cfg_cb__sender_gap(const char* name, int pos)
270 {
271   sg_sender_gap = xbt_cfg_get_double(_sg_cfg_set, name);
272 }
273
274 static void _sg_cfg_cb__latency_factor(const char *name, int pos)
275 {
276   sg_latency_factor = xbt_cfg_get_double(_sg_cfg_set, name);
277 }
278
279 static void _sg_cfg_cb__bandwidth_factor(const char *name, int pos)
280 {
281   sg_bandwidth_factor = xbt_cfg_get_double(_sg_cfg_set, name);
282 }
283
284 static void _sg_cfg_cb__weight_S(const char *name, int pos)
285 {
286   sg_weight_S_parameter = xbt_cfg_get_double(_sg_cfg_set, name);
287 }
288
289 #ifdef HAVE_SMPI
290 /* callback of the mpi collectives */
291 static void _sg_cfg_cb__coll(const char *category,
292                              s_mpi_coll_description_t * table,
293                              const char *name, int pos)
294 {
295   char *val;
296
297   xbt_assert(_sg_cfg_init_status < 2,
298               "Cannot change the model after the initialization");
299
300   val = xbt_cfg_get_string(_sg_cfg_set, name);
301
302   if (!strcmp(val, "help")) {
303     coll_help(category, table);
304     sg_cfg_exit_early();
305   }
306
307   /* New Module missing */
308   find_coll_description(table, val, category);
309 }
310 static void _sg_cfg_cb__coll_gather(const char *name, int pos){
311   _sg_cfg_cb__coll("gather", mpi_coll_gather_description, name, pos);
312 }
313 static void _sg_cfg_cb__coll_allgather(const char *name, int pos){
314   _sg_cfg_cb__coll("allgather", mpi_coll_allgather_description, name, pos);
315 }
316 static void _sg_cfg_cb__coll_allgatherv(const char *name, int pos){
317   _sg_cfg_cb__coll("allgatherv", mpi_coll_allgatherv_description, name, pos);
318 }
319 static void _sg_cfg_cb__coll_allreduce(const char *name, int pos)
320 {
321   _sg_cfg_cb__coll("allreduce", mpi_coll_allreduce_description, name, pos);
322 }
323 static void _sg_cfg_cb__coll_alltoall(const char *name, int pos)
324 {
325   _sg_cfg_cb__coll("alltoall", mpi_coll_alltoall_description, name, pos);
326 }
327 static void _sg_cfg_cb__coll_alltoallv(const char *name, int pos)
328 {
329   _sg_cfg_cb__coll("alltoallv", mpi_coll_alltoallv_description, name, pos);
330 }
331 static void _sg_cfg_cb__coll_bcast(const char *name, int pos)
332 {
333   _sg_cfg_cb__coll("bcast", mpi_coll_bcast_description, name, pos);
334 }
335 static void _sg_cfg_cb__coll_reduce(const char *name, int pos)
336 {
337   _sg_cfg_cb__coll("reduce", mpi_coll_reduce_description, name, pos);
338 }
339 static void _sg_cfg_cb__coll_reduce_scatter(const char *name, int pos){
340   _sg_cfg_cb__coll("reduce_scatter", mpi_coll_reduce_scatter_description, name, pos);
341 }
342 static void _sg_cfg_cb__coll_scatter(const char *name, int pos){
343   _sg_cfg_cb__coll("scatter", mpi_coll_scatter_description, name, pos);
344 }
345 static void _sg_cfg_cb__coll_barrier(const char *name, int pos){
346   _sg_cfg_cb__coll("barrier", mpi_coll_barrier_description, name, pos);
347 }
348
349 static void _sg_cfg_cb__wtime_sleep(const char *name, int pos){
350   smpi_wtime_sleep = xbt_cfg_get_double(_sg_cfg_set, name);
351 }
352
353 static void _sg_cfg_cb__iprobe_sleep(const char *name, int pos){
354   smpi_iprobe_sleep = xbt_cfg_get_double(_sg_cfg_set, name);
355 }
356
357 static void _sg_cfg_cb__test_sleep(const char *name, int pos){
358   smpi_test_sleep = xbt_cfg_get_double(_sg_cfg_set, name);
359 }
360
361
362
363 #endif
364
365 /* callback of the inclusion path */
366 static void _sg_cfg_cb__surf_path(const char *name, int pos)
367 {
368   char *path = xbt_strdup(xbt_cfg_get_string_at(_sg_cfg_set, name, pos));
369   xbt_dynar_push(surf_path, &path);
370 }
371
372 /* callback to decide if we want to use the model-checking */
373 #include "src/xbt_modinter.h"
374
375 #ifdef HAVE_MC
376 extern int _sg_do_model_check;   /* this variable lives in xbt_main until I find a right location for it */
377 extern int _sg_do_model_check_record;
378 #endif
379
380 static void _sg_cfg_cb_model_check_replay(const char *name, int pos) {
381   MC_record_path = xbt_cfg_get_string(_sg_cfg_set, name);
382 }
383
384 #ifdef HAVE_MC
385 static void _sg_cfg_cb_model_check_record(const char *name, int pos) {
386   _sg_do_model_check_record = xbt_cfg_get_boolean(_sg_cfg_set, name);
387 }
388 #endif
389
390 extern int _sg_do_verbose_exit;
391
392 static void _sg_cfg_cb_verbose_exit(const char *name, int pos)
393 {
394   _sg_do_verbose_exit = xbt_cfg_get_boolean(_sg_cfg_set, name);
395 }
396
397 extern int _sg_do_clean_atexit;
398
399 static void _sg_cfg_cb_clean_atexit(const char *name, int pos)
400 {
401   _sg_do_clean_atexit = xbt_cfg_get_boolean(_sg_cfg_set, name);
402 }
403
404 static void _sg_cfg_cb_context_factory(const char *name, int pos)
405 {
406   smx_context_factory_name = xbt_cfg_get_string(_sg_cfg_set, name);
407 }
408
409 static void _sg_cfg_cb_context_stack_size(const char *name, int pos)
410 {
411   smx_context_stack_size_was_set = 1;
412   smx_context_stack_size = xbt_cfg_get_int(_sg_cfg_set, name) * 1024;
413 }
414
415 static void _sg_cfg_cb_context_guard_size(const char *name, int pos)
416 {
417   smx_context_guard_size_was_set = 1;
418   smx_context_guard_size = xbt_cfg_get_int(_sg_cfg_set, name) * xbt_pagesize;
419 }
420
421 static void _sg_cfg_cb_contexts_nthreads(const char *name, int pos)
422 {
423   SIMIX_context_set_nthreads(xbt_cfg_get_int(_sg_cfg_set, name));
424 }
425
426 static void _sg_cfg_cb_contexts_parallel_threshold(const char *name, int pos)
427 {
428   SIMIX_context_set_parallel_threshold(xbt_cfg_get_int(_sg_cfg_set, name));
429 }
430
431 static void _sg_cfg_cb_contexts_parallel_mode(const char *name, int pos)
432 {
433   const char* mode_name = xbt_cfg_get_string(_sg_cfg_set, name);
434   if (!strcmp(mode_name, "posix")) {
435     SIMIX_context_set_parallel_mode(XBT_PARMAP_POSIX);
436   }
437   else if (!strcmp(mode_name, "futex")) {
438     SIMIX_context_set_parallel_mode(XBT_PARMAP_FUTEX);
439   }
440   else if (!strcmp(mode_name, "busy_wait")) {
441     SIMIX_context_set_parallel_mode(XBT_PARMAP_BUSY_WAIT);
442   }
443   else {
444     xbt_die("Command line setting of the parallel synchronization mode should "
445             "be one of \"posix\", \"futex\" or \"busy_wait\"");
446   }
447 }
448
449 static void _sg_cfg_cb__surf_network_coordinates(const char *name,
450                                                  int pos)
451 {
452   static int already_set = 0;
453   int val = xbt_cfg_get_boolean(_sg_cfg_set, name);
454   if (val) {
455     if (!already_set) {
456       COORD_HOST_LEVEL = sg_host_extension_create(xbt_dynar_free_voidp);
457       COORD_ASR_LEVEL  = xbt_lib_add_level(as_router_lib,xbt_dynar_free_voidp);
458     }
459     already_set = 1;
460   } else
461     if (already_set)
462       xbt_die("Setting of whether to use coordinate cannot be disabled once set.");
463 }
464
465 static void _sg_cfg_cb__surf_network_crosstraffic(const char *name,
466                                                   int pos)
467 {
468   sg_network_crosstraffic = xbt_cfg_get_boolean(_sg_cfg_set, name);
469 }
470
471 /* build description line with possible values */
472 static void describe_model(char *result,
473                            const s_surf_model_description_t model_description[],
474                            const char *name,
475                            const char *description)
476 {
477   char *p = result +
478     sprintf(result, "%s. Possible values: %s", description,
479             model_description[0].name ? model_description[0].name : "n/a");
480   int i;
481   for (i = 1; model_description[i].name; i++)
482     p += sprintf(p, ", %s", model_description[i].name);
483   sprintf(p,
484       ".\n       (use 'help' as a value to see the long description of each %s)",
485           name);
486 }
487
488 /* create the config set, register what should be and parse the command line*/
489 void sg_config_init(int *argc, char **argv)
490 {
491   char description[1024];
492
493   /* Create the configuration support */
494   if (_sg_cfg_init_status == 0) { /* Only create stuff if not already inited */
495
496     /* Plugins configuration */
497     describe_model(description, surf_plugin_description,
498                    "plugin", "The plugins");
499     xbt_cfg_register(&_sg_cfg_set, "plugin", description,
500                      xbt_cfgelm_string, 0, 1, &_sg_cfg_cb__plugin);
501
502     describe_model(description, surf_cpu_model_description, "model", "The model to use for the CPU");
503     xbt_cfg_register(&_sg_cfg_set, "cpu/model", description, xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__cpu_model);
504     xbt_cfg_setdefault_string(_sg_cfg_set, "cpu/model", "Cas01");
505
506     describe_model(description, surf_optimization_mode_description, "optimization mode", "The optimization modes to use for the CPU");
507     xbt_cfg_register(&_sg_cfg_set, "cpu/optim", description, xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__optimization_mode);
508     xbt_cfg_setdefault_string(_sg_cfg_set, "cpu/optim", "Lazy");
509
510     describe_model(description, surf_storage_model_description, "model", "The model to use for the storage");
511     xbt_cfg_register(&_sg_cfg_set, "storage/model", description, xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__storage_mode);
512     xbt_cfg_setdefault_string(_sg_cfg_set, "storage/model", "default");
513
514     describe_model(description, surf_network_model_description, "model", "The model to use for the network");
515     xbt_cfg_register(&_sg_cfg_set, "network/model", description, xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__network_model);
516     xbt_cfg_setdefault_string(_sg_cfg_set, "network/model", "LV08");
517
518     describe_model(description, surf_optimization_mode_description, "optimization mode", "The optimization modes to use for the network");
519     xbt_cfg_register(&_sg_cfg_set, "network/optim", description, xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__optimization_mode);
520     xbt_cfg_setdefault_string(_sg_cfg_set, "network/optim", "Lazy");
521
522     describe_model(description, surf_host_model_description, "model", "The model to use for the host");
523     xbt_cfg_register(&_sg_cfg_set, "host/model", description, xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__host_model);
524     xbt_cfg_setdefault_string(_sg_cfg_set, "host/model", "default");
525
526     describe_model(description, surf_vm_model_description, "model", "The model to use for the vm");
527     xbt_cfg_register(&_sg_cfg_set, "vm/model", description, xbt_cfgelm_string, 1, 1, &_sg_cfg_cb__vm_model);
528     xbt_cfg_setdefault_string(_sg_cfg_set, "vm/model", "default");
529
530     xbt_cfg_register(&_sg_cfg_set, "network/TCP_gamma",
531                      "Size of the biggest TCP window (cat /proc/sys/net/ipv4/tcp_[rw]mem for recv/send window; Use the last given value, which is the max window size)",
532                      xbt_cfgelm_double, 1, 1, _sg_cfg_cb__tcp_gamma);
533     xbt_cfg_setdefault_double(_sg_cfg_set, "network/TCP_gamma", 4194304.0);
534
535     xbt_cfg_register(&_sg_cfg_set, "surf/precision", "Numerical precision used when updating simulation times (in seconds)",
536                      xbt_cfgelm_double, 1, 1, _sg_cfg_cb__surf_precision);
537     xbt_cfg_setdefault_double(_sg_cfg_set, "surf/precision", 0.00001);
538
539     xbt_cfg_register(&_sg_cfg_set, "maxmin/precision",
540                      "Numerical precision used when computing resource sharing (in ops/sec or bytes/sec)",
541                      xbt_cfgelm_double, 1, 1, _sg_cfg_cb__maxmin_precision);
542     xbt_cfg_setdefault_double(_sg_cfg_set, "maxmin/precision", 0.00001);
543
544     /* The parameters of network models */
545
546     xbt_cfg_register(&_sg_cfg_set, "network/sender_gap", "Minimum gap between two overlapping sends",
547         xbt_cfgelm_double, 1, 1, _sg_cfg_cb__sender_gap);
548     /* real default for "network/sender_gap" is set in network_smpi.cpp */
549     xbt_cfg_setdefault_double(_sg_cfg_set, "network/sender_gap", NAN);
550
551     xbt_cfg_register(&_sg_cfg_set, "network/latency_factor",
552                      "Correction factor to apply to the provided latency (default value set by network model)",
553                      xbt_cfgelm_double, 1, 1, _sg_cfg_cb__latency_factor);
554     xbt_cfg_setdefault_double(_sg_cfg_set, "network/latency_factor", 1.0);
555
556     xbt_cfg_register(&_sg_cfg_set, "network/bandwidth_factor",
557                      "Correction factor to apply to the provided bandwidth (default value set by network model)",
558                      xbt_cfgelm_double, 1, 1, _sg_cfg_cb__bandwidth_factor);
559     xbt_cfg_setdefault_double(_sg_cfg_set, "network/bandwidth_factor", 1.0);
560
561     xbt_cfg_register(&_sg_cfg_set, "network/weight_S",
562                      "Correction factor to apply to the weight of competing streams (default value set by network model)",
563                      xbt_cfgelm_double, 1, 1, _sg_cfg_cb__weight_S);
564     /* real default for "network/weight_S" is set in network_*.cpp */
565     xbt_cfg_setdefault_double(_sg_cfg_set, "network/weight_S", NAN);
566
567     /* Inclusion path */
568     xbt_cfg_register(&_sg_cfg_set, "path",
569                      "Lookup path for inclusions in platform and deployment XML files",
570                      xbt_cfgelm_string, 1, 0, _sg_cfg_cb__surf_path);
571
572     xbt_cfg_register(&_sg_cfg_set, "cpu/maxmin_selective_update",
573                      "Update the constraint set propagating recursively to others constraints (off by default when optim is set to lazy)",
574                      xbt_cfgelm_boolean, 1, 1, NULL);
575     xbt_cfg_setdefault_boolean(_sg_cfg_set, "cpu/maxmin_selective_update", "no");
576
577     xbt_cfg_register(&_sg_cfg_set, "network/maxmin_selective_update",
578                      "Update the constraint set propagating recursively to others constraints (off by default when optim is set to lazy)",
579                      xbt_cfgelm_boolean, 1, 1, NULL);
580     xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/maxmin_selective_update", "no");
581
582     /* Replay (this part is enabled even if MC it disabled) */
583     xbt_cfg_register(&_sg_cfg_set, "model-check/replay",
584       "Enable replay mode with the given path", xbt_cfgelm_string, 0, 1, _sg_cfg_cb_model_check_replay);
585
586 #ifdef HAVE_MC
587     /* do model-checking-record */
588     xbt_cfg_register(&_sg_cfg_set, "model-check/record",
589                      "Record the model-checking paths",
590                      xbt_cfgelm_boolean, 1, 1, _sg_cfg_cb_model_check_record);
591     xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check/record", "no");
592
593     /* do stateful model-checking */
594     xbt_cfg_register(&_sg_cfg_set, "model-check/checkpoint",
595                      "Specify the amount of steps between checkpoints during stateful model-checking (default: 0 => stateless verification). "
596                      "If value=1, one checkpoint is saved for each step => faster verification, but huge memory consumption; higher values are good compromises between speed and memory consumption.",
597                      xbt_cfgelm_int, 1, 1, _mc_cfg_cb_checkpoint);
598     xbt_cfg_setdefault_int(_sg_cfg_set, "model-check/checkpoint", 0);
599
600     /* do stateful model-checking */
601     xbt_cfg_register(&_sg_cfg_set, "model-check/sparse_checkpoint",
602                      "Use sparse per-page snapshots.",
603                      xbt_cfgelm_boolean, 1, 1, _mc_cfg_cb_sparse_checkpoint);
604     xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check/sparse_checkpoint", "no");
605
606     /* do stateful model-checking */
607     xbt_cfg_register(&_sg_cfg_set, "model-check/soft-dirty",
608                      "Use sparse per-page snapshots.",
609                      xbt_cfgelm_boolean, 1, 1, _mc_cfg_cb_soft_dirty);
610     xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check/soft-dirty", "no");
611
612     xbt_cfg_register(&_sg_cfg_set, "model-check/ksm",
613                      "Kernel same-page merging",
614                      xbt_cfgelm_boolean, 1, 1, _mc_cfg_cb_ksm);
615     xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check/ksm", "no");
616
617     /* do liveness model-checking */
618     xbt_cfg_register(&_sg_cfg_set, "model-check/property",
619                      "Specify the name of the file containing the property. It must be the result of the ltl2ba program.",
620                      xbt_cfgelm_string, 1, 1, _mc_cfg_cb_property);
621     xbt_cfg_setdefault_string(_sg_cfg_set, "model-check/property", "");
622
623     /* do communications determinism model-checking */
624     xbt_cfg_register(&_sg_cfg_set, "model-check/communications_determinism",
625                      "Enable/disable the detection of determinism in the communications schemes",
626                      xbt_cfgelm_boolean, 1, 1, _mc_cfg_cb_comms_determinism);
627     xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check/communications_determinism", "no");
628
629     /* do send determinism model-checking */
630     xbt_cfg_register(&_sg_cfg_set, "model-check/send_determinism",
631                      "Enable/disable the detection of send-determinism in the communications schemes",
632                      xbt_cfgelm_boolean, 1, 1, _mc_cfg_cb_send_determinism);
633     xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check/send_determinism", "no");
634
635     /* Specify the kind of model-checking reduction */
636     xbt_cfg_register(&_sg_cfg_set, "model-check/reduction",
637                      "Specify the kind of exploration reduction (either none or DPOR)",
638                      xbt_cfgelm_string, 1, 1, _mc_cfg_cb_reduce);
639     xbt_cfg_setdefault_string(_sg_cfg_set, "model-check/reduction", "dpor");
640
641     /* Enable/disable timeout for wait requests with model-checking */
642     xbt_cfg_register(&_sg_cfg_set, "model-check/timeout",
643                      "Enable/Disable timeout for wait requests",
644                      xbt_cfgelm_boolean, 1, 1, _mc_cfg_cb_timeout);
645     xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check/timeout", "no");
646
647     /* Enable/disable global hash computation with model-checking */
648     xbt_cfg_register(&_sg_cfg_set, "model-check/hash",
649                      "Enable/Disable state hash for state comparison (experimental)",
650                      xbt_cfgelm_boolean, 1, 1, _mc_cfg_cb_hash);
651     xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check/hash", "no");
652
653     /* Set max depth exploration */
654     /* Currently, this option cannot be used. */
655     xbt_cfg_register(&_sg_cfg_set, "model-check/snapshot_fds",
656                      "Whether file descriptors must be snapshoted",
657                      xbt_cfgelm_boolean, 1, 1, _mc_cfg_cb_snapshot_fds);
658     xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check/snapshot_fds", "no");
659
660     /* Set max depth exploration */
661     xbt_cfg_register(&_sg_cfg_set, "model-check/max_depth",
662                      "Specify the max depth of exploration (default : 1000)",
663                      xbt_cfgelm_int, 1, 1, _mc_cfg_cb_max_depth);
664     xbt_cfg_setdefault_int(_sg_cfg_set, "model-check/max_depth", 1000);
665
666     /* Set number of visited state stored for state comparison reduction*/
667     xbt_cfg_register(&_sg_cfg_set, "model-check/visited",
668                      "Specify the number of visited state stored for state comparison reduction. If value=5, the last 5 visited states are stored",
669                      xbt_cfgelm_int, 1, 1, _mc_cfg_cb_visited);
670     xbt_cfg_setdefault_int(_sg_cfg_set, "model-check/visited", 0);
671
672     /* Set file name for dot output of graph state */
673     xbt_cfg_register(&_sg_cfg_set, "model-check/dot_output",
674                      "Specify the name of dot file corresponding to graph state",
675                      xbt_cfgelm_string, 1, 1, _mc_cfg_cb_dot_output);
676     xbt_cfg_setdefault_string(_sg_cfg_set, "model-check/dot_output", "");
677
678      /* Enable/disable non progressive cycles detection with model-checking */
679     xbt_cfg_register(&_sg_cfg_set, "model-check/termination",
680                      "Enable/Disable non progressive cycle detection",
681                      xbt_cfgelm_boolean, 1, 1, _mc_cfg_cb_termination);
682     xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check/termination", "no");
683 #endif
684
685     /* do verbose-exit */
686     xbt_cfg_register(&_sg_cfg_set, "verbose-exit",
687                      "Activate the \"do nothing\" mode in Ctrl-C",
688                      xbt_cfgelm_boolean, 1, 1, _sg_cfg_cb_verbose_exit);
689     xbt_cfg_setdefault_boolean(_sg_cfg_set, "verbose-exit", "yes");
690
691     /* context factory */
692     const char *dflt_ctx_fact = "thread";
693     {
694       char *p = description +
695         sprintf(description,
696                 "Context factory to use in SIMIX. Possible values: %s",
697                 dflt_ctx_fact);
698 #ifdef HAVE_UCONTEXT_CONTEXTS
699       dflt_ctx_fact = "ucontext";
700       p += sprintf(p, ", %s", dflt_ctx_fact);
701 #endif
702 #ifdef HAVE_RAW_CONTEXTS
703       dflt_ctx_fact = "raw";
704       p += sprintf(p, ", %s", dflt_ctx_fact);
705 #endif
706       sprintf(p, ".");
707     }
708     xbt_cfg_register(&_sg_cfg_set, "contexts/factory", description,
709                      xbt_cfgelm_string, 1, 1, _sg_cfg_cb_context_factory);
710     xbt_cfg_setdefault_string(_sg_cfg_set, "contexts/factory", dflt_ctx_fact);
711
712     /* stack size of contexts in KiB */
713     xbt_cfg_register(&_sg_cfg_set, "contexts/stack_size",
714                      "Stack size of contexts in KiB",
715                      xbt_cfgelm_int, 1, 1, _sg_cfg_cb_context_stack_size);
716     xbt_cfg_setdefault_int(_sg_cfg_set, "contexts/stack_size", 8*1024);
717     /* No, it was not set yet (the above setdefault() changed this to 1). */
718     smx_context_stack_size_was_set = 0;
719
720     /* guard size for contexts stacks in memory pages */
721     xbt_cfg_register(&_sg_cfg_set, "contexts/guard_size",
722                      "Guard size for contexts stacks in memory pages",
723                      xbt_cfgelm_int, 1, 1, _sg_cfg_cb_context_guard_size);
724 #if defined(_XBT_WIN32) || (PTH_STACKGROWTH != -1)
725     xbt_cfg_setdefault_int(_sg_cfg_set, "contexts/guard_size", 0);
726 #else
727     xbt_cfg_setdefault_int(_sg_cfg_set, "contexts/guard_size", 1);
728 #endif
729     /* No, it was not set yet (the above setdefault() changed this to 1). */
730     smx_context_guard_size_was_set = 0;
731
732     /* number of parallel threads for user processes */
733     xbt_cfg_register(&_sg_cfg_set, "contexts/nthreads",
734                      "Number of parallel threads used to execute user contexts",
735                      xbt_cfgelm_int, 1, 1, _sg_cfg_cb_contexts_nthreads);
736     xbt_cfg_setdefault_int(_sg_cfg_set, "contexts/nthreads", 1);
737
738     /* minimal number of user contexts to be run in parallel */
739     xbt_cfg_register(&_sg_cfg_set, "contexts/parallel_threshold",
740                      "Minimal number of user contexts to be run in parallel (raw contexts only)",
741                      xbt_cfgelm_int, 1, 1, _sg_cfg_cb_contexts_parallel_threshold);
742     xbt_cfg_setdefault_int(_sg_cfg_set, "contexts/parallel_threshold", 2);
743
744     /* synchronization mode for parallel user contexts */
745     xbt_cfg_register(&_sg_cfg_set, "contexts/synchro",
746                      "Synchronization mode to use when running contexts in parallel (either futex, posix or busy_wait)",
747                      xbt_cfgelm_string, 1, 1, _sg_cfg_cb_contexts_parallel_mode);
748 #ifdef HAVE_FUTEX_H
749     xbt_cfg_setdefault_string(_sg_cfg_set, "contexts/synchro", "futex");
750 #else //No futex on mac and posix is unimplememted yet
751     xbt_cfg_setdefault_string(_sg_cfg_set, "contexts/synchro", "busy_wait");
752 #endif
753
754     xbt_cfg_register(&_sg_cfg_set, "network/coordinates",
755                      "\"yes\" or \"no\", specifying whether we use a coordinate-based routing (as Vivaldi)",
756                      xbt_cfgelm_boolean, 1, 1, _sg_cfg_cb__surf_network_coordinates);
757     xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/coordinates", "no");
758
759     xbt_cfg_register(&_sg_cfg_set, "network/crosstraffic",
760                      "Activate the interferences between uploads and downloads for fluid max-min models (LV08, CM02)",
761                      xbt_cfgelm_boolean, 1, 1, _sg_cfg_cb__surf_network_crosstraffic);
762     xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/crosstraffic", "no");
763
764 #ifdef HAVE_NS3
765     xbt_cfg_register(&_sg_cfg_set, "ns3/TcpModel",
766                      "The ns3 tcp model can be : NewReno or Reno or Tahoe",
767                      xbt_cfgelm_string, 1, 1, NULL);
768     xbt_cfg_setdefault_string(_sg_cfg_set, "ns3/TcpModel", "default");
769 #endif
770
771     //For smpi/bw_factor and smpi/lat_factor
772     //Default value have to be "threshold0:value0;threshold1:value1;...;thresholdN:valueN"
773     //test is if( size >= thresholdN ) return valueN;
774     //Values can be modified with command line --cfg=smpi/bw_factor:"threshold0:value0;threshold1:value1;...;thresholdN:valueN"
775     //  or with tag config put line <prop id="smpi/bw_factor" value="threshold0:value0;threshold1:value1;...;thresholdN:valueN"></prop>
776     // SMPI model can be used without enable_smpi, so keep this out of the ifdef.
777     xbt_cfg_register(&_sg_cfg_set, "smpi/bw_factor",
778                      "Bandwidth factors for smpi.",
779                      xbt_cfgelm_string, 1, 1, NULL);
780     xbt_cfg_setdefault_string(_sg_cfg_set, "smpi/bw_factor", "65472:0.940694;15424:0.697866;9376:0.58729;5776:1.08739;3484:0.77493;1426:0.608902;732:0.341987;257:0.338112;0:0.812084");
781
782     xbt_cfg_register(&_sg_cfg_set, "smpi/lat_factor",
783                      "Latency factors for smpi.",
784                      xbt_cfgelm_string, 1, 1, NULL);
785     xbt_cfg_setdefault_string(_sg_cfg_set, "smpi/lat_factor", "65472:11.6436;15424:3.48845;9376:2.59299;5776:2.18796;3484:1.88101;1426:1.61075;732:1.9503;257:1.95341;0:2.01467");
786     
787     xbt_cfg_register(&_sg_cfg_set, "smpi/IB_penalty_factors",
788                      "Correction factor to communications using Infiniband model with contention (default value based on Stampede cluster profiling)",
789                      xbt_cfgelm_string, 1, 1, NULL);
790     xbt_cfg_setdefault_string(_sg_cfg_set, "smpi/IB_penalty_factors", "0.965;0.925;1.35");
791     
792 #ifdef HAVE_SMPI
793     xbt_cfg_register(&_sg_cfg_set, "smpi/running_power",
794                      "Power of the host running the simulation (in flop/s). Used to bench the operations.",
795                      xbt_cfgelm_double, 1, 1, NULL);
796     xbt_cfg_setdefault_double(_sg_cfg_set, "smpi/running_power", 20000.0);
797
798     xbt_cfg_register(&_sg_cfg_set, "smpi/display_timing",
799                      "Boolean indicating whether we should display the timing after simulation.",
800                      xbt_cfgelm_boolean, 1, 1, NULL);
801     xbt_cfg_setdefault_boolean(_sg_cfg_set, "smpi/display_timing", "no");
802
803     xbt_cfg_register(&_sg_cfg_set, "smpi/simulate_computation",
804                      "Boolean indicating whether the computational part of the simulated application should be simulated.",
805                      xbt_cfgelm_boolean, 1, 1, NULL);
806     xbt_cfg_setdefault_boolean(_sg_cfg_set, "smpi/simulate_computation", "yes");
807
808     xbt_cfg_register(&_sg_cfg_set, "smpi/use_shared_malloc",
809                      "Boolean indicating whether we should use shared memory when using SMPI_SHARED_MALLOC. Allows user to disable it for debug purposes.",
810                      xbt_cfgelm_boolean, 1, 1, NULL);
811     xbt_cfg_setdefault_boolean(_sg_cfg_set, "smpi/use_shared_malloc", "yes");
812
813     xbt_cfg_register(&_sg_cfg_set, "smpi/cpu_threshold",
814                      "Minimal computation time (in seconds) not discarded, or -1 for infinity.",
815                      xbt_cfgelm_double, 1, 1, NULL);
816     xbt_cfg_setdefault_double(_sg_cfg_set, "smpi/cpu_threshold", 1e-6);
817
818     xbt_cfg_register(&_sg_cfg_set, "smpi/async_small_thresh",
819                      "Maximal size of messages that are to be sent asynchronously, without waiting for the receiver",
820                      xbt_cfgelm_int, 1, 1, NULL);
821     xbt_cfg_setdefault_int(_sg_cfg_set, "smpi/async_small_thresh", 0);
822
823     xbt_cfg_register(&_sg_cfg_set, "smpi/send_is_detached_thresh",
824                      "Threshold of message size where MPI_Send stops behaving like MPI_Isend and becomes MPI_Ssend",
825                      xbt_cfgelm_int, 1, 1, NULL);
826     xbt_cfg_setdefault_int(_sg_cfg_set, "smpi/send_is_detached_thresh", 65536);
827
828     xbt_cfg_register(&_sg_cfg_set, "smpi/privatize_global_variables",
829                      "Boolean indicating whether we should privatize global variable at runtime.",
830                      xbt_cfgelm_boolean, 1, 1, NULL);
831     xbt_cfg_setdefault_boolean(_sg_cfg_set, "smpi/privatize_global_variables", "no");
832
833     xbt_cfg_register(&_sg_cfg_set, "smpi/os",
834                      "Small messages timings (MPI_Send minimum time for small messages)",
835                      xbt_cfgelm_string, 1, 1, NULL);
836     xbt_cfg_setdefault_string(_sg_cfg_set, "smpi/os", "1:0:0:0:0");
837
838     xbt_cfg_register(&_sg_cfg_set, "smpi/ois",
839                      "Small messages timings (MPI_Isend minimum time for small messages)",
840                      xbt_cfgelm_string, 1, 1, NULL);
841     xbt_cfg_setdefault_string(_sg_cfg_set, "smpi/ois", "1:0:0:0:0");
842
843     xbt_cfg_register(&_sg_cfg_set, "smpi/or",
844                      "Small messages timings (MPI_Recv minimum time for small messages)",
845                      xbt_cfgelm_string, 1, 1, NULL);
846     xbt_cfg_setdefault_string(_sg_cfg_set, "smpi/or", "1:0:0:0:0");
847
848     xbt_cfg_register(&_sg_cfg_set, "smpi/iprobe",
849                      "Minimum time to inject inside a call to MPI_Iprobe",
850                      xbt_cfgelm_double, 1, 1, _sg_cfg_cb__iprobe_sleep);
851     xbt_cfg_setdefault_double(_sg_cfg_set, "smpi/iprobe", 1e-4);
852
853     xbt_cfg_register(&_sg_cfg_set, "smpi/test",
854                      "Minimum time to inject inside a call to MPI_Test",
855                      xbt_cfgelm_double, 1, 1, _sg_cfg_cb__test_sleep);
856     xbt_cfg_setdefault_double(_sg_cfg_set, "smpi/test", 1e-4);
857
858     xbt_cfg_register(&_sg_cfg_set, "smpi/wtime",
859                      "Minimum time to inject inside a call to MPI_Wtime",
860                      xbt_cfgelm_double, 1, 1, _sg_cfg_cb__wtime_sleep);
861     xbt_cfg_setdefault_double(_sg_cfg_set, "smpi/wtime", 0.0);
862
863     xbt_cfg_register(&_sg_cfg_set, "smpi/coll_selector",
864                      "Which collective selector to use",
865                      xbt_cfgelm_string, 1, 1, NULL);
866     xbt_cfg_setdefault_string(_sg_cfg_set, "smpi/coll_selector", "default");
867
868     xbt_cfg_register(&_sg_cfg_set, "smpi/gather",
869                      "Which collective to use for gather",
870                      xbt_cfgelm_string, 0, 1, &_sg_cfg_cb__coll_gather);
871
872     xbt_cfg_register(&_sg_cfg_set, "smpi/allgather",
873                      "Which collective to use for allgather",
874                      xbt_cfgelm_string, 0, 1, &_sg_cfg_cb__coll_allgather);
875
876     xbt_cfg_register(&_sg_cfg_set, "smpi/barrier",
877                      "Which collective to use for barrier",
878                      xbt_cfgelm_string, 0, 1, &_sg_cfg_cb__coll_barrier);
879
880     xbt_cfg_register(&_sg_cfg_set, "smpi/reduce_scatter",
881                      "Which collective to use for reduce_scatter",
882                      xbt_cfgelm_string, 0, 1, &_sg_cfg_cb__coll_reduce_scatter);
883
884     xbt_cfg_register(&_sg_cfg_set, "smpi/scatter",
885                      "Which collective to use for scatter",
886                      xbt_cfgelm_string, 0, 1, &_sg_cfg_cb__coll_scatter);
887
888     xbt_cfg_register(&_sg_cfg_set, "smpi/allgatherv",
889                      "Which collective to use for allgatherv",
890                      xbt_cfgelm_string, 0, 1, &_sg_cfg_cb__coll_allgatherv);
891
892     xbt_cfg_register(&_sg_cfg_set, "smpi/allreduce",
893                      "Which collective to use for allreduce",
894                      xbt_cfgelm_string, 0, 1, &_sg_cfg_cb__coll_allreduce);
895
896     xbt_cfg_register(&_sg_cfg_set, "smpi/alltoall",
897                      "Which collective to use for alltoall",
898                      xbt_cfgelm_string, 0, 1, &_sg_cfg_cb__coll_alltoall);
899
900     xbt_cfg_register(&_sg_cfg_set, "smpi/alltoallv",
901                      "Which collective to use for alltoallv",
902                      xbt_cfgelm_string, 0, 1, &_sg_cfg_cb__coll_alltoallv);
903
904     xbt_cfg_register(&_sg_cfg_set, "smpi/bcast",
905                      "Which collective to use for bcast",
906                      xbt_cfgelm_string, 0, 1, &_sg_cfg_cb__coll_bcast);
907
908     xbt_cfg_register(&_sg_cfg_set, "smpi/reduce",
909                      "Which collective to use for reduce",
910                      xbt_cfgelm_string, 0, 1, &_sg_cfg_cb__coll_reduce);
911 #endif // HAVE_SMPI
912
913     xbt_cfg_register(&_sg_cfg_set, "exception/cutpath",
914                      "\"yes\" or \"no\". \"yes\" will cut all path information from call traces, used e.g. in exceptions.",
915                      xbt_cfgelm_boolean, 1, 1, NULL);
916     xbt_cfg_setdefault_boolean(_sg_cfg_set, "exception/cutpath", "no");
917
918     xbt_cfg_register(&_sg_cfg_set, "clean_atexit",
919                      "\"yes\" or \"no\". \"yes\" enables all the cleanups of SimGrid (XBT,SIMIX,MSG) to be registered with atexit. \"no\" may be useful if your code segfaults when calling the exit function.",
920                      xbt_cfgelm_boolean, 1, 1, _sg_cfg_cb_clean_atexit);
921     xbt_cfg_setdefault_boolean(_sg_cfg_set, "clean_atexit", "yes");
922
923     if (!surf_path) {
924       /* retrieves the current directory of the current process */
925       const char *initial_path = __surf_get_initial_path();
926       xbt_assert((initial_path), "__surf_get_initial_path() failed! Can't resolve current Windows directory");
927
928       surf_path = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
929       xbt_cfg_setdefault_string(_sg_cfg_set, "path", initial_path);
930     }
931
932     xbt_cfg_check(_sg_cfg_set);
933     _sg_cfg_init_status = 1;
934
935     sg_config_cmd_line(argc, argv);
936
937     xbt_mallocator_initialization_is_done(SIMIX_context_is_parallel());
938   } else {
939     XBT_WARN("Call to sg_config_init() after initialization ignored");
940   }
941 }
942
943 void sg_config_finalize(void)
944 {
945   if (!_sg_cfg_init_status)
946     return;                     /* Not initialized yet. Nothing to do */
947
948   xbt_cfg_free(&_sg_cfg_set);
949   _sg_cfg_init_status = 0;
950 }
951
952 int sg_cfg_is_default_value(const char *name)
953 {
954   return xbt_cfg_is_default_value(_sg_cfg_set, name);
955 }
956
957 int sg_cfg_get_int(const char* name)
958 {
959   return xbt_cfg_get_int(_sg_cfg_set, name);
960 }
961
962 double sg_cfg_get_double(const char* name)
963 {
964   return xbt_cfg_get_double(_sg_cfg_set, name);
965 }
966
967 char* sg_cfg_get_string(const char* name)
968 {
969   return xbt_cfg_get_string(_sg_cfg_set, name);
970 }
971
972 int sg_cfg_get_boolean(const char* name)
973 {
974   return xbt_cfg_get_boolean(_sg_cfg_set, name);
975 }
976
977 xbt_dynar_t sg_cfg_get_dynar(const char* name)
978 {
979   return xbt_cfg_get_dynar(_sg_cfg_set, name);
980 }