Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
6108c02fc99a12d855081b43cf1898456be52ede
[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/misc.h"
10 #include "xbt/config.h"
11 #include "xbt/log.h"
12 #include "xbt/str.h"
13 #include "surf/surf_private.h"
14 #include "surf/surf_routing.h"  /* COORD_HOST_LEVEL and COORD_ASR_LEVEL */
15 #include "simgrid/simix.h"
16 #include "mc/mc.h" /* configuration callbacks of model-checking */
17
18 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf,
19                                 "About the configuration of surf (and the rest of the simulation)");
20
21 xbt_cfg_t _surf_cfg_set = NULL;
22
23 /* Parse the command line, looking for options */
24 static void surf_config_cmd_line(int *argc, char **argv)
25 {
26   int shall_exit = 0;
27   int i, j;
28   char *opt;
29
30   for (j = i = 1; i < *argc; i++) {
31     if (!strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
32       opt = strchr(argv[i], '=');
33       opt++;
34
35       xbt_cfg_set_parse(_surf_cfg_set, opt);
36       XBT_DEBUG("Did apply '%s' as config setting", opt);
37     } else if (!strcmp(argv[i], "--cfg-help") || !strcmp(argv[i], "--help")) {
38       printf
39           ("Description of the configuration accepted by this simulator:\n");
40       xbt_cfg_help(_surf_cfg_set);
41       printf(
42 "\n"
43 "Each of these configurations can be used by adding\n"
44 "    --cfg=<option name>:<option value>\n"
45 "to the command line.\n"
46 "You can also use --help-models to see the details of all models known by this simulator.\n"
47 #ifdef HAVE_TRACING
48 "\n"
49 "You can also use --help-tracing to see the details of all tracing options known by this simulator.\n"
50 #endif
51 "\n"
52 "You can also use --help-logs and --help-log-categories to see the details of logging output.\n"
53 "\n"
54         );
55       shall_exit = 1;
56     } else if (!strcmp(argv[i], "--help-models")) {
57       int k;
58
59       model_help("workstation", surf_workstation_model_description);
60       printf("\n");
61       model_help("CPU", surf_cpu_model_description);
62       printf("\n");
63       model_help("network", surf_network_model_description);
64       printf("\nLong description of all optimization levels accepted by the models of this simulator:\n");
65       for (k = 0; surf_optimization_mode_description[k].name; k++)
66         printf("  %s: %s\n",
67                surf_optimization_mode_description[k].name,
68                surf_optimization_mode_description[k].description);
69       printf("Both network and CPU models have 'Lazy' as default optimization level\n\n");
70       shall_exit = 1;
71 #ifdef HAVE_TRACING
72     } else if (!strcmp(argv[i], "--help-tracing")) {
73       TRACE_help (1);
74       shall_exit = 1;
75 #endif
76     } else {
77       argv[j++] = argv[i];
78     }
79   }
80   if (j < *argc) {
81     argv[j] = NULL;
82     *argc = j;
83   }
84   if (shall_exit)
85     exit(0);
86 }
87
88
89 int _surf_init_status = 0;      /* 0: beginning of time;
90                                    1: pre-inited (cfg_set created);
91                                    2: inited (running) */
92
93 /* callback of the workstation/model variable */
94 static void _surf_cfg_cb__workstation_model(const char *name, int pos)
95 {
96   char *val;
97
98   xbt_assert(_surf_init_status < 2,
99               "Cannot change the model after the initialization");
100
101   val = xbt_cfg_get_string(_surf_cfg_set, name);
102
103   if (!strcmp(val, "help")) {
104     model_help("workstation", surf_workstation_model_description);
105     exit(0);
106   }
107
108   /* Make sure that the model exists */
109   find_model_description(surf_workstation_model_description, val);
110 }
111
112 /* callback of the cpu/model variable */
113 static void _surf_cfg_cb__cpu_model(const char *name, int pos)
114 {
115   char *val;
116
117   xbt_assert(_surf_init_status < 2,
118               "Cannot change the model after the initialization");
119
120   val = xbt_cfg_get_string(_surf_cfg_set, name);
121
122   if (!strcmp(val, "help")) {
123     model_help("CPU", surf_cpu_model_description);
124     exit(0);
125   }
126
127   /* New Module missing */
128   find_model_description(surf_cpu_model_description, val);
129 }
130
131 /* callback of the cpu/model variable */
132 static void _surf_cfg_cb__optimization_mode(const char *name, int pos)
133 {
134   char *val;
135
136   xbt_assert(_surf_init_status < 2,
137               "Cannot change the model after the initialization");
138
139   val = xbt_cfg_get_string(_surf_cfg_set, name);
140
141   if (!strcmp(val, "help")) {
142     model_help("optimization", surf_optimization_mode_description);
143     exit(0);
144   }
145
146   /* New Module missing */
147   find_model_description(surf_optimization_mode_description, val);
148 }
149
150 /* callback of the cpu/model variable */
151 static void _surf_cfg_cb__storage_mode(const char *name, int pos)
152 {
153   char *val;
154
155   xbt_assert(_surf_init_status < 2,
156               "Cannot change the model after the initialization");
157
158   val = xbt_cfg_get_string(_surf_cfg_set, name);
159
160   if (!strcmp(val, "help")) {
161     model_help("storage", surf_storage_model_description);
162     exit(0);
163   }
164
165   /* New Module missing */
166   find_model_description(surf_storage_model_description, val);
167 }
168
169 /* callback of the workstation_model variable */
170 static void _surf_cfg_cb__network_model(const char *name, int pos)
171 {
172   char *val;
173
174   xbt_assert(_surf_init_status < 2,
175               "Cannot change the model after the initialization");
176
177   val = xbt_cfg_get_string(_surf_cfg_set, name);
178
179   if (!strcmp(val, "help")) {
180     model_help("network", surf_network_model_description);
181     exit(0);
182   }
183
184   /* New Module missing */
185   find_model_description(surf_network_model_description, val);
186 }
187
188
189 /* callbacks of the network models values */
190 static void _surf_cfg_cb__tcp_gamma(const char *name, int pos)
191 {
192   sg_tcp_gamma = xbt_cfg_get_double(_surf_cfg_set, name);
193 }
194
195 static void _surf_cfg_cb__maxmin_precision(const char* name, int pos)
196 {
197   sg_maxmin_precision = xbt_cfg_get_double(_surf_cfg_set, name);
198 }
199
200 static void _surf_cfg_cb__sender_gap(const char* name, int pos)
201 {
202   sg_sender_gap = xbt_cfg_get_double(_surf_cfg_set, name);
203 }
204
205 static void _surf_cfg_cb__latency_factor(const char *name, int pos)
206 {
207   sg_latency_factor = xbt_cfg_get_double(_surf_cfg_set, name);
208 }
209
210 static void _surf_cfg_cb__bandwidth_factor(const char *name, int pos)
211 {
212   sg_bandwidth_factor = xbt_cfg_get_double(_surf_cfg_set, name);
213 }
214
215 static void _surf_cfg_cb__weight_S(const char *name, int pos)
216 {
217   sg_weight_S_parameter = xbt_cfg_get_double(_surf_cfg_set, name);
218 }
219
220 /* callback of the inclusion path */
221 static void _surf_cfg_cb__surf_path(const char *name, int pos)
222 {
223   char *path = xbt_cfg_get_string_at(_surf_cfg_set, name, pos);
224   xbt_dynar_push(surf_path, &path);
225 }
226
227 /* callback to decide if we want to use the model-checking */
228 #include "xbt_modinter.h"
229 extern int _surf_do_model_check;   /* this variable lives in xbt_main until I find a right location for it */
230
231 static void _surf_cfg_cb_model_check(const char *name, int pos)
232 {
233   _surf_do_model_check = xbt_cfg_get_int(_surf_cfg_set, name);
234
235   if (_surf_do_model_check) {
236 #ifndef HAVE_MC
237     xbt_die("You tried to activate the model-checking from the command line, but it was not compiled in. Change your settings in cmake, recompile and try again");
238 #endif
239     /* Tell modules using mallocators that they shouldn't. MC don't like them */
240     xbt_fifo_preinit();
241     xbt_dict_preinit();
242   }
243 }
244
245 extern int _surf_do_verbose_exit;
246
247 static void _surf_cfg_cb_verbose_exit(const char *name, int pos)
248 {
249   _surf_do_verbose_exit = xbt_cfg_get_int(_surf_cfg_set, name);
250 }
251
252
253 static void _surf_cfg_cb_context_factory(const char *name, int pos) {
254   smx_context_factory_name = xbt_cfg_get_string(_surf_cfg_set, name);
255 }
256
257 static void _surf_cfg_cb_context_stack_size(const char *name, int pos)
258 {
259   smx_context_stack_size = xbt_cfg_get_int(_surf_cfg_set, name) * 1024;
260 }
261
262 static void _surf_cfg_cb_contexts_nthreads(const char *name, int pos)
263 {
264   SIMIX_context_set_nthreads(xbt_cfg_get_int(_surf_cfg_set, name));
265 }
266
267 static void _surf_cfg_cb_contexts_parallel_threshold(const char *name, int pos)
268 {
269   SIMIX_context_set_parallel_threshold(xbt_cfg_get_int(_surf_cfg_set, name));
270 }
271
272 static void _surf_cfg_cb_contexts_parallel_mode(const char *name, int pos)
273 {
274   const char* mode_name = xbt_cfg_get_string(_surf_cfg_set, name);
275   if (!strcmp(mode_name, "posix")) {
276     SIMIX_context_set_parallel_mode(XBT_PARMAP_POSIX);
277   }
278   else if (!strcmp(mode_name, "futex")) {
279     SIMIX_context_set_parallel_mode(XBT_PARMAP_FUTEX);
280   }
281   else if (!strcmp(mode_name, "busy_wait")) {
282     SIMIX_context_set_parallel_mode(XBT_PARMAP_BUSY_WAIT);
283   }
284   else {
285     xbt_die("Command line setting of the parallel synchronization mode should "
286         "be one of \"posix\", \"futex\" or \"busy_wait\"");
287   }
288 }
289
290 static void _surf_cfg_cb_surf_nthreads(const char *name, int pos)
291 {
292   surf_set_nthreads(xbt_cfg_get_int(_surf_cfg_set, name));
293 }
294
295 static void _surf_cfg_cb__surf_network_coordinates(const char *name,
296                                                    int pos)
297 {
298   char *val = xbt_cfg_get_string(_surf_cfg_set, name);
299   if (!strcmp(val, "yes")) {
300     if (!COORD_HOST_LEVEL) {
301       COORD_HOST_LEVEL = xbt_lib_add_level(host_lib,xbt_dynar_free_voidp);
302       COORD_ASR_LEVEL  = xbt_lib_add_level(as_router_lib,xbt_dynar_free_voidp);
303     }
304   } else if (!strcmp(val, "no")) {
305     if (COORD_HOST_LEVEL)
306       xbt_die("Setting of whether to use coordinate cannot be disabled once set.");
307   } else {
308     xbt_die("Command line setting of whether to use coordinates must be either \"yes\" or \"no\"");
309   }
310 }
311
312 static void _surf_cfg_cb__surf_network_crosstraffic(const char *name,
313                                                   int pos)
314 {
315   sg_network_crosstraffic = xbt_cfg_get_int(_surf_cfg_set, name);
316 }
317
318 #ifdef HAVE_GTNETS
319 static void _surf_cfg_cb__gtnets_jitter(const char *name, int pos)
320 {
321   sg_gtnets_jitter = xbt_cfg_get_double(_surf_cfg_set, name);
322 }
323
324 static void _surf_cfg_cb__gtnets_jitter_seed(const char *name, int pos)
325 {
326   sg_gtnets_jitter_seed = xbt_cfg_get_int(_surf_cfg_set, name);
327 }
328 #endif
329
330 /* create the config set, register what should be and parse the command line*/
331 void surf_config_init(int *argc, char **argv)
332 {
333   char *description = xbt_malloc(1024), *p = description;
334   char *default_value;
335   double double_default_value;
336   int default_value_int;
337   int i;
338
339   /* Create the configuration support */
340   if (_surf_init_status == 0) { /* Only create stuff if not already inited */
341     sprintf(description,
342             "The model to use for the CPU. Possible values: ");
343     p = description;
344     while (*(++p) != '\0');
345     for (i = 0; surf_cpu_model_description[i].name; i++)
346       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
347                    surf_cpu_model_description[i].name);
348     sprintf(p,
349             ".\n       (use 'help' as a value to see the long description of each model)");
350     default_value = xbt_strdup("Cas01");
351     xbt_cfg_register(&_surf_cfg_set, "cpu/model", description, xbt_cfgelm_string,
352                      &default_value, 1, 1, &_surf_cfg_cb__cpu_model, NULL);
353
354     sprintf(description,
355             "The optimization modes to use for the CPU. Possible values: ");
356     p = description;
357     while (*(++p) != '\0');
358     for (i = 0; surf_optimization_mode_description[i].name; i++)
359       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
360                    surf_optimization_mode_description[i].name);
361     sprintf(p,
362             ".\n       (use 'help' as a value to see the long description of each optimization mode)");
363     default_value = xbt_strdup("Lazy");
364     xbt_cfg_register(&_surf_cfg_set, "cpu/optim", description, xbt_cfgelm_string,
365                      &default_value, 1, 1, &_surf_cfg_cb__optimization_mode, NULL);
366
367     sprintf(description,
368             "The model to use for the storage. Possible values: ");
369     p = description;
370     while (*(++p) != '\0');
371     for (i = 0; surf_storage_model_description[i].name; i++)
372       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
373                    surf_storage_model_description[i].name);
374     sprintf(p,
375             ".\n       (use 'help' as a value to see the long description of each model)");
376     default_value = xbt_strdup("default");
377     xbt_cfg_register(&_surf_cfg_set, "storage/model", description, xbt_cfgelm_string,
378                      &default_value, 1, 1, &_surf_cfg_cb__storage_mode,
379                      NULL);
380
381     /* ********************************************************************* */
382     /* TUTORIAL: New model                                                   */
383     sprintf(description,
384             "The model to use for the New model. Possible values: ");
385     p = description;
386     while (*(++p) != '\0');
387     for (i = 0; surf_new_model_description[i].name; i++)
388       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
389                    surf_new_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("default");
393     xbt_cfg_register(&_surf_cfg_set, "new_model/model", description, xbt_cfgelm_string,
394                      &default_value, 1, 1, &_surf_cfg_cb__storage_mode,
395                      NULL);
396     /* ********************************************************************* */
397
398     sprintf(description,
399             "The model to use for the network. Possible values: ");
400     p = description;
401     while (*(++p) != '\0');
402     for (i = 0; surf_network_model_description[i].name; i++)
403       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
404                    surf_network_model_description[i].name);
405     sprintf(p,
406             ".\n       (use 'help' as a value to see the long description of each model)");
407     default_value = xbt_strdup("LV08");
408     xbt_cfg_register(&_surf_cfg_set, "network/model", description, xbt_cfgelm_string,
409                      &default_value, 1, 1, &_surf_cfg_cb__network_model,
410                      NULL);
411
412     sprintf(description,
413             "The optimization modes to use for the network. Possible values: ");
414     p = description;
415     while (*(++p) != '\0');
416     for (i = 0; surf_optimization_mode_description[i].name; i++)
417       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
418                    surf_optimization_mode_description[i].name);
419     sprintf(p,
420             ".\n       (use 'help' as a value to see the long description of each optimization mode)");
421     default_value = xbt_strdup("Lazy");
422     xbt_cfg_register(&_surf_cfg_set, "network/optim", description, xbt_cfgelm_string,
423                      &default_value, 1, 1, &_surf_cfg_cb__optimization_mode, NULL);
424
425     sprintf(description,
426             "The model to use for the workstation. Possible values: ");
427     p = description;
428     while (*(++p) != '\0');
429     for (i = 0; surf_workstation_model_description[i].name; i++)
430       p += sprintf(p, "%s%s", (i == 0 ? "" : ", "),
431                    surf_workstation_model_description[i].name);
432     sprintf(p,
433             ".\n       (use 'help' as a value to see the long description of each model)");
434     default_value = xbt_strdup("default");
435     xbt_cfg_register(&_surf_cfg_set, "workstation/model", description, xbt_cfgelm_string,
436                      &default_value, 1, 1,
437                      &_surf_cfg_cb__workstation_model, NULL);
438
439     xbt_free(description);
440
441     xbt_cfg_register(&_surf_cfg_set, "network/TCP_gamma",
442                      "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)",
443                      xbt_cfgelm_double, NULL, 1, 1,
444                      _surf_cfg_cb__tcp_gamma, NULL);
445     xbt_cfg_setdefault_double(_surf_cfg_set, "network/TCP_gamma", 20000.0);
446
447     xbt_cfg_register(&_surf_cfg_set, "maxmin/precision",
448                      "Numerical precision used when updating simulation models (epsilon in double comparisons)",
449                      xbt_cfgelm_double, NULL, 1, 1, _surf_cfg_cb__maxmin_precision, NULL);
450     xbt_cfg_setdefault_double(_surf_cfg_set, "maxmin/precision", 0.00001); // FIXME use setdefault everywhere here!
451
452     /* The parameters of network models */
453
454     double_default_value = 0.0;
455     xbt_cfg_register(&_surf_cfg_set, "network/sender_gap",
456                      "Minimum gap between two overlapping sends",
457                      xbt_cfgelm_double, &double_default_value, 1, 1,
458                      _surf_cfg_cb__sender_gap, NULL);
459
460     double_default_value = 1.0;
461     xbt_cfg_register(&_surf_cfg_set, "network/latency_factor",
462                      "Correction factor to apply to the provided latency (default value set by network model)",
463                      xbt_cfgelm_double, &double_default_value, 1, 1,
464                      _surf_cfg_cb__latency_factor, NULL);
465     double_default_value = 1.0;
466     xbt_cfg_register(&_surf_cfg_set, "network/bandwidth_factor",
467                      "Correction factor to apply to the provided bandwidth (default value set by network model)",
468                      xbt_cfgelm_double, &double_default_value, 1, 1,
469                      _surf_cfg_cb__bandwidth_factor, NULL);
470     double_default_value = 0.0;
471     xbt_cfg_register(&_surf_cfg_set, "network/weight_S",
472                      "Correction factor to apply to the weight of competing streams(default value set by network model)",
473                      xbt_cfgelm_double, &double_default_value, 1, 1,
474                      _surf_cfg_cb__weight_S, NULL);
475
476     /* Inclusion path */
477     xbt_cfg_register(&_surf_cfg_set, "path",
478                      "Lookup path for inclusions in platform and deployment XML files",
479                      xbt_cfgelm_string, NULL, 0, 0,
480                      _surf_cfg_cb__surf_path, NULL);
481
482     default_value_int = 0;
483     xbt_cfg_register(&_surf_cfg_set, "cpu/maxmin_selective_update",
484                      "Update the constraint set propagating recursively to others constraints (1 by default when optim is set to lazy)",
485                      xbt_cfgelm_int, &default_value_int, 0, 1,
486                      NULL, NULL);
487     default_value_int = 0;
488     xbt_cfg_register(&_surf_cfg_set, "network/maxmin_selective_update",
489                      "Update the constraint set propagating recursively to others constraints (1 by default when optim is set to lazy)",
490                      xbt_cfgelm_int, &default_value_int, 0, 1,
491                      NULL, NULL);
492
493 #ifdef HAVE_MC
494     /* do model-checking */
495     default_value_int = 0;
496     xbt_cfg_register(&_surf_cfg_set, "model-check",
497                      "Verify the system through model-checking instead of simulating it (EXPERIMENTAL)",
498                      xbt_cfgelm_int, &default_value_int, 0, 1,
499                      _surf_cfg_cb_model_check, NULL);
500
501     /* do stateful model-checking */
502     default_value_int = 0;
503     xbt_cfg_register(&_surf_cfg_set, "model-check/checkpoint",
504                      "Specify the amount of steps between checkpoints during stateful model-checking (default: 0 => stateless verification). "
505                      "If value=1, one checkpoint is saved for each step => faster verification, but huge memory consumption; higher values are good compromises between speed and memory consumption.",
506                      xbt_cfgelm_int, &default_value_int, 0, 1,
507                      _mc_cfg_cb_checkpoint, NULL);
508     
509     /* do liveness model-checking */
510     default_value = xbt_strdup("");
511     xbt_cfg_register(&_surf_cfg_set, "model-check/property",
512                      "Specify the name of the file containing the property. It must be the result of the ltl2ba program.",
513                      xbt_cfgelm_string, &default_value, 0, 1,
514                      _mc_cfg_cb_property, NULL);
515
516     /* Specify the kind of model-checking reduction */
517     default_value = xbt_strdup("unset");
518     xbt_cfg_register(&_surf_cfg_set, "model-check/reduction",
519                      "Specify the kind of exploration reduction (either none or DPOR)",
520                      xbt_cfgelm_string, &default_value, 0, 1,
521                      _mc_cfg_cb_reduce, NULL);
522 #endif
523
524     /* do verbose-exit */
525     default_value_int = 1;
526     xbt_cfg_register(&_surf_cfg_set, "verbose-exit",
527                      "Activate the \"do nothing\" mode in Ctrl-C",
528                      xbt_cfgelm_int, &default_value_int, 0, 1,
529                      _surf_cfg_cb_verbose_exit, NULL);
530     
531     
532     /* context factory */
533     default_value = xbt_strdup("ucontext");
534     xbt_cfg_register(&_surf_cfg_set, "contexts/factory",
535                      "Context factory to use in SIMIX (ucontext, thread or raw)",
536                      xbt_cfgelm_string, &default_value, 1, 1, _surf_cfg_cb_context_factory, NULL);
537
538     /* stack size of contexts in Ko */
539     default_value_int = 128;
540     xbt_cfg_register(&_surf_cfg_set, "contexts/stack_size",
541                      "Stack size of contexts in Kib (ucontext or raw only)",
542                      xbt_cfgelm_int, &default_value_int, 1, 1,
543                      _surf_cfg_cb_context_stack_size, NULL);
544
545     /* number of parallel threads for user processes */
546     default_value_int = 1;
547     xbt_cfg_register(&_surf_cfg_set, "contexts/nthreads",
548                      "Number of parallel threads used to execute user contexts",
549                      xbt_cfgelm_int, &default_value_int, 1, 1,
550                      _surf_cfg_cb_contexts_nthreads, NULL);
551
552     /* minimal number of user contexts to be run in parallel */
553     default_value_int = 2;
554     xbt_cfg_register(&_surf_cfg_set, "contexts/parallel_threshold",
555         "Minimal number of user contexts to be run in parallel (raw contexts only)",
556         xbt_cfgelm_int, &default_value_int, 1, 1,
557         _surf_cfg_cb_contexts_parallel_threshold, NULL);
558
559     /* synchronization mode for parallel user contexts */
560 #ifdef HAVE_FUTEX_H
561     default_value = xbt_strdup("futex");
562 #else //No futex on mac and posix is unimplememted yet
563     default_value = xbt_strdup("busy_wait");
564 #endif
565     xbt_cfg_register(&_surf_cfg_set, "contexts/synchro",
566         "Synchronization mode to use when running contexts in parallel (either futex, posix or busy_wait)",
567         xbt_cfgelm_string, &default_value, 1, 1,
568         _surf_cfg_cb_contexts_parallel_mode, NULL);
569
570     /* number of parallel threads for Surf */
571     default_value_int = surf_get_nthreads();
572     xbt_cfg_register(&_surf_cfg_set, "surf/nthreads",
573                      "Number of parallel threads used to update Surf models",
574                      xbt_cfgelm_int, &default_value_int, 1, 1,
575                      _surf_cfg_cb_surf_nthreads, NULL);
576
577     default_value = xbt_strdup("no");
578     xbt_cfg_register(&_surf_cfg_set, "network/coordinates",
579                      "\"yes\" or \"no\", specifying whether we use a coordinate-based routing (as Vivaldi)",
580                      xbt_cfgelm_string, &default_value, 1, 1,
581                      _surf_cfg_cb__surf_network_coordinates, NULL);
582     xbt_cfg_setdefault_string(_surf_cfg_set, "network/coordinates", default_value);
583
584     default_value_int = 0;
585     xbt_cfg_register(&_surf_cfg_set, "network/crosstraffic",
586                      "Activate the interferences between uploads and downloads for fluid max-min models (LV08, CM02)",
587                      xbt_cfgelm_int, &default_value_int, 0, 1,
588                      _surf_cfg_cb__surf_network_crosstraffic, NULL);
589     xbt_cfg_setdefault_int(_surf_cfg_set, "network/crosstraffic", default_value_int);
590
591 #ifdef HAVE_GTNETS
592     xbt_cfg_register(&_surf_cfg_set, "gtnets/jitter",
593                      "Double value to oscillate the link latency, uniformly in random interval [-latency*gtnets_jitter,latency*gtnets_jitter)",
594                      xbt_cfgelm_double, NULL, 1, 1,
595                      _surf_cfg_cb__gtnets_jitter, NULL);
596     xbt_cfg_setdefault_double(_surf_cfg_set, "gtnets/jitter", 0.0);
597
598     default_value_int = 10;
599     xbt_cfg_register(&_surf_cfg_set, "gtnets/jitter_seed",
600                      "Use a positive seed to reproduce jitted results, value must be in [1,1e8], default is 10",
601                      xbt_cfgelm_int, &default_value_int, 0, 1,
602                      _surf_cfg_cb__gtnets_jitter_seed, NULL);
603 #endif
604 #ifdef HAVE_NS3
605     xbt_cfg_register(&_surf_cfg_set, "ns3/TcpModel",
606                      "The ns3 tcp model can be : NewReno or Reno or Tahoe",
607                      xbt_cfgelm_string, NULL, 1, 1,
608                      NULL, NULL);
609     xbt_cfg_setdefault_string(_surf_cfg_set, "ns3/TcpModel", "default");
610 #endif
611
612 //SMPI
613     double default_reference_speed = 20000.0;
614     xbt_cfg_register(&_surf_cfg_set, "smpi/running_power",
615                      "Power of the host running the simulation (in flop/s). Used to bench the operations.",
616                      xbt_cfgelm_double, &default_reference_speed, 1, 1, NULL,
617                      NULL);
618
619     int default_display_timing = 0;
620     xbt_cfg_register(&_surf_cfg_set, "smpi/display_timing",
621                      "Boolean indicating whether we should display the timing after simulation.",
622                      xbt_cfgelm_int, &default_display_timing, 1, 1, NULL,
623                      NULL);
624
625     double default_threshold = 1e-6;
626     xbt_cfg_register(&_surf_cfg_set, "smpi/cpu_threshold",
627                      "Minimal computation time (in seconds) not discarded.",
628                      xbt_cfgelm_double, &default_threshold, 1, 1, NULL,
629                      NULL);
630
631     int default_small_messages_threshold = 0;
632     xbt_cfg_register(&_surf_cfg_set, "smpi/async_small_thres",
633                      "Maximal size of messages that are to be sent asynchronously, without waiting for the receiver",
634                      xbt_cfgelm_int, &default_small_messages_threshold, 1, 1, NULL,
635                      NULL);
636
637     //For smpi/bw_factor and smpi/lat_factor
638     //Default value have to be "threshold0:value0;threshold1:value1;...;thresholdN:valueN"
639     //test is if( size >= thresholdN ) return valueN;
640     //Values can be modified with command line --cfg=smpi/bw_factor:"threshold0:value0;threshold1:value1;...;thresholdN:valueN"
641     //  or with tag config put line <prop id="smpi/bw_factor" value="threshold0:value0;threshold1:value1;...;thresholdN:valueN"></prop>
642     xbt_cfg_register(&_surf_cfg_set, "smpi/bw_factor",
643                      "Bandwidth factors for smpi.",
644                      xbt_cfgelm_string, NULL, 1, 1, NULL,
645                      NULL);
646     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");
647
648     xbt_cfg_register(&_surf_cfg_set, "smpi/lat_factor",
649                      "Latency factors for smpi.",
650                      xbt_cfgelm_string, NULL, 1, 1, NULL,
651                      NULL);
652     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");
653 //END SMPI
654
655
656     if (!surf_path) {
657       /* retrieves the current directory of the        current process */
658       const char *initial_path = __surf_get_initial_path();
659       xbt_assert((initial_path),
660                   "__surf_get_initial_path() failed! Can't resolves current Windows directory");
661
662       surf_path = xbt_dynar_new(sizeof(char *), NULL);
663       xbt_cfg_setdefault_string(_surf_cfg_set, "path", initial_path);
664     }
665
666
667     surf_config_cmd_line(argc, argv);
668
669     _surf_init_status = 1;
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
747   /* ********************************************************************* */
748   /* TUTORIAL: New model                                                   */
749   int new_model_id = -1;
750   char *new_model_name = NULL;
751   new_model_name = xbt_cfg_get_string(_surf_cfg_set, "new_model/model");
752   XBT_DEBUG("Call new model_init");
753   new_model_id = find_model_description(surf_new_model_description, new_model_name);
754   surf_new_model_description[new_model_id].model_init_preparse();
755   /* ********************************************************************* */
756 }