Logo AND Algorithmique Numérique Distribuée

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