Logo AND Algorithmique Numérique Distribuée

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