Logo AND Algorithmique Numérique Distribuée

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