Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
bring new network models to end users
[simgrid.git] / src / simix / smx_config.c
1 /* $Id$ */
2
3 /* Copyright (c) 2007 Arnaud Legrand, Bruno Donassolo.
4    All rights reserved.                                          */
5
6 /* This program is free software; you can redistribute it and/or modify it
7  * under the terms of the license (GNU LGPL) which comes with this package. */
8
9 #include "private.h"
10 #include "xbt/sysdep.h"
11 #include "xbt/log.h"
12
13 int _simix_init_status = 0; /* 0: beginning of time; 
14                              1: pre-inited (cfg_set created); 
15                              2: inited (running) */
16 xbt_cfg_t _simix_cfg_set = NULL;
17
18 /* callback of the workstation_model variable */
19 static void _simix_cfg_cb__workstation_model(const char *name, int pos) 
20 {
21   char *val;
22
23   xbt_assert0(_simix_init_status<2, "Cannot change the model after the initialization");
24   
25   val = xbt_cfg_get_string (_simix_cfg_set, name);
26   /* New Module missing */
27   xbt_assert1(!strcmp(val, "CLM03") ||
28               !strcmp(val, "KCCFLN05") ||
29               !strcmp(val, "SDP") ||
30               !strcmp(val, "Vegas") ||
31               !strcmp(val, "Reno") ||
32               !strcmp(val, "GTNets") ||
33               !strcmp(val, "compound"),
34               "Unknown workstation model: %s (choices are: 'CLM03', 'KCCFLN05', 'SDP', 'Vegas', 'Reno', 'GTNets' and 'Compound'",val);
35 }
36
37 /* callback of the cpu_model variable */
38 static void _simix_cfg_cb__cpu_model(const char *name, int pos) 
39 {
40   char *val;
41
42   xbt_assert0(_simix_init_status<2, "Cannot change the model after the initialization");
43   
44   val = xbt_cfg_get_string (_simix_cfg_set, name);
45   /* New Module missing */
46   xbt_assert1(!strcmp(val, "Cas01"),
47               "Unknown CPU model: %s (choices are: 'Cas01'",val);
48 }
49 /* callback of the workstation_model variable */
50 static void _simix_cfg_cb__network_model(const char *name, int pos) 
51 {
52   char *val;
53
54   xbt_assert0(_simix_init_status<2, "Cannot change the model after the initialization");
55   
56   val = xbt_cfg_get_string (_simix_cfg_set, name);
57   /* New Module missing */
58   xbt_assert1(!strcmp(val, "CM02") ||
59               !strcmp(val, "GTNets") ||
60               !strcmp(val, "SDP") ||
61               !strcmp(val, "Vegas") ||
62               !strcmp(val, "Reno"),
63               "Unknown workstation model: %s (choices are: 'CM02', 'GTNets', 'SDP', 'Vegas' and 'Reno'",val);
64 }
65
66 /* create the config set and register what should be */
67 void simix_config_init(void) 
68 {
69
70   if (_simix_init_status) 
71     return; /* Already inited, nothing to do */
72
73   _simix_init_status = 1;
74   _simix_cfg_set = xbt_cfg_new();
75   
76   xbt_cfg_register (_simix_cfg_set, 
77                     "workstation_model", xbt_cfgelm_string, 1,1,
78                     &_simix_cfg_cb__workstation_model,NULL);
79
80   xbt_cfg_register (_simix_cfg_set, 
81                     "cpu_model", xbt_cfgelm_string, 1,1,
82                     &_simix_cfg_cb__cpu_model,NULL); 
83   xbt_cfg_register (_simix_cfg_set, 
84                     "network_model", xbt_cfgelm_string, 1,1,
85                     &_simix_cfg_cb__network_model,NULL);
86                    
87   xbt_cfg_set_string(_simix_cfg_set,"workstation_model", "KCCFLN05");
88 }
89
90 void simix_config_finalize(void) 
91 {
92
93   if (!_simix_init_status) 
94     return; /* Not initialized yet. Nothing to do */
95
96   xbt_cfg_free(&_simix_cfg_set);
97   _simix_init_status = 0;
98 }
99
100 /** \brief Set a configuration variable
101  * 
102  * Currently existing configuration variable:
103  *   - workstation_model (string): Model of workstation to use.  
104  *     Possible values (defaults to "KCCFLN05"):
105  *     - "CLM03": realistic TCP behavior + basic CPU model (see [CML03 at CCGrid03]) + support for parallel tasks
106  *     - "KCCFLN05": realistic TCP behavior + basic CPU model (see [CML03 at CCGrid03]) + failure handling + interference between communications and computations if precised in the platform file.
107  * 
108  *      \param name Configuration variable name that will change.
109  *      \param pa A va_list with the others parameters
110  */
111 void SIMIX_config(const char *name, va_list pa) 
112 {
113   if (!_simix_init_status) {
114     simix_config_init();
115   }
116   xbt_cfg_set_vargs(_simix_cfg_set,name,pa);
117 }