Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
model-checker : display malloc backtrace according to address
[simgrid.git] / src / surf / surf_config.c
1 /* Copyright (c) 2009, 2010. 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 /* surf_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/str.h"
13 #include "surf/surf_private.h"
14 #include "surf/surf_routing.h"  /* COORD_HOST_LEVEL and COORD_ASR_LEVEL */
15 #include "simgrid/simix.h"
16 #include "mc/mc.h" /* configuration callbacks of model-checking */
17
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf,
19                                 "About the configuration of surf (and the rest of the simulation)");
20
21 xbt_cfg_t _surf_cfg_set = NULL;
22
23 /* Parse the command line, looking for options */
24 static void surf_config_cmd_line(int *argc, char **argv)
25 {
26   int shall_exit = 0;
27   int i, j;
28   char *opt;
29
30   for (j = i = 1; i < *argc; i++) {
31     if (!strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
32       opt = strchr(argv[i], '=');
33       opt++;
34
35       xbt_cfg_set_parse(_surf_cfg_set, opt);
36       XBT_DEBUG("Did apply '%s' as config setting", opt);
37     } else if (!strcmp(argv[i], "--cfg-help") || !strcmp(argv[i], "--help")) {
38       printf
39           ("Description of the configuration accepted by this simulator:\n");
40       xbt_cfg_help(_surf_cfg_set);
41       printf(
42 "\n"
43 "Each of these configurations can be used by adding\n"
44 "    --cfg=<option name>:<option value>\n"
45 "to the command line.\n"
46 "You can also use --help-models to see the details of all models known by this simulator.\n"
47 #ifdef HAVE_TRACING
48 "\n"
49 "You can also use --help-tracing to see the details of all tracing options known by this simulator.\n"
50 #endif
51 "\n"
52 "You can also use --help-logs and --help-log-categories to see the details of logging output.\n"
53 "\n"
54         );
55       shall_exit = 1;
56     } else if (!strcmp(argv[i], "--help-models")) {
57       int k;
58
59       model_help("workstation", surf_workstation_model_description);
60       printf("\n");
61       model_help("CPU", surf_cpu_model_description);
62       printf("\n");
63       model_help("network", surf_network_model_description);
64       printf("\nLong description of all optimization levels accepted by the models of this simulator:\n");
65       for (k = 0; surf_optimization_mode_description[k].name; k++)
66         printf("  %s: %s\n",
67                surf_optimization_mode_description[k].name,
68                surf_optimization_mode_description[k].description);
69       printf("Both network and CPU models have 'Lazy' as default optimization level\n\n");
70       shall_exit = 1;
71 #ifdef HAVE_TRACING
72     } else if (!strcmp(argv[i], "--help-tracing")) {
73       TRACE_help (1);
74       shall_exit = 1;
75 #endif
76     } else {
77       argv[j++] = argv[i];
78     }
79   }
80   if (j < *argc) {
81     argv[j] = NULL;
82     *argc = j;
83   }
84   if (shall_exit)
85     exit(0);
86 }
87
88
89 int _surf_init_status = 0;      /* 0: beginning of time;
90                                    1: pre-inited (cfg_set created);
91                                    2: inited (running) */
92
93 /* callback of the workstation/model variable */
94 static void _surf_cfg_cb__workstation_model(const char *name, int pos)
95 {
96   char *val;
97
98   xbt_assert(_surf_init_status < 2,
99               "Cannot change the model after the initialization");
100
101   val = xbt_cfg_get_string(_surf_cfg_set, name);
102
103   if (!strcmp(val, "help")) {
104     model_help("workstation", surf_workstation_model_description);
105     exit(0);
106   }
107
108   /* Make sure that the model exists */
109   find_model_description(surf_workstation_model_description, val);
110 }
111
112 /* callback of the cpu/model variable */
113 static void _surf_cfg_cb__cpu_model(const char *name, int pos)
114 {
115   char *val;
116
117   xbt_assert(_surf_init_status < 2,
118               "Cannot change the model after the initialization");
119
120   val = xbt_cfg_get_string(_surf_cfg_set, name);
121
122   if (!strcmp(val, "help")) {
123     model_help("CPU", surf_cpu_model_description);
124     exit(0);
125   }
126
127   /* New Module missing */
128   find_model_description(surf_cpu_model_description, val);
129 }
130
131 /* callback of the cpu/model variable */
132 static void _surf_cfg_cb__optimization_mode(const char *name, int pos)
133 {
134   char *val;
135
136   xbt_assert(_surf_init_status < 2,
137               "Cannot change the model after the initialization");
138
139   val = xbt_cfg_get_string(_surf_cfg_set, name);
140
141   if (!strcmp(val, "help")) {
142     model_help("optimization", surf_optimization_mode_description);
143     exit(0);
144   }
145
146   /* New Module missing */
147   find_model_description(surf_optimization_mode_description, val);
148 }
149
150 /* callback of the cpu/model variable */
151 static void _surf_cfg_cb__storage_mode(const char *name, int pos)
152 {
153   char *val;
154
155   xbt_assert(_surf_init_status < 2,
156               "Cannot change the model after the initialization");
157
158   val = xbt_cfg_get_string(_surf_cfg_set, name);
159
160   if (!strcmp(val, "help")) {
161     model_help("storage", surf_storage_model_description);
162     exit(0);
163   }
164
165   /* New Module missing */
166   find_model_description(surf_storage_model_description, val);
167 }
168
169 /* callback of the workstation_model variable */
170 static void _surf_cfg_cb__network_model(const char *name, int pos)
171 {
172   char *val;
173
174   xbt_assert(_surf_init_status < 2,
175               "Cannot change the model after the initialization");
176
177   val = xbt_cfg_get_string(_surf_cfg_set, name);
178
179   if (!strcmp(val, "help")) {
180     model_help("network", surf_network_model_description);
181     exit(0);
182   }
183
184   /* New Module missing */
185   find_model_description(surf_network_model_description, val);
186 }
187
188
189 /* callbacks of the network models values */
190 static void _surf_cfg_cb__tcp_gamma(const char *name, int pos)
191 {
192   sg_tcp_gamma = xbt_cfg_get_double(_surf_cfg_set, name);
193 }
194
195 static void _surf_cfg_cb__maxmin_precision(const char* name, int pos)
196 {
197   sg_maxmin_precision = xbt_cfg_get_double(_surf_cfg_set, name);
198 }
199
200 static void _surf_cfg_cb__sender_gap(const char* name, int pos)
201 {
202   sg_sender_gap = xbt_cfg_get_double(_surf_cfg_set, name);
203 }
204
205 static void _surf_cfg_cb__latency_factor(const char *name, int pos)
206 {
207   sg_latency_factor = xbt_cfg_get_double(_surf_cfg_set, name);
208 }
209
210 static void _surf_cfg_cb__bandwidth_factor(const char *name, int pos)
211 {
212   sg_bandwidth_factor = xbt_cfg_get_double(_surf_cfg_set, name);
213 }
214
215 static void _surf_cfg_cb__weight_S(const char *name, int pos)
216 {
217   sg_weight_S_parameter = xbt_cfg_get_double(_surf_cfg_set, name);
218 }
219
220 /* callback of the inclusion path */
221 static void _surf_cfg_cb__surf_path(const char *name, int pos)
222 {
223   char *path = xbt_cfg_get_string_at(_surf_cfg_set, name, pos);
224   xbt_dynar_push(surf_path, &path);
225 }
226
227 /* callback to decide if we want to use the model-checking */
228 #include "xbt_modinter.h"
229 extern int _surf_do_model_check;   /* this variable lives in xbt_main until I find a right location for it */
230
231 static void _surf_cfg_cb_model_check(const char *name, int pos)
232 {
233   _surf_do_model_check = xbt_cfg_get_int(_surf_cfg_set, name);
234
235   if (_surf_do_model_check) {
236 #ifndef HAVE_MC
237     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");
238 #endif
239     /* Tell modules using mallocators that they shouldn't. MC don't like them */
240     xbt_fifo_preinit();
241     xbt_dict_preinit();
242   }
243 }
244
245 extern int _surf_do_verbose_exit;
246
247 static void _surf_cfg_cb_verbose_exit(const char *name, int pos)
248 {
249   _surf_do_verbose_exit = xbt_cfg_get_int(_surf_cfg_set, name);
250 }
251
252
253 static void _surf_cfg_cb_context_factory(const char *name, int pos) {
254   smx_context_factory_name = xbt_cfg_get_string(_surf_cfg_set, name);
255 }
256
257 static void _surf_cfg_cb_context_stack_size(const char *name, int pos)
258 {
259   smx_context_stack_size = xbt_cfg_get_int(_surf_cfg_set, name) * 1024;
260 }
261
262 static void _surf_cfg_cb_contexts_nthreads(const char *name, int pos)
263 {
264   SIMIX_context_set_nthreads(xbt_cfg_get_int(_surf_cfg_set, name));
265 }
266
267 static void _surf_cfg_cb_contexts_parallel_threshold(const char *name, int pos)
268 {
269   SIMIX_context_set_parallel_threshold(xbt_cfg_get_int(_surf_cfg_set, name));
270 }
271
272 static void _surf_cfg_cb_contexts_parallel_mode(const char *name, int pos)
273 {
274   const char* mode_name = xbt_cfg_get_string(_surf_cfg_set, name);
275   if (!strcmp(mode_name, "posix")) {
276     SIMIX_context_set_parallel_mode(XBT_PARMAP_POSIX);
277   }
278   else if (!strcmp(mode_name, "futex")) {
279     SIMIX_context_set_parallel_mode(XBT_PARMAP_FUTEX);
280   }
281   else if (!strcmp(mode_name, "busy_wait")) {
282     SIMIX_context_set_parallel_mode(XBT_PARMAP_BUSY_WAIT);
283   }
284   else {
285     xbt_die("Command line setting of the parallel synchronization mode should "
286         "be one of \"posix\", \"futex\" or \"busy_wait\"");
287   }
288 }
289
290 static void _surf_cfg_cb_surf_nthreads(const char *name, int pos)
291 {
292   surf_set_nthreads(xbt_cfg_get_int(_surf_cfg_set, name));
293 }
294
295 static void _surf_cfg_cb__surf_network_coordinates(const char *name,
296                                                    int pos)
297 {
298   char *val = xbt_cfg_get_string(_surf_cfg_set, name);
299   if (!strcmp(val, "yes")) {
300     if (!COORD_HOST_LEVEL) {
301       COORD_HOST_LEVEL = xbt_lib_add_level(host_lib,xbt_dynar_free_voidp);
302       COORD_ASR_LEVEL  = xbt_lib_add_level(as_router_lib,xbt_dynar_free_voidp);
303     }
304   } else if (!strcmp(val, "no")) {
305     if (COORD_HOST_LEVEL)
306       xbt_die("Setting of whether to use coordinate cannot be disabled once set.");
307   } else {
308     xbt_die("Command line setting of whether to use coordinates must be either \"yes\" or \"no\"");
309   }
310 }
311
312 static void _surf_cfg_cb__surf_network_crosstraffic(const char *name,
313                                                   int pos)
314 {
315   sg_network_crosstraffic = xbt_cfg_get_int(_surf_cfg_set, name);
316 }
317
318 #ifdef HAVE_GTNETS
319 static void _surf_cfg_cb__gtnets_jitter(const char *name, int pos)
320 {
321   sg_gtnets_jitter = xbt_cfg_get_double(_surf_cfg_set, name);
322 }
323
324 static void _surf_cfg_cb__gtnets_jitter_seed(const char *name, int pos)
325 {
326   sg_gtnets_jitter_seed = xbt_cfg_get_int(_surf_cfg_set, name);
327 }
328 #endif
329
330 /* create the config set, register what should be and parse the command line*/
331 void surf_config_init(int *argc, char **argv)
332 {
333   char *description = xbt_malloc(1024), *p = description;
334   char *default_value;
335   double double_default_value;
336   int default_value_int;
337   int i;
338
339   /* Create the configuration support */
340   if (_surf_init_status == 0) { /* Only create stuff if not already inited */
341     sprintf(description,
342             "The model to use for the CPU. Possible values: ");
343     p = description;
344     while (*(++p) != '\0');
345     for (i = 0; surf_cpu_model_description[i].name; i++)
346       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
347                    surf_cpu_model_description[i].name);
348     sprintf(p,
349             ".\n       (use 'help' as a value to see the long description of each model)");
350     default_value = xbt_strdup("Cas01");
351     xbt_cfg_register(&_surf_cfg_set, "cpu/model", description, xbt_cfgelm_string,
352                      &default_value, 1, 1, &_surf_cfg_cb__cpu_model, NULL);
353
354     sprintf(description,
355             "The optimization modes to use for the CPU. Possible values: ");
356     p = description;
357     while (*(++p) != '\0');
358     for (i = 0; surf_optimization_mode_description[i].name; i++)
359       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
360                    surf_optimization_mode_description[i].name);
361     sprintf(p,
362             ".\n       (use 'help' as a value to see the long description of each optimization mode)");
363     default_value = xbt_strdup("Lazy");
364     xbt_cfg_register(&_surf_cfg_set, "cpu/optim", description, xbt_cfgelm_string,
365                      &default_value, 1, 1, &_surf_cfg_cb__optimization_mode, NULL);
366
367     sprintf(description,
368             "The model to use for the storage. Possible values: ");
369     p = description;
370     while (*(++p) != '\0');
371     for (i = 0; surf_storage_model_description[i].name; i++)
372       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
373                    surf_storage_model_description[i].name);
374     sprintf(p,
375             ".\n       (use 'help' as a value to see the long description of each model)");
376     default_value = xbt_strdup("default");
377     xbt_cfg_register(&_surf_cfg_set, "storage/model", description, xbt_cfgelm_string,
378                      &default_value, 1, 1, &_surf_cfg_cb__storage_mode,
379                      NULL);
380
381     sprintf(description,
382             "The model to use for the network. Possible values: ");
383     p = description;
384     while (*(++p) != '\0');
385     for (i = 0; surf_network_model_description[i].name; i++)
386       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
387                    surf_network_model_description[i].name);
388     sprintf(p,
389             ".\n       (use 'help' as a value to see the long description of each model)");
390     default_value = xbt_strdup("LV08");
391     xbt_cfg_register(&_surf_cfg_set, "network/model", description, xbt_cfgelm_string,
392                      &default_value, 1, 1, &_surf_cfg_cb__network_model,
393                      NULL);
394
395     sprintf(description,
396             "The optimization modes to use for the network. Possible values: ");
397     p = description;
398     while (*(++p) != '\0');
399     for (i = 0; surf_optimization_mode_description[i].name; i++)
400       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
401                    surf_optimization_mode_description[i].name);
402     sprintf(p,
403             ".\n       (use 'help' as a value to see the long description of each optimization mode)");
404     default_value = xbt_strdup("Lazy");
405     xbt_cfg_register(&_surf_cfg_set, "network/optim", description, xbt_cfgelm_string,
406                      &default_value, 1, 1, &_surf_cfg_cb__optimization_mode, NULL);
407
408     sprintf(description,
409             "The model to use for the workstation. Possible values: ");
410     p = description;
411     while (*(++p) != '\0');
412     for (i = 0; surf_workstation_model_description[i].name; i++)
413       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
414                    surf_workstation_model_description[i].name);
415     sprintf(p,
416             ".\n       (use 'help' as a value to see the long description of each model)");
417     default_value = xbt_strdup("default");
418     xbt_cfg_register(&_surf_cfg_set, "workstation/model", description, xbt_cfgelm_string,
419                      &default_value, 1, 1,
420                      &_surf_cfg_cb__workstation_model, NULL);
421
422     xbt_free(description);
423
424     xbt_cfg_register(&_surf_cfg_set, "network/TCP_gamma",
425                      "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)",
426                      xbt_cfgelm_double, NULL, 1, 1,
427                      _surf_cfg_cb__tcp_gamma, NULL);
428     xbt_cfg_setdefault_double(_surf_cfg_set, "network/TCP_gamma", 20000.0);
429
430     xbt_cfg_register(&_surf_cfg_set, "maxmin/precision",
431                      "Numerical precision used when updating simulation models (epsilon in double comparisons)",
432                      xbt_cfgelm_double, NULL, 1, 1, _surf_cfg_cb__maxmin_precision, NULL);
433     xbt_cfg_setdefault_double(_surf_cfg_set, "maxmin/precision", 0.00001); // FIXME use setdefault everywhere here!
434
435     /* The parameters of network models */
436
437     double_default_value = 0.0;
438     xbt_cfg_register(&_surf_cfg_set, "network/sender_gap",
439                      "Minimum gap between two overlapping sends",
440                      xbt_cfgelm_double, &double_default_value, 1, 1,
441                      _surf_cfg_cb__sender_gap, NULL);
442
443     double_default_value = 1.0;
444     xbt_cfg_register(&_surf_cfg_set, "network/latency_factor",
445                      "Correction factor to apply to the provided latency (default value set by network model)",
446                      xbt_cfgelm_double, &double_default_value, 1, 1,
447                      _surf_cfg_cb__latency_factor, NULL);
448     double_default_value = 1.0;
449     xbt_cfg_register(&_surf_cfg_set, "network/bandwidth_factor",
450                      "Correction factor to apply to the provided bandwidth (default value set by network model)",
451                      xbt_cfgelm_double, &double_default_value, 1, 1,
452                      _surf_cfg_cb__bandwidth_factor, NULL);
453     double_default_value = 0.0;
454     xbt_cfg_register(&_surf_cfg_set, "network/weight_S",
455                      "Correction factor to apply to the weight of competing streams(default value set by network model)",
456                      xbt_cfgelm_double, &double_default_value, 1, 1,
457                      _surf_cfg_cb__weight_S, NULL);
458
459     /* Inclusion path */
460     xbt_cfg_register(&_surf_cfg_set, "path",
461                      "Lookup path for inclusions in platform and deployment XML files",
462                      xbt_cfgelm_string, NULL, 0, 0,
463                      _surf_cfg_cb__surf_path, NULL);
464
465     default_value_int = 0;
466     xbt_cfg_register(&_surf_cfg_set, "cpu/maxmin_selective_update",
467                      "Update the constraint set propagating recursively to others constraints (1 by default when optim is set to lazy)",
468                      xbt_cfgelm_int, &default_value_int, 0, 1,
469                      NULL, NULL);
470     default_value_int = 0;
471     xbt_cfg_register(&_surf_cfg_set, "network/maxmin_selective_update",
472                      "Update the constraint set propagating recursively to others constraints (1 by default when optim is set to lazy)",
473                      xbt_cfgelm_int, &default_value_int, 0, 1,
474                      NULL, NULL);
475
476 #ifdef HAVE_MC
477     /* do model-checking */
478     default_value_int = 0;
479     xbt_cfg_register(&_surf_cfg_set, "model-check",
480                      "Verify the system through model-checking instead of simulating it (EXPERIMENTAL)",
481                      xbt_cfgelm_int, &default_value_int, 0, 1,
482                      _surf_cfg_cb_model_check, NULL);
483
484     /* do stateful model-checking */
485     default_value_int = 0;
486     xbt_cfg_register(&_surf_cfg_set, "model-check/checkpoint",
487                      "Specify the amount of steps between checkpoints during stateful model-checking (default: 0 => stateless verification). "
488                      "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.",
489                      xbt_cfgelm_int, &default_value_int, 0, 1,
490                      _mc_cfg_cb_checkpoint, NULL);
491     
492     /* do liveness model-checking */
493     default_value = xbt_strdup("");
494     xbt_cfg_register(&_surf_cfg_set, "model-check/property",
495                      "Specify the name of the file containing the property. It must be the result of the ltl2ba program.",
496                      xbt_cfgelm_string, &default_value, 0, 1,
497                      _mc_cfg_cb_property, NULL);
498
499     /* Specify the kind of model-checking reduction */
500     default_value = xbt_strdup("unset");
501     xbt_cfg_register(&_surf_cfg_set, "model-check/reduction",
502                      "Specify the kind of exploration reduction (either none or DPOR)",
503                      xbt_cfgelm_string, &default_value, 0, 1,
504                      _mc_cfg_cb_reduce, NULL);
505 #endif
506
507     /* do verbose-exit */
508     default_value_int = 1;
509     xbt_cfg_register(&_surf_cfg_set, "verbose-exit",
510                      "Activate the \"do nothing\" mode in Ctrl-C",
511                      xbt_cfgelm_int, &default_value_int, 0, 1,
512                      _surf_cfg_cb_verbose_exit, NULL);
513     
514     
515     /* context factory */
516     default_value = xbt_strdup("ucontext");
517     xbt_cfg_register(&_surf_cfg_set, "contexts/factory",
518                      "Context factory to use in SIMIX (ucontext, thread or raw)",
519                      xbt_cfgelm_string, &default_value, 1, 1, _surf_cfg_cb_context_factory, NULL);
520
521     /* stack size of contexts in Ko */
522     default_value_int = 128;
523     xbt_cfg_register(&_surf_cfg_set, "contexts/stack_size",
524                      "Stack size of contexts in Kib (ucontext or raw only)",
525                      xbt_cfgelm_int, &default_value_int, 1, 1,
526                      _surf_cfg_cb_context_stack_size, NULL);
527
528     /* number of parallel threads for user processes */
529     default_value_int = 1;
530     xbt_cfg_register(&_surf_cfg_set, "contexts/nthreads",
531                      "Number of parallel threads used to execute user contexts",
532                      xbt_cfgelm_int, &default_value_int, 1, 1,
533                      _surf_cfg_cb_contexts_nthreads, NULL);
534
535     /* minimal number of user contexts to be run in parallel */
536     default_value_int = 2;
537     xbt_cfg_register(&_surf_cfg_set, "contexts/parallel_threshold",
538         "Minimal number of user contexts to be run in parallel (raw contexts only)",
539         xbt_cfgelm_int, &default_value_int, 1, 1,
540         _surf_cfg_cb_contexts_parallel_threshold, NULL);
541
542     /* synchronization mode for parallel user contexts */
543 #ifdef HAVE_FUTEX_H
544     default_value = xbt_strdup("futex");
545 #else //No futex on mac and posix is unimplememted yet
546     default_value = xbt_strdup("busy_wait");
547 #endif
548     xbt_cfg_register(&_surf_cfg_set, "contexts/synchro",
549         "Synchronization mode to use when running contexts in parallel (either futex, posix or busy_wait)",
550         xbt_cfgelm_string, &default_value, 1, 1,
551         _surf_cfg_cb_contexts_parallel_mode, NULL);
552
553     /* number of parallel threads for Surf */
554     default_value_int = surf_get_nthreads();
555     xbt_cfg_register(&_surf_cfg_set, "surf/nthreads",
556                      "Number of parallel threads used to update Surf models",
557                      xbt_cfgelm_int, &default_value_int, 1, 1,
558                      _surf_cfg_cb_surf_nthreads, NULL);
559
560     default_value = xbt_strdup("no");
561     xbt_cfg_register(&_surf_cfg_set, "network/coordinates",
562                      "\"yes\" or \"no\", specifying whether we use a coordinate-based routing (as Vivaldi)",
563                      xbt_cfgelm_string, &default_value, 1, 1,
564                      _surf_cfg_cb__surf_network_coordinates, NULL);
565     xbt_cfg_setdefault_string(_surf_cfg_set, "network/coordinates", default_value);
566
567     default_value_int = 0;
568     xbt_cfg_register(&_surf_cfg_set, "network/crosstraffic",
569                      "Activate the interferences between uploads and downloads for fluid max-min models (LV08, CM02)",
570                      xbt_cfgelm_int, &default_value_int, 0, 1,
571                      _surf_cfg_cb__surf_network_crosstraffic, NULL);
572     xbt_cfg_setdefault_int(_surf_cfg_set, "network/crosstraffic", default_value_int);
573
574 #ifdef HAVE_GTNETS
575     xbt_cfg_register(&_surf_cfg_set, "gtnets/jitter",
576                      "Double value to oscillate the link latency, uniformly in random interval [-latency*gtnets_jitter,latency*gtnets_jitter)",
577                      xbt_cfgelm_double, NULL, 1, 1,
578                      _surf_cfg_cb__gtnets_jitter, NULL);
579     xbt_cfg_setdefault_double(_surf_cfg_set, "gtnets/jitter", 0.0);
580
581     default_value_int = 10;
582     xbt_cfg_register(&_surf_cfg_set, "gtnets/jitter_seed",
583                      "Use a positive seed to reproduce jitted results, value must be in [1,1e8], default is 10",
584                      xbt_cfgelm_int, &default_value_int, 0, 1,
585                      _surf_cfg_cb__gtnets_jitter_seed, NULL);
586 #endif
587 #ifdef HAVE_NS3
588     xbt_cfg_register(&_surf_cfg_set, "ns3/TcpModel",
589                      "The ns3 tcp model can be : NewReno or Reno or Tahoe",
590                      xbt_cfgelm_string, NULL, 1, 1,
591                      NULL, NULL);
592     xbt_cfg_setdefault_string(_surf_cfg_set, "ns3/TcpModel", "default");
593 #endif
594
595 //SMPI
596     double default_reference_speed = 20000.0;
597     xbt_cfg_register(&_surf_cfg_set, "smpi/running_power",
598                      "Power of the host running the simulation (in flop/s). Used to bench the operations.",
599                      xbt_cfgelm_double, &default_reference_speed, 1, 1, NULL,
600                      NULL);
601
602     int default_display_timing = 0;
603     xbt_cfg_register(&_surf_cfg_set, "smpi/display_timing",
604                      "Boolean indicating whether we should display the timing after simulation.",
605                      xbt_cfgelm_int, &default_display_timing, 1, 1, NULL,
606                      NULL);
607
608     double default_threshold = 1e-6;
609     xbt_cfg_register(&_surf_cfg_set, "smpi/cpu_threshold",
610                      "Minimal computation time (in seconds) not discarded.",
611                      xbt_cfgelm_double, &default_threshold, 1, 1, NULL,
612                      NULL);
613
614     int default_small_messages_threshold = 0;
615     xbt_cfg_register(&_surf_cfg_set, "smpi/async_small_thres",
616                      "Maximal size of messages that are to be sent asynchronously, without waiting for the receiver",
617                      xbt_cfgelm_int, &default_small_messages_threshold, 1, 1, NULL,
618                      NULL);
619
620     //For smpi/bw_factor and smpi/lat_factor
621     //Default value have to be "threshold0:value0;threshold1:value1;...;thresholdN:valueN"
622     //test is if( size >= thresholdN ) return valueN;
623     //Values can be modified with command line --cfg=smpi/bw_factor:"threshold0:value0;threshold1:value1;...;thresholdN:valueN"
624     //  or with tag config put line <prop id="smpi/bw_factor" value="threshold0:value0;threshold1:value1;...;thresholdN:valueN"></prop>
625     xbt_cfg_register(&_surf_cfg_set, "smpi/bw_factor",
626                      "Bandwidth factors for smpi.",
627                      xbt_cfgelm_string, NULL, 1, 1, NULL,
628                      NULL);
629     xbt_cfg_setdefault_string(_surf_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");
630
631     xbt_cfg_register(&_surf_cfg_set, "smpi/lat_factor",
632                      "Latency factors for smpi.",
633                      xbt_cfgelm_string, NULL, 1, 1, NULL,
634                      NULL);
635     xbt_cfg_setdefault_string(_surf_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");
636 //END SMPI
637
638
639     if (!surf_path) {
640       /* retrieves the current directory of the        current process */
641       const char *initial_path = __surf_get_initial_path();
642       xbt_assert((initial_path),
643                   "__surf_get_initial_path() failed! Can't resolves current Windows directory");
644
645       surf_path = xbt_dynar_new(sizeof(char *), NULL);
646       xbt_cfg_setdefault_string(_surf_cfg_set, "path", initial_path);
647     }
648
649
650     surf_config_cmd_line(argc, argv);
651
652     _surf_init_status = 1;
653   } else {
654     XBT_WARN("Call to surf_config_init() after initialization ignored");
655   }
656 }
657
658 void surf_config_finalize(void)
659 {
660   if (!_surf_init_status)
661     return;                     /* Not initialized yet. Nothing to do */
662
663   xbt_cfg_free(&_surf_cfg_set);
664   _surf_init_status = 0;
665 }
666
667 /* Pick the right models for CPU, net and workstation, and call their model_init_preparse */
668 void surf_config_models_setup()
669 {
670   char *workstation_model_name;
671   int workstation_id = -1;
672   char *network_model_name = NULL;
673   char *cpu_model_name = NULL;
674   int storage_id = -1;
675   char *storage_model_name = NULL;
676
677   workstation_model_name =
678       xbt_cfg_get_string(_surf_cfg_set, "workstation/model");
679   network_model_name = xbt_cfg_get_string(_surf_cfg_set, "network/model");
680   cpu_model_name = xbt_cfg_get_string(_surf_cfg_set, "cpu/model");
681   storage_model_name = xbt_cfg_get_string(_surf_cfg_set, "storage/model");
682
683   /* Check whether we use a net/cpu model differing from the default ones, in which case
684    * we should switch to the "compound" workstation model to correctly dispatch stuff to
685    * the right net/cpu models.
686    */
687
688   if((!xbt_cfg_is_default_value(_surf_cfg_set, "network/model") ||
689     !xbt_cfg_is_default_value(_surf_cfg_set, "cpu/model")) &&
690     xbt_cfg_is_default_value(_surf_cfg_set, "workstation/model"))
691   {
692       const char *val = "compound";
693       XBT_INFO
694           ("Switching workstation model to compound since you changed the network and/or cpu model(s)");
695       xbt_cfg_set_string(_surf_cfg_set, "workstation/model", val);
696       workstation_model_name = (char *) "compound";
697   }
698
699   XBT_DEBUG("Workstation model: %s", workstation_model_name);
700   workstation_id =
701       find_model_description(surf_workstation_model_description,
702                              workstation_model_name);
703   if (!strcmp(workstation_model_name, "compound")) {
704     int network_id = -1;
705     int cpu_id = -1;
706
707     xbt_assert(cpu_model_name,
708                 "Set a cpu model to use with the 'compound' workstation model");
709
710     xbt_assert(network_model_name,
711                 "Set a network model to use with the 'compound' workstation model");
712
713     network_id =
714         find_model_description(surf_network_model_description,
715                                network_model_name);
716     cpu_id =
717         find_model_description(surf_cpu_model_description, cpu_model_name);
718
719     surf_cpu_model_description[cpu_id].model_init_preparse();
720     surf_network_model_description[network_id].model_init_preparse();
721   }
722
723   XBT_DEBUG("Call workstation_model_init");
724   surf_workstation_model_description[workstation_id].model_init_preparse();
725
726   XBT_DEBUG("Call storage_model_init");
727   storage_id = find_model_description(surf_storage_model_description, storage_model_name);
728   surf_storage_model_description[storage_id].model_init_preparse();
729 }