Logo AND Algorithmique Numérique Distribuée

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