SimGrid  3.11
Versatile Simulation of Distributed Systems
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Modules Pages
Configuration support

Changing the configuration of SimGrid components (grounding feature) More...

Modules

 User interface: changing values
 
 Configuration type declaration and memory management
 
 Registering stuff
 
 Getting the stored values
 

Detailed Description

Changing the configuration of SimGrid components (grounding feature)

All modules of the SimGrid toolkit can be configured with this API. User modules and libraries can also use these facilities to handle their own configuration.

A configuration set contain several variables which have a unique name in the set and can take a given type of value. For example, it may contain a size variable, accepting int values.

It is impossible to set a value to a variable which has not been registered before. Usually, the module registers all the options it accepts in the configuration set, during its initialization and user code then set and unset values.

The easiest way to register a variable is to use the xbt_str_register_str function, which accepts a string representation of the config element descriptor. The syntax is the following:

<name>:<min nb>_to_<max nb>_<type>

For example, size:1_to_1_int describes a variable called size which must take exactly one value, and the value being an integer. Set the maximum to 0 to disable the upper bound on data count.

Another example could be outputfiles:0_to_10_string which describes a variable called outputfiles and which can take between 0 and 10 strings as value.

To some extend, configuration sets can be seen as typed hash structures.

Example of use

First, let's create a configuration set with some registered variables. This must be done by the configurable library before the user interactions.

static xbt_cfg_t make_set()
{
xbt_cfg_t set = NULL;
xbt_log_threshold_set(&_XBT_LOGV(xbt_cfg), xbt_log_priority_critical);
xbt_cfg_register_str(&set, "speed:1_to_2_int");
xbt_cfg_register_str(&set, "peername:1_to_1_string");
xbt_cfg_register_str(&set, "user:1_to_10_string");
return set;
} /* end_of_make_set */

Now, set and get a single value

int ival;
xbt_cfg_t myset = make_set();
xbt_cfg_set_parse(myset, "peername:toto:42 speed:42");
ival = xbt_cfg_get_int(myset, "speed");
if (ival != 42)
xbt_test_fail("Speed value = %d, I expected 42", ival);
xbt_cfg_free(&myset);

And now, set and get a multiple value

xbt_cfg_t myset = make_set();
"peername:veloce user:foo\nuser:bar\tuser:toto");
xbt_cfg_set_parse(myset, "speed:42");
xbt_cfg_check(myset);
dyn = xbt_cfg_get_dynar(myset, "user");
if (xbt_dynar_length(dyn) != 3)
xbt_test_fail("Dynar length = %lu, I expected 3",
if (strcmp(xbt_dynar_get_as(dyn, 0, char *), "foo"))
xbt_test_fail("Dynar[0] = %s, I expected foo",
xbt_dynar_get_as(dyn, 0, char *));
if (strcmp(xbt_dynar_get_as(dyn, 1, char *), "bar"))
xbt_test_fail("Dynar[1] = %s, I expected bar",
xbt_dynar_get_as(dyn, 1, char *));
if (strcmp(xbt_dynar_get_as(dyn, 2, char *), "toto"))
xbt_test_fail("Dynar[2] = %s, I expected toto",
xbt_dynar_get_as(dyn, 2, char *));
xbt_cfg_free(&myset);

All those functions throws mismatch_error if asked to deal with an unregistered variable.

xbt_cfg_t myset = make_set();
TRY {
xbt_cfg_set_parse(myset, "color:blue");
}
CATCH(e) {
}
xbt_cfg_free(&myset);