Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Added a gtnets_jitter_seed parameter enabling jitted repeatable experiments, activate...
[simgrid.git] / src / surf / surf_config.c
1 /*      $Id$     */
2
3 /* Copyright (c) 2009 The SimGrid team. All rights reserved.                */
4
5 /* This program is free software; you can redistribute it and/or modify it
6  * under the terms of the license (GNU LGPL) which comes with this package. */
7
8 /* surf_config: configuration infrastructure for the simulation world       */
9
10 #include "xbt/config.h"
11 #include "xbt/str.h"
12 #include "surf/surf_private.h"
13
14 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_config, surf,
15                                 "About the configuration of surf (and the rest of the simulation)");
16
17 xbt_cfg_t _surf_cfg_set = NULL;
18
19
20 /* Parse the command line, looking for options */
21 static void surf_config_cmd_line(int *argc, char **argv)
22 {
23   int i, j;
24   char *opt;
25
26   for (i = 1; i < *argc; i++) {
27     int remove_it = 0;
28     if (!strncmp(argv[i], "--cfg=", strlen("--cfg="))) {
29       opt = strchr(argv[i], '=');
30       opt++;
31
32       xbt_cfg_set_parse(_surf_cfg_set, opt);
33       DEBUG1("Did apply '%s' as config setting", opt);
34       remove_it = 1;
35     } else if (!strncmp(argv[i], "--cfg-help", strlen("--cfg-help") + 1) ||
36                !strncmp(argv[i], "--help", strlen("--help") + 1)) {
37       printf
38         ("Description of the configuration accepted by this simulator:\n");
39       xbt_cfg_help(_surf_cfg_set);
40       remove_it = 1;
41       exit(0);
42     }
43     if (remove_it) {            /*remove this from argv */
44       for (j = i + 1; j < *argc; j++) {
45         argv[j - 1] = argv[j];
46       }
47
48       argv[j - 1] = NULL;
49       (*argc)--;
50       i--;                      /* compensate effect of next loop incrementation */
51     }
52   }
53 }
54
55
56 int _surf_init_status = 0;      /* 0: beginning of time;
57                                    1: pre-inited (cfg_set created);
58                                    2: inited (running) */
59
60 /* callback of the workstation_model variable */
61 static void _surf_cfg_cb__workstation_model(const char *name, int pos)
62 {
63   char *val;
64
65   xbt_assert0(_surf_init_status < 2,
66               "Cannot change the model after the initialization");
67
68   val = xbt_cfg_get_string(_surf_cfg_set, name);
69   /* New Module missing */
70
71   find_model_description(surf_workstation_model_description, val);
72 }
73
74 /* callback of the cpu_model variable */
75 static void _surf_cfg_cb__cpu_model(const char *name, int pos)
76 {
77   char *val;
78
79   xbt_assert0(_surf_init_status < 2,
80               "Cannot change the model after the initialization");
81
82   val = xbt_cfg_get_string(_surf_cfg_set, name);
83   /* New Module missing */
84   find_model_description(surf_cpu_model_description, val);
85 }
86
87 /* callback of the workstation_model variable */
88 static void _surf_cfg_cb__network_model(const char *name, int pos)
89 {
90   char *val;
91
92   xbt_assert0(_surf_init_status < 2,
93               "Cannot change the model after the initialization");
94
95   val = xbt_cfg_get_string(_surf_cfg_set, name);
96   /* New Module missing */
97   find_model_description(surf_network_model_description, val);
98 }
99
100 /* callback of the tcp gamma variable */
101 static void _surf_cfg_cb__tcp_gamma(const char *name, int pos)
102 {
103   sg_tcp_gamma = xbt_cfg_get_double(_surf_cfg_set, name);
104 }
105
106 static void _surf_cfg_cb__surf_path(const char *name, int pos)
107 {
108   char *path = xbt_cfg_get_string_at(_surf_cfg_set, name, pos);
109   xbt_dynar_push(surf_path, &path);
110 }
111
112 static void _surf_cfg_cb__surf_maxmin_selective_update(const char *name, int pos)
113 {
114         sg_maxmin_selective_update = xbt_cfg_get_int(_surf_cfg_set, name);
115 }
116
117 #ifdef HAVE_GTNETS
118 static void _surf_cfg_cb__gtnets_jitter(const char *name, int pos){
119         sg_gtnets_jitter = xbt_cfg_get_double(_surf_cfg_set, name);
120 }
121 static void _surf_cfg_cb__gtnets_jitter_seed(const char *name, int pos){
122         sg_gtnets_jitter_seed = xbt_cfg_get_int(_surf_cfg_set, name);
123 }
124 #endif
125
126 /* create the config set, register what should be and parse the command line*/
127 void surf_config_init(int *argc, char **argv)
128 {
129
130   /* Create the configuration support */
131   if (_surf_init_status == 0) { /* Only create stuff if not already inited */
132     _surf_init_status = 1;
133
134     char *description = xbt_malloc(1024), *p = description;
135     char *default_value;
136         int default_value_int;
137         int default_value_int_seed;
138     int i;
139
140     sprintf(description, "The model to use for the CPU. Possible values: ");
141     p = description;
142     while (*(++p) != '\0');
143     for (i = 0; surf_cpu_model_description[i].name; i++)
144       p +=
145         sprintf(p, "%s%s", (i == 0 ? "" : ", "),
146                 surf_cpu_model_description[i].name);
147     default_value = xbt_strdup("Cas01");
148     xbt_cfg_register(&_surf_cfg_set,
149                      "cpu_model", description, xbt_cfgelm_string,
150                      &default_value, 1, 1, &_surf_cfg_cb__cpu_model, NULL);
151
152     sprintf(description,
153             "The model to use for the network. Possible values: ");
154     p = description;
155     while (*(++p) != '\0');
156     for (i = 0; surf_network_model_description[i].name; i++)
157       p +=
158         sprintf(p, "%s%s", (i == 0 ? "" : ", "),
159                 surf_network_model_description[i].name);
160     default_value = xbt_strdup("LV08");
161     xbt_cfg_register(&_surf_cfg_set,
162                      "network_model", description, xbt_cfgelm_string,
163                      &default_value, 1, 1, &_surf_cfg_cb__network_model,
164                      NULL);
165
166     sprintf(description,
167             "The model to use for the workstation. Possible values: ");
168     p = description;
169     while (*(++p) != '\0');
170     for (i = 0; surf_workstation_model_description[i].name; i++)
171       p +=
172         sprintf(p, "%s%s", (i == 0 ? "" : ", "),
173                 surf_workstation_model_description[i].name);
174     default_value = xbt_strdup("CLM03");
175     xbt_cfg_register(&_surf_cfg_set,
176                      "workstation_model", description, xbt_cfgelm_string,
177                      &default_value, 1, 1, &_surf_cfg_cb__workstation_model,
178                      NULL);
179
180     xbt_free(description);
181
182     default_value = xbt_strdup("Full");
183     xbt_cfg_register(&_surf_cfg_set, "routing",
184                      "Model to use to store the routing information",
185                      xbt_cfgelm_string, &default_value, 1, 1, NULL,
186                      NULL);
187
188     xbt_cfg_register(&_surf_cfg_set, "TCP_gamma",
189                      "Size of the biggest TCP window", xbt_cfgelm_double,
190                      NULL, 1, 1, _surf_cfg_cb__tcp_gamma, NULL);
191     xbt_cfg_set_double(_surf_cfg_set, "TCP_gamma", 20000.0);
192
193     xbt_cfg_register(&_surf_cfg_set, "path",
194                      "Lookup path for inclusions in platform and deployment XML files",
195                      xbt_cfgelm_string, NULL, 0, 0, _surf_cfg_cb__surf_path,
196                      NULL);
197
198                 default_value_int = 0;
199     xbt_cfg_register(&_surf_cfg_set, "maxmin_selective_update",
200                      "Update the constraint set propagating recursively to others constraints",
201                      xbt_cfgelm_int, &default_value_int, 0, 1, _surf_cfg_cb__surf_maxmin_selective_update, NULL);
202
203 #ifdef HAVE_GTNETS
204     xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter",
205                      "Double value to oscillate the link latency, uniformly in random interval [-latency*gtnets_jitter,latency*gtnets_jitter)", xbt_cfgelm_double,
206                      NULL, 1, 1, _surf_cfg_cb__gtnets_jitter, NULL);
207     xbt_cfg_set_double(_surf_cfg_set, "gtnets_jitter", 0.0);
208
209     default_value_int_seed = 10;
210     xbt_cfg_register(&_surf_cfg_set, "gtnets_jitter_seed",
211                      "Use a positive seed to reproduce jitted results, value must be in [1,1e8], default is 10",
212                      xbt_cfgelm_int, &default_value_int_seed, 0, 1, _surf_cfg_cb__gtnets_jitter_seed, NULL);
213 #endif
214
215     if (!surf_path) {
216       /* retrieves the current directory of the        current process */
217       const char *initial_path = __surf_get_initial_path();
218       xbt_assert0((initial_path),
219                   "__surf_get_initial_path() failed! Can't resolves current Windows directory");
220
221       surf_path = xbt_dynar_new(sizeof(char *), NULL);
222       xbt_cfg_set_string(_surf_cfg_set, "path", initial_path);
223     }
224
225
226     surf_config_cmd_line(argc, argv);
227   }
228 }
229
230 void surf_config_finalize(void)
231 {
232   if (!_surf_init_status)
233     return;                     /* Not initialized yet. Nothing to do */
234
235   xbt_cfg_free(&_surf_cfg_set);
236   _surf_init_status = 0;
237 }
238
239 void surf_config_models_setup(const char *platform_file)
240 {
241   char *workstation_model_name;
242   int workstation_id = -1;
243
244   surf_timer_model_init(platform_file);
245
246   workstation_model_name =
247     xbt_cfg_get_string(_surf_cfg_set, "workstation_model");
248   char *network_model_name = xbt_cfg_get_string(_surf_cfg_set, "network_model");
249   char *cpu_model_name = xbt_cfg_get_string(_surf_cfg_set, "cpu_model");
250
251   if ((strcmp(network_model_name,"LV08") || strcmp(cpu_model_name,"Cas01"))
252       && !strcmp(workstation_model_name, "CLM03")){
253     const char *val = "compound";
254     INFO0("Switching workstation model to compound since you changed the network and/or cpu model(s)");
255     xbt_cfg_set_string(_surf_cfg_set,"workstation_model",val);
256     workstation_model_name = (char*)"compound";
257   }
258
259   DEBUG1("Workstation model: %s", workstation_model_name);
260   workstation_id =
261     find_model_description(surf_workstation_model_description,
262                            workstation_model_name);
263   if (!strcmp(workstation_model_name, "compound")) {
264     int network_id = -1;
265     int cpu_id = -1;
266
267     xbt_assert0(cpu_model_name,
268         "Set a cpu model to use with the 'compound' workstation model");
269
270     xbt_assert0(network_model_name,
271         "Set a network model to use with the 'compound' workstation model");
272
273     network_id =
274       find_model_description(surf_network_model_description,
275                              network_model_name);
276     cpu_id =
277       find_model_description(surf_cpu_model_description, cpu_model_name);
278
279     surf_cpu_model_description[cpu_id].model_init_preparse(platform_file);
280     surf_network_model_description[network_id].
281       model_init_preparse(platform_file);
282   }
283
284   DEBUG0("Call workstation_model_init");
285   surf_workstation_model_description[workstation_id].model_init_preparse
286     (platform_file);
287 }
288
289 void surf_config_models_create_elms(void)
290 {
291   char *workstation_model_name =
292     xbt_cfg_get_string(_surf_cfg_set, "workstation_model");
293   int workstation_id =
294     find_model_description(surf_workstation_model_description,
295                            workstation_model_name);
296   if (surf_workstation_model_description[workstation_id].
297       model_init_postparse != NULL)
298     surf_workstation_model_description[workstation_id].model_init_postparse();
299 }