Logo AND Algorithmique Numérique Distribuée

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