Logo AND Algorithmique Numérique Distribuée

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