Logo AND Algorithmique Numérique Distribuée

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