Logo AND Algorithmique Numérique Distribuée

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