printf("\n");
model_help("network", surf_network_model_description);
printf("\nLong description of all optimization levels accepted by the models of this simulator:\n");
- for (int k = 0; surf_optimization_mode_description[k].name; k++)
- printf(" %s: %s\n",
- surf_optimization_mode_description[k].name,
- surf_optimization_mode_description[k].description);
+ for (auto const& item : surf_optimization_mode_description)
+ printf(" %s: %s\n", item.name, item.description);
printf("Both network and CPU models have 'Lazy' as default optimization level\n\n");
shall_exit = true;
} else if (parse_args && not strcmp(argv[i], "--help-tracing")) {
return;
if (value == "help") {
- model_help("plugin", surf_plugin_description);
+ model_help("plugin", *surf_plugin_description);
exit(0);
}
- int plugin_id = find_model_description(surf_plugin_description, value);
- surf_plugin_description[plugin_id].model_init_preparse();
+ int plugin_id = find_model_description(*surf_plugin_description, value);
+ (*surf_plugin_description)[plugin_id].model_init_preparse();
}
/* callback of the host/model variable */
}
/* build description line with possible values */
-static void describe_model(char *result,int resultsize,
- const s_surf_model_description_t model_description[],
- const char *name,
- const char *description)
+static void declare_model_flag(const std::string& name, const std::string& value,
+ const std::function<void(std::string const&)>& callback,
+ const std::vector<surf_model_description_t>& model_description, const std::string& type,
+ const std::string& descr)
{
- result[0] = '\0';
- char *p = result;
- p += snprintf(result,resultsize-1, "%s. Possible values: %s", description,
- model_description[0].name ? model_description[0].name : "n/a");
- for (int i = 1; model_description[i].name; i++)
- p += snprintf(p,resultsize-(p-result)-1, ", %s", model_description[i].name);
- p += snprintf(p,resultsize-(p-result)-1, ".\n (use 'help' as a value to see the long description of each %s)", name);
-
- xbt_assert(p<result+resultsize-1,"Buffer too small to display the model description of %s",name);
+ std::string description = descr + ". Possible values: ";
+ std::string sep = "";
+ for (auto const& item : model_description) {
+ description += sep + item.name;
+ sep = ", ";
+ }
+ description += ".\n (use 'help' as a value to see the long description of each " + type + ")";
+ simgrid::config::declare_flag<std::string>(name, description, value, callback);
}
/* create the config set, register what should be and parse the command line*/
void sg_config_init(int *argc, char **argv)
{
- const int descsize = 1024;
- char description[descsize];
-
/* Create the configuration support */
if (_sg_cfg_init_status != 0) { /* Only create stuff if not already inited */
XBT_WARN("Call to sg_config_init() after initialization ignored");
}
/* Plugins configuration */
- describe_model(description, descsize, surf_plugin_description, "plugin", "The plugins");
- simgrid::config::declare_flag<std::string>("plugin", description, "", &_sg_cfg_cb__plugin);
+ declare_model_flag("plugin", "", &_sg_cfg_cb__plugin, *surf_plugin_description, "plugin", "The plugins");
- describe_model(description, descsize, surf_cpu_model_description, "model", "The model to use for the CPU");
- simgrid::config::declare_flag<std::string>("cpu/model", description, "Cas01", &_sg_cfg_cb__cpu_model);
+ declare_model_flag("cpu/model", "Cas01", &_sg_cfg_cb__cpu_model, surf_cpu_model_description, "model",
+ "The model to use for the CPU");
- describe_model(description, descsize, surf_storage_model_description, "model", "The model to use for the storage");
- simgrid::config::declare_flag<std::string>("storage/model", description, "default", &_sg_cfg_cb__storage_mode);
+ declare_model_flag("storage/model", "default", &_sg_cfg_cb__storage_mode, surf_storage_model_description, "model",
+ "The model to use for the storage");
- describe_model(description, descsize, surf_network_model_description, "model", "The model to use for the network");
- simgrid::config::declare_flag<std::string>("network/model", description, "LV08", &_sg_cfg_cb__network_model);
+ declare_model_flag("network/model", "LV08", &_sg_cfg_cb__network_model, surf_network_model_description, "model",
+ "The model to use for the network");
- describe_model(description, descsize, surf_optimization_mode_description, "optimization mode",
- "The optimization modes to use for the network");
- simgrid::config::declare_flag<std::string>("network/optim", description, "Lazy", &_sg_cfg_cb__optimization_mode);
+ declare_model_flag("network/optim", "Lazy", &_sg_cfg_cb__optimization_mode, surf_optimization_mode_description,
+ "optimization mode", "The optimization modes to use for the network");
- describe_model(description, descsize, surf_host_model_description, "model", "The model to use for the host");
- simgrid::config::declare_flag<std::string>("host/model", description, "default", &_sg_cfg_cb__host_model);
+ declare_model_flag("host/model", "default", &_sg_cfg_cb__host_model, surf_host_model_description, "model",
+ "The model to use for the host");
simgrid::config::bind_flag(sg_surf_precision, "surf/precision",
"Numerical precision used when updating simulation times (in seconds)");
std::set<std::string> watched_hosts;
extern std::map<std::string, simgrid::kernel::resource::StorageType*> storage_types;
-s_surf_model_description_t* surf_plugin_description = nullptr;
+std::vector<surf_model_description_t>* surf_plugin_description = nullptr;
+
static void XBT_ATTRIB_DESTRUCTOR(800) simgrid_free_plugin_description()
{
- xbt_free(surf_plugin_description);
+ delete surf_plugin_description;
+ surf_plugin_description = nullptr;
}
XBT_PUBLIC void simgrid_add_plugin_description(const char* name, const char* description, void_f_void_t init_fun)
{
- static int plugin_amount = 0;
-
- /* no need to check for plugin name conflict: the compiler already ensures that the generated
- * simgrid_##id##_plugin_register() is unique */
-
- plugin_amount++;
- surf_plugin_description = static_cast<s_surf_model_description_t*>(
- xbt_realloc(surf_plugin_description, sizeof(s_surf_model_description_t) * (plugin_amount + 2)));
-
- surf_plugin_description[plugin_amount - 1] = {name, description, init_fun};
- surf_plugin_description[plugin_amount] = {nullptr, nullptr, nullptr}; // this array must be null terminated
+ if (not surf_plugin_description)
+ surf_plugin_description = new std::vector<surf_model_description_t>;
+ surf_plugin_description->emplace_back(surf_model_description_t{name, description, init_fun});
}
/* Don't forget to update the option description in smx_config when you change this */
-s_surf_model_description_t surf_network_model_description[] = {
+const std::vector<surf_model_description_t> surf_network_model_description = {
{"LV08", "Realistic network analytic model (slow-start modeled by multiplying latency by 13.01, bandwidth by .97; "
"bottleneck sharing uses a payload of S=20537 for evaluating RTT). ",
&surf_network_model_init_LegrandVelho},
{"Vegas",
"Model from Steven H. Low using lagrange_solve instead of lmm_solve (experts only; check the code for more info).",
&surf_network_model_init_Vegas},
- {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
};
#if ! HAVE_SMPI
}
#endif
-s_surf_model_description_t surf_cpu_model_description[] = {
- {"Cas01", "Simplistic CPU model (time=size/power).", &surf_cpu_model_init_Cas01},
- {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
+const std::vector<surf_model_description_t> surf_cpu_model_description = {
+ {"Cas01", "Simplistic CPU model (time=size/power).", &surf_cpu_model_init_Cas01},
};
-s_surf_model_description_t surf_host_model_description[] = {
- {"default", "Default host model. Currently, CPU:Cas01 and network:LV08 (with cross traffic enabled)", &surf_host_model_init_current_default},
- {"compound", "Host model that is automatically chosen if you change the network and CPU models", &surf_host_model_init_compound},
- {"ptask_L07", "Host model somehow similar to Cas01+CM02 but allowing parallel tasks", &surf_host_model_init_ptask_L07},
- {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
+const std::vector<surf_model_description_t> surf_host_model_description = {
+ {"default", "Default host model. Currently, CPU:Cas01 and network:LV08 (with cross traffic enabled)",
+ &surf_host_model_init_current_default},
+ {"compound", "Host model that is automatically chosen if you change the network and CPU models",
+ &surf_host_model_init_compound},
+ {"ptask_L07", "Host model somehow similar to Cas01+CM02 but allowing parallel tasks",
+ &surf_host_model_init_ptask_L07},
};
-s_surf_model_description_t surf_optimization_mode_description[] = {
- {"Lazy", "Lazy action management (partial invalidation in lmm + heap in action remaining).", nullptr},
- {"TI", "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU model for now).", nullptr},
- {"Full", "Full update of remaining and variables. Slow but may be useful when debugging.", nullptr},
- {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
+const std::vector<surf_model_description_t> surf_optimization_mode_description = {
+ {"Lazy", "Lazy action management (partial invalidation in lmm + heap in action remaining).", nullptr},
+ {"TI", "Trace integration. Highly optimized mode when using availability traces (only available for the Cas01 CPU "
+ "model for now).",
+ nullptr},
+ {"Full", "Full update of remaining and variables. Slow but may be useful when debugging.", nullptr},
};
-s_surf_model_description_t surf_storage_model_description[] = {
- {"default", "Simplistic storage model.", &surf_storage_model_init_default},
- {nullptr, nullptr, nullptr} /* this array must be nullptr terminated */
+const std::vector<surf_model_description_t> surf_storage_model_description = {
+ {"default", "Simplistic storage model.", &surf_storage_model_init_default},
};
double NOW = 0;
}
/** Displays the long description of all registered models, and quit */
-void model_help(const char *category, s_surf_model_description_t * table)
+void model_help(const char* category, const std::vector<surf_model_description_t>& table)
{
printf("Long description of the %s models accepted by this simulator:\n", category);
- for (int i = 0; table[i].name; i++)
- printf(" %s: %s\n", table[i].name, table[i].description);
+ for (auto const& item : table)
+ printf(" %s: %s\n", item.name, item.description);
}
-int find_model_description(s_surf_model_description_t* table, const std::string& name)
+int find_model_description(const std::vector<surf_model_description_t>& table, const std::string& name)
{
- for (int i = 0; table[i].name; i++)
- if (name == table[i].name)
- return i;
+ auto pos = std::find_if(table.begin(), table.end(),
+ [&name](const surf_model_description_t& item) { return item.name == name; });
+ if (pos != table.end())
+ return std::distance(table.begin(), pos);
- if (not table[0].name)
+ if (table.empty())
xbt_die("No model is valid! This is a bug.");
- std::string name_list = std::string(table[0].name);
- for (int i = 1; table[i].name; i++)
- name_list = name_list + ", " + table[i].name;
+ std::string sep;
+ std::string name_list;
+ for (auto const& item : table) {
+ name_list += sep + item.name;
+ sep = ", ";
+ }
xbt_die("Model '%s' is invalid! Valid models are: %s.", name.c_str(), name_list.c_str());
return -1;
* Model Descriptions
* -------------------- */
/** @brief Resource model description */
-struct surf_model_description {
+struct surf_model_description_t {
const char* name;
const char* description;
void_f_void_t model_init_preparse;
};
-typedef struct surf_model_description s_surf_model_description_t;
-XBT_PUBLIC int find_model_description(s_surf_model_description_t* table, const std::string& name);
-XBT_PUBLIC void model_help(const char* category, s_surf_model_description_t* table);
+XBT_PUBLIC int find_model_description(const std::vector<surf_model_description_t>& table, const std::string& name);
+XBT_PUBLIC void model_help(const char* category, const std::vector<surf_model_description_t>& table);
#define SIMGRID_REGISTER_PLUGIN(id, desc, init) \
static void XBT_ATTRIB_CONSTRUCTOR(800) simgrid_##id##_plugin_register() \
XBT_PUBLIC void simgrid_add_plugin_description(const char* name, const char* description, void_f_void_t init_fun);
/** @brief The list of all available plugins */
-XBT_PUBLIC_DATA s_surf_model_description_t* surf_plugin_description;
+XBT_PUBLIC_DATA std::vector<surf_model_description_t>* surf_plugin_description;
/** @brief The list of all available optimization modes (both for cpu and networks).
* These optimization modes can be set using --cfg=cpu/optim:... and --cfg=network/optim:... */
-XBT_PUBLIC_DATA s_surf_model_description_t surf_optimization_mode_description[];
+XBT_PUBLIC_DATA const std::vector<surf_model_description_t> surf_optimization_mode_description;
/** @brief The list of all cpu models (pick one with --cfg=cpu/model) */
-XBT_PUBLIC_DATA s_surf_model_description_t surf_cpu_model_description[];
+XBT_PUBLIC_DATA const std::vector<surf_model_description_t> surf_cpu_model_description;
/** @brief The list of all network models (pick one with --cfg=network/model) */
-XBT_PUBLIC_DATA s_surf_model_description_t surf_network_model_description[];
+XBT_PUBLIC_DATA const std::vector<surf_model_description_t> surf_network_model_description;
/** @brief The list of all storage models (pick one with --cfg=storage/model) */
-XBT_PUBLIC_DATA s_surf_model_description_t surf_storage_model_description[];
+XBT_PUBLIC_DATA const std::vector<surf_model_description_t> surf_storage_model_description;
/** @brief The list of all host models (pick one with --cfg=host/model:) */
-XBT_PUBLIC_DATA s_surf_model_description_t surf_host_model_description[];
+XBT_PUBLIC_DATA const std::vector<surf_model_description_t> surf_host_model_description;
/**********
* Action *