Logo AND Algorithmique Numérique Distribuée

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