* Our own implementation of getline is renamed xbt_getline, and gets
used even if the OS provide a getline(). This should reduce the
configuration complexity by using the same code on all platforms.
+ * new xbt_cfg_elm_boolean type
Java:
* Reintegrate Java to the main archive as desynchronizing these
version of MPE.
- Bug Fix: the compute part of the reduce action is now taken into account.
+ PLATFORM:
+ * Handle units for values (10ms, 10kiloflops, 10Bps, …)
-- $date Da SimGrid team <simgrid-devel@lists.gforge.inria.fr>
SimGrid (3.9) stable; urgency=low
double val);
XBT_PUBLIC(void) xbt_cfg_set_string(xbt_cfg_t cfg, const char *name,
const char *val);
+XBT_PUBLIC(void) xbt_cfg_set_boolean(xbt_cfg_t cfg, const char *name, const char *val);
XBT_PUBLIC(void) xbt_cfg_set_peer(xbt_cfg_t cfg, const char *name,
const char *peer, int port);
XBT_PUBLIC(void*) xbt_cfg_set_as_string(xbt_cfg_t cfg, const char *name, const char *val);
double val);
XBT_PUBLIC(void) xbt_cfg_setdefault_string(xbt_cfg_t cfg, const char *name,
const char *val);
+XBT_PUBLIC(void) xbt_cfg_setdefault_boolean(xbt_cfg_t cfg, const char *name,
+ const char *val);
XBT_PUBLIC(void) xbt_cfg_setdefault_peer(xbt_cfg_t cfg, const char *name,
const char *host, int port);
double val);
XBT_PUBLIC(void) xbt_cfg_rm_string(xbt_cfg_t cfg, const char *name,
const char *val);
+XBT_PUBLIC(void) xbt_cfg_rm_boolean(xbt_cfg_t cfg, const char *name, int val);
XBT_PUBLIC(void) xbt_cfg_rm_peer(xbt_cfg_t cfg, const char *name,
const char *peer, int port);
/**< double */
xbt_cfgelm_string,
/**< char* */
+ xbt_cfgelm_boolean, /**< int */
xbt_cfgelm_peer, /**< both a char* (representing the peername) and an integer (representing the port) */
xbt_cfgelm_any, /* not shown to users to prevent errors */
xbt_cfgelm_type_count
} e_xbt_cfgelm_type_t;
+/** Boolean possible values **/
+
+struct xbt_boolean_couple {
+ const char *true_val;
+ const char *false_val;
+};
+
+
+
+
/** \brief Callback types. They get the name of the modified entry, and the position of the changed value */
typedef void (*xbt_cfg_cb_t) (const char *, int);
XBT_PUBLIC(int) xbt_cfg_get_int(xbt_cfg_t cfg, const char *name);
XBT_PUBLIC(double) xbt_cfg_get_double(xbt_cfg_t cfg, const char *name);
XBT_PUBLIC(char *) xbt_cfg_get_string(xbt_cfg_t cfg, const char *name);
+XBT_PUBLIC(int) xbt_cfg_get_boolean(xbt_cfg_t cfg, const char *name);
XBT_PUBLIC(void) xbt_cfg_get_peer(xbt_cfg_t cfg, const char *name,
char **peer, int *port);
XBT_PUBLIC(xbt_dynar_t) xbt_cfg_get_dynar(xbt_cfg_t cfg, const char *name);
int pos);
XBT_PUBLIC(char *) xbt_cfg_get_string_at(xbt_cfg_t cfg, const char *name,
int pos);
+XBT_PUBLIC(int) xbt_cfg_get_boolean_at(xbt_cfg_t cfg, const char *name,
+ int pos);
XBT_PUBLIC(void) xbt_cfg_get_peer_at(xbt_cfg_t cfg, const char *name,
int pos, char **peer, int *port);
XBT_PUBLIC(int) sg_cfg_get_int(const char* name);
XBT_PUBLIC(double) sg_cfg_get_double(const char* name);
XBT_PUBLIC(char*) sg_cfg_get_string(const char* name);
+XBT_PUBLIC(int) sg_cfg_get_boolean(const char* name);
XBT_PUBLIC(void) sg_cfg_get_peer(const char *name, char **peer, int *port);
XBT_PUBLIC(xbt_dynar_t) sg_cfg_get_dynar(const char* name);
if (_sg_init_status && !_sg_do_model_check) {
xbt_die("You are specifying a checkpointing value after the initialization (through MSG_config?), but model-checking was not activated at config time (through --cfg=model-check:1). This won't work, sorry.");
}
- _sg_mc_checkpoint = xbt_cfg_get_int(_sg_cfg_set, name);
+ _sg_mc_checkpoint = xbt_cfg_get_boolean(_sg_cfg_set, name);
}
void _mc_cfg_cb_property(const char *name, int pos) {
if (_sg_init_status && !_sg_do_model_check) {
if (_sg_init_status && !_sg_do_model_check) {
xbt_die("You are specifying a value to enable/disable timeout for wait requests after the initialization (through MSG_config?), but model-checking was not activated at config time (through --cfg=model-check:1). This won't work, sorry.");
}
- _sg_mc_timeout= xbt_cfg_get_int(_sg_cfg_set, name);
+ _sg_mc_timeout= xbt_cfg_get_boolean(_sg_cfg_set, name);
}
void _mc_cfg_cb_max_depth(const char *name, int pos) {
static void _sg_cfg_cb_model_check(const char *name, int pos)
{
#ifdef HAVE_MC
- _sg_do_model_check = xbt_cfg_get_int(_sg_cfg_set, name);
+ _sg_do_model_check = xbt_cfg_get_boolean(_sg_cfg_set, name);
#else
- if (xbt_cfg_get_int(_sg_cfg_set, name)) {
+ if (xbt_cfg_get_boolean(_sg_cfg_set, name)) {
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");
}
#endif
static void _sg_cfg_cb_verbose_exit(const char *name, int pos)
{
- _sg_do_verbose_exit = xbt_cfg_get_int(_sg_cfg_set, name);
+ _sg_do_verbose_exit = xbt_cfg_get_boolean(_sg_cfg_set, name);
}
static void _sg_cfg_cb__surf_network_coordinates(const char *name,
int pos)
{
- char *val = xbt_cfg_get_string(_sg_cfg_set, name);
- if (!strcmp(val, "yes")) {
+ int val = xbt_cfg_get_boolean(_sg_cfg_set, name);
+ if (val) {
if (!COORD_HOST_LEVEL) {
COORD_HOST_LEVEL = xbt_lib_add_level(host_lib,xbt_dynar_free_voidp);
COORD_ASR_LEVEL = xbt_lib_add_level(as_router_lib,xbt_dynar_free_voidp);
}
- } else if (!strcmp(val, "no")) {
+ } else
if (COORD_HOST_LEVEL)
xbt_die("Setting of whether to use coordinate cannot be disabled once set.");
- } else {
- xbt_die("Command line setting of whether to use coordinates must be either \"yes\" or \"no\"");
- }
}
static void _sg_cfg_cb_surf_nthreads(const char *name, int pos)
static void _sg_cfg_cb__surf_network_crosstraffic(const char *name,
int pos)
{
- sg_network_crosstraffic = xbt_cfg_get_int(_sg_cfg_set, name);
+ sg_network_crosstraffic = xbt_cfg_get_boolean(_sg_cfg_set, name);
}
#ifdef HAVE_GTNETS
xbt_cfgelm_string, NULL, 0, 0,
_sg_cfg_cb__surf_path, NULL);
- default_value_int = 0;
+ default_value = xbt_strdup("off");
xbt_cfg_register(&_sg_cfg_set, "cpu/maxmin_selective_update",
- "Update the constraint set propagating recursively to others constraints (1 by default when optim is set to lazy)",
- xbt_cfgelm_int, &default_value_int, 0, 1,
+ "Update the constraint set propagating recursively to others constraints (off by default when optim is set to lazy)",
+ xbt_cfgelm_boolean, &default_value, 0, 1,
NULL, NULL);
- default_value_int = 0;
+ default_value = xbt_strdup("off");
xbt_cfg_register(&_sg_cfg_set, "network/maxmin_selective_update",
- "Update the constraint set propagating recursively to others constraints (1 by default when optim is set to lazy)",
- xbt_cfgelm_int, &default_value_int, 0, 1,
+ "Update the constraint set propagating recursively to others constraints (off by default when optim is set to lazy)",
+ xbt_cfgelm_boolean, &default_value, 0, 1,
NULL, NULL);
#ifdef HAVE_MC
/* do model-checking */
+ default_value = xbt_strdup("off");
xbt_cfg_register(&_sg_cfg_set, "model-check",
"Verify the system through model-checking instead of simulating it (EXPERIMENTAL)",
- xbt_cfgelm_int, NULL, 0, 1,
+ xbt_cfgelm_boolean, NULL, 0, 1,
_sg_cfg_cb_model_check, NULL);
- xbt_cfg_setdefault_int(_sg_cfg_set, "model-check", 0);
+ xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check", default_value);
/* do stateful model-checking */
+ default_value = xbt_strdup("off");
xbt_cfg_register(&_sg_cfg_set, "model-check/checkpoint",
- "Specify the amount of steps between checkpoints during stateful model-checking (default: 0 => stateless verification). "
- "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.",
- xbt_cfgelm_int, NULL, 0, 1,
+ "Specify the amount of steps between checkpoints during stateful model-checking (default: off => stateless verification). "
+ "If value=on, one checkpoint is saved for each step => faster verification, but huge memory consumption; higher values are good compromises between speed and memory consumption.",
+ xbt_cfgelm_boolean, NULL, 0, 1,
_mc_cfg_cb_checkpoint, NULL);
- xbt_cfg_setdefault_int(_sg_cfg_set, "model-check/checkpoint", 0);
+ xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check/checkpoint", default_value);
/* do liveness model-checking */
xbt_cfg_register(&_sg_cfg_set, "model-check/property",
xbt_cfg_setdefault_string(_sg_cfg_set, "model-check/reduction", "dpor");
/* Enable/disable timeout for wait requests with model-checking */
+ default_value = xbt_strdup("off");
xbt_cfg_register(&_sg_cfg_set, "model-check/timeout",
"Enable/Disable timeout for wait requests",
- xbt_cfgelm_int, NULL, 0, 1,
+ xbt_cfgelm_boolean, NULL, 0, 1,
_mc_cfg_cb_timeout, NULL);
- xbt_cfg_setdefault_int(_sg_cfg_set, "model-check/timeout", 0);
+ xbt_cfg_setdefault_boolean(_sg_cfg_set, "model-check/timeout", default_value);
/* Set max depth exploration */
xbt_cfg_register(&_sg_cfg_set, "model-check/max_depth",
#endif
/* do verbose-exit */
- default_value_int = 1;
+ default_value = xbt_strdup("on");
xbt_cfg_register(&_sg_cfg_set, "verbose-exit",
"Activate the \"do nothing\" mode in Ctrl-C",
- xbt_cfgelm_int, &default_value_int, 0, 1,
+ xbt_cfgelm_boolean, &default_value, 0, 1,
_sg_cfg_cb_verbose_exit, NULL);
default_value = xbt_strdup("no");
xbt_cfg_register(&_sg_cfg_set, "network/coordinates",
"\"yes\" or \"no\", specifying whether we use a coordinate-based routing (as Vivaldi)",
- xbt_cfgelm_string, &default_value, 1, 1,
+ xbt_cfgelm_boolean, &default_value, 1, 1,
_sg_cfg_cb__surf_network_coordinates, NULL);
- xbt_cfg_setdefault_string(_sg_cfg_set, "network/coordinates", default_value);
+ xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/coordinates", default_value);
- default_value_int = 0;
+ default_value = xbt_strdup("no");
xbt_cfg_register(&_sg_cfg_set, "network/crosstraffic",
"Activate the interferences between uploads and downloads for fluid max-min models (LV08, CM02)",
- xbt_cfgelm_int, &default_value_int, 0, 1,
+ xbt_cfgelm_boolean, &default_value, 0, 1,
_sg_cfg_cb__surf_network_crosstraffic, NULL);
- xbt_cfg_setdefault_int(_sg_cfg_set, "network/crosstraffic", default_value_int);
+ xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/crosstraffic", default_value);
#ifdef HAVE_GTNETS
xbt_cfg_register(&_sg_cfg_set, "gtnets/jitter",
xbt_cfgelm_double, &default_reference_speed, 1, 1, NULL,
NULL);
- int default_display_timing = 0;
+ default_value = xbt_strdup("no");
xbt_cfg_register(&_sg_cfg_set, "smpi/display_timing",
"Boolean indicating whether we should display the timing after simulation.",
- xbt_cfgelm_int, &default_display_timing, 1, 1, NULL,
+ xbt_cfgelm_boolean, &default_value, 1, 1, NULL,
NULL);
+ xbt_cfg_setdefault_boolean(_sg_cfg_set, "smpi/display_timing", default_value);
double default_threshold = 1e-6;
xbt_cfg_register(&_sg_cfg_set, "smpi/cpu_threshold",
{
return xbt_cfg_get_string(_sg_cfg_set,name);
}
+int sg_cfg_get_boolean(const char* name)
+{
+ return xbt_cfg_get_boolean(_sg_cfg_set,name);
+}
void sg_cfg_get_peer(const char *name, char **peer, int *port)
{
xbt_cfg_get_peer(_sg_cfg_set,name, peer, port);
else
SIMIX_run();
- if (sg_cfg_get_int("smpi/display_timing"))
+ if (sg_cfg_get_boolean("smpi/display_timing"))
XBT_INFO("Simulation time: %g seconds.", SIMIX_get_clock());
smpi_global_destroy();
char *optim = xbt_cfg_get_string(_sg_cfg_set, "cpu/optim");
int select =
- xbt_cfg_get_int(_sg_cfg_set, "cpu/maxmin_selective_update");
+ xbt_cfg_get_boolean(_sg_cfg_set, "cpu/maxmin_selective_update");
surf_cpu_model = surf_model_init();
{
char *optim = xbt_cfg_get_string(_sg_cfg_set, "network/optim");
int select =
- xbt_cfg_get_int(_sg_cfg_set, "network/maxmin_selective_update");
+ xbt_cfg_get_boolean(_sg_cfg_set, "network/maxmin_selective_update");
if (!strcmp(optim, "Full")) {
surf_network_model->model_private->update_mechanism = UM_FULL;
void surf_workstation_model_init_current_default(void)
{
surf_workstation_model_init_internal();
- xbt_cfg_setdefault_int(_sg_cfg_set, "network/crosstraffic", 1);
+ xbt_cfg_setdefault_boolean(_sg_cfg_set, "network/crosstraffic", xbt_strdup("yes"));
surf_cpu_model_init_Cas01();
surf_network_model_init_LegrandVelho();
} s_xbt_cfgelm_t, *xbt_cfgelm_t;
static const char *xbt_cfgelm_type_name[xbt_cfgelm_type_count] =
- { "int", "double", "string", "peer", "any" };
+ { "int", "double", "string", "boolean", "peer", "any" };
+
+const struct xbt_boolean_couple xbt_cfgelm_boolean_values[] = {
+ { "yes", "no"},
+ { "on", "off"},
+ {"true", "false"},
+ { "1", "0"},
+ { NULL, NULL}
+};
/* Internal stuff used in cache to free a variable */
static void xbt_cfgelm_free(void *data);
}
break;
+ case xbt_cfgelm_boolean:
+ for (i = 0; i < size; i++) {
+ ival = xbt_dynar_get_as(variable->content, i, int);
+ printf("%s %d\n", indent, ival);
+ }
+ break;
+
case xbt_cfgelm_peer:
for (i = 0; i < size; i++) {
hval = xbt_dynar_get_as(variable->content, i, xbt_peer_t);
xbt_dynar_push(res->content, default_value);
break;
+ case xbt_cfgelm_boolean:
+ res->content = xbt_dynar_new(sizeof(int), NULL);
+ if (default_value)
+ xbt_dynar_push(res->content, default_value);
+ break;
+
case xbt_cfgelm_peer:
res->content = xbt_dynar_new(sizeof(xbt_peer_t), xbt_peer_free_voidp);
if (default_value)
printf("'%s'%s", xbt_dynar_get_as(variable->content, i, char *), sep);
break;
+ case xbt_cfgelm_boolean:
+ printf("'%d'%s", xbt_dynar_get_as(variable->content, i, int), sep);
+ break;
+
case xbt_cfgelm_peer: {
xbt_peer_t hval = xbt_dynar_get_as(variable->content, i, xbt_peer_t);
printf("%s:%d%s", hval->name, hval->port, sep);
xbt_cfg_set_double(cfg, name, d);
break;
+ case xbt_cfgelm_boolean:
+ str = va_arg(pa, char *);
+ xbt_cfg_set_boolean(cfg, name, str);
+ break;
+
default:
xbt_die("Config element variable %s not valid (type=%d)", name, (int)type);
}
xbt_cfg_set_double(cfg, key, d); /* throws */
break;
+ case xbt_cfgelm_boolean:
+ xbt_cfg_set_boolean(cfg, key, value); /* throws */
+ break;
+
case xbt_cfgelm_peer:
val = xbt_strdup(value);
str = val;
name, val);
}
+
+/** @brief Set an boolean value to \a name within \a cfg if it wasn't changed yet
+ *
+ * This is useful to change the default value of a variable while allowing
+ * users to override it with command line arguments
+ */
+void xbt_cfg_setdefault_boolean(xbt_cfg_t cfg, const char *name, const char *val)
+{
+ xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_boolean);
+
+ if (variable->isdefault){
+ xbt_cfg_set_boolean(cfg, name, val);
+ variable->isdefault = 1;
+ }
+ else
+ XBT_DEBUG
+ ("Do not override configuration variable '%s' with value '%s' because it was already set.",
+ name, val);
+}
+
/** @brief Set a peer value to \a name within \a cfg if it wasn't changed yet
*
* This is useful to change the default value of a variable while allowing
variable->isdefault = 0;
}
+/** @brief Set or add a boolean value to \a name within \a cfg
+ *
+ * \arg cfg the config set
+ * \arg name the name of the variable
+ * \arg val the value of the variable
+ */
+void xbt_cfg_set_boolean(xbt_cfg_t cfg, const char *name, const char *val)
+{
+ xbt_cfgelm_t variable;
+ int i, bval;
+
+ XBT_VERB("Configuration setting: %s=%s", name, val);
+ variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_boolean);
+
+ for (i = 0; xbt_cfgelm_boolean_values[i].true_val != NULL; i++) {
+ if (strcmp(val, xbt_cfgelm_boolean_values[i].true_val) == 0){
+ bval = 1;
+ break;
+ }
+ if (strcmp(val, xbt_cfgelm_boolean_values[i].false_val) == 0){
+ bval = 0;
+ break;
+ }
+ }
+ if (xbt_cfgelm_boolean_values[i].true_val == NULL) {
+ xbt_die("Value of option '%s' not valid. Should be a boolean (yes,no,on,off,true,false,0,1)", val);
+ }
+
+ if (variable->max == 1) {
+ if (variable->cb_rm && !xbt_dynar_is_empty(variable->content))
+ variable->cb_rm(name, 0);
+
+ xbt_dynar_set(variable->content, 0, &bval);
+ } else {
+ if (variable->max
+ && xbt_dynar_length(variable->content) ==
+ (unsigned long) variable->max)
+ THROWF(mismatch_error, 0,
+ "Cannot add value %s to the config element %s since it's already full (size=%d)",
+ val, name, variable->max);
+
+ xbt_dynar_push(variable->content, &bval);
+ }
+
+ if (variable->cb_set)
+ variable->cb_set(name, xbt_dynar_length(variable->content) - 1);
+ variable->isdefault = 0;
+}
+
/** @brief Set or add an peer value to \a name within \a cfg
*
* \arg cfg the config set
val, name);
}
+/** @brief Remove the provided \e val boolean value from a variable
+ *
+ * \arg cfg the config set
+ * \arg name the name of the variable
+ * \arg val the value to be removed
+ */
+void xbt_cfg_rm_boolean(xbt_cfg_t cfg, const char *name, int val)
+{
+
+ xbt_cfgelm_t variable;
+ unsigned int cpt;
+ int seen;
+
+ variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_boolean);
+
+ if (xbt_dynar_length(variable->content) == variable->min)
+ THROWF(mismatch_error, 0,
+ "Cannot remove value %d from the config element %s since it's already at its minimal size (=%d)",
+ val, name, variable->min);
+
+ xbt_dynar_foreach(variable->content, cpt, seen) {
+ if (seen == val) {
+ if (variable->cb_rm)
+ variable->cb_rm(name, cpt);
+ xbt_dynar_cursor_rm(variable->content, &cpt);
+ return;
+ }
+ }
+
+ THROWF(not_found_error, 0,
+ "Can't remove the value %d of config element %s: value not found.",
+ val, name);
+}
+
/** @brief Remove the provided \e val peer value from a variable
*
* \arg cfg the config set
return xbt_dynar_get_as(variable->content, 0, char *);
}
+/** @brief Retrieve a boolean value of a variable (get a warning if not uniq)
+ *
+ * \arg cfg the config set
+ * \arg name the name of the variable
+ * \arg val the wanted value
+ *
+ * Returns the first value from the config set under the given name.
+ * If there is more than one value, it will issue a warning. Consider using
+ * xbt_cfg_get_dynar() instead.
+ *
+ * \warning the returned value is the actual content of the config set
+ */
+int xbt_cfg_get_boolean(xbt_cfg_t cfg, const char *name)
+{
+ xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_boolean);
+
+ if (xbt_dynar_length(variable->content) > 1) {
+ XBT_WARN
+ ("You asked for the first value of the config element '%s', but there is %lu values",
+ name, xbt_dynar_length(variable->content));
+ }
+
+ return xbt_dynar_get_as(variable->content, 0, int);
+}
+
/** @brief Retrieve an peer value of a variable (get a warning if not uniq)
*
* \arg cfg the config set
return xbt_dynar_get_as(variable->content, pos, char *);
}
+/** @brief Retrieve one of the boolean value of a variable */
+int xbt_cfg_get_boolean_at(xbt_cfg_t cfg, const char *name, int pos)
+{
+
+ xbt_cfgelm_t variable = xbt_cfgelm_get(cfg, name, xbt_cfgelm_boolean);
+ return xbt_dynar_get_as(variable->content, pos, int);
+}
+
/** @brief Retrieve one of the peer value of a variable */
void
xbt_cfg_get_peer_at(xbt_cfg_t cfg, const char *name, int pos,