sg_size_t getSizeUsed();
std::map<std::string, std::string>* getProperties();
- const char* getProperty(const char* key);
- void setProperty(const char* key, const char* value);
+ const char* getProperty(std::string key);
+ void setProperty(std::string, std::string value);
std::map<std::string, sg_size_t>* getContent();
void setUserdata(void* data) { userdata_ = data; }
/* Set the value of the cell \a name in \a cfg with the provided value.*/
XBT_PUBLIC(void) xbt_cfg_set_int (const char *name, int val);
XBT_PUBLIC(void) xbt_cfg_set_double (const char *name, double val);
-XBT_PUBLIC(void) xbt_cfg_set_string (const char *name, const char *val);
XBT_PUBLIC(void) xbt_cfg_set_boolean (const char *name, const char *val);
XBT_PUBLIC(void) xbt_cfg_set_as_string(const char *name, const char *val);
XBT_PUBLIC(int) xbt_cfg_get_int(const char *name);
XBT_PUBLIC(double) xbt_cfg_get_double(const char *name);
-XBT_PUBLIC(char *) xbt_cfg_get_string(const char *name);
XBT_PUBLIC(int) xbt_cfg_get_boolean(const char *name);
/** @} */
}
}
+XBT_PUBLIC(std::string) xbt_cfg_get_string(const char* name);
+XBT_PUBLIC(void) xbt_cfg_set_string(const char* name, std::string val);
#endif
#include "simgrid/msg.h"
+#include "include/xbt/signal.hpp"
#include "jmsg.hpp"
#include "jmsg_storage.h"
#include "jxbt_utilities.hpp"
+#include "simgrid/s4u/Storage.hpp"
XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(java);
}
const char *name = env->GetStringUTFChars((jstring) jname, 0);
const char *value_java = env->GetStringUTFChars((jstring) jvalue, 0);
- char *value = xbt_strdup(value_java);
- MSG_storage_set_property_value(storage, name, value);
+ storage->setProperty(name, std::string(value_java));
env->ReleaseStringUTFChars((jstring) jvalue, value_java);
env->ReleaseStringUTFChars((jstring) jname, name);
extern XBT_PRIVATE int _sg_mc_checkpoint;
extern XBT_PUBLIC(int) _sg_mc_sparse_checkpoint;
extern XBT_PUBLIC(int) _sg_mc_ksm;
-extern XBT_PUBLIC(char*) _sg_mc_property_file;
extern XBT_PRIVATE int _sg_mc_timeout;
extern XBT_PRIVATE int _sg_mc_hash;
extern XBT_PRIVATE int _sg_mc_max_depth;
extern XBT_PUBLIC(int) _sg_mc_max_visited_states;
-extern XBT_PRIVATE char* _sg_mc_dot_output_file;
extern XBT_PUBLIC(int) _sg_mc_comms_determinism;
extern XBT_PUBLIC(int) _sg_mc_send_determinism;
extern XBT_PRIVATE int _sg_mc_snapshot_fds;
#define SIMGRID_CONFIG_H
#include "xbt/config.h"
+#include "xbt/config.hpp"
/** Config Globals */
SG_BEGIN_DECL()
SG_END_DECL()
-#endif
\ No newline at end of file
+#endif
#define SMPI_UTILS_HPP
#include "xbt/base.h"
#include <cstddef>
+#include <string>
#include <vector>
extern "C" {
typedef s_smpi_factor_t* smpi_os_factor_t;
}
-XBT_PUBLIC(std::vector<s_smpi_factor_t>) parse_factor(const char *smpi_coef_string);
+XBT_PUBLIC(std::vector<s_smpi_factor_t>) parse_factor(std::string smpi_coef_string);
#endif
const char *description;
void_f_void_t model_init_preparse;
};
-typedef struct surf_model_description s_surf_model_description_t;
-typedef struct surf_model_description* surf_model_description_t;
+typedef struct surf_model_description s_surf_model_description_t;
-XBT_PUBLIC(int) find_model_description(s_surf_model_description_t * table, const char *name);
+#ifdef __cplusplus
+XBT_PUBLIC(int) find_model_description(s_surf_model_description_t* table, std::string name);
+#endif
XBT_PUBLIC(void) model_help(const char *category, s_surf_model_description_t * table);
/***************************/
/* This program is free software; you can redistribute it and/or modify it
* under the terms of the license (GNU LGPL) which comes with this package. */
+#include "include/xbt/config.hpp"
#include "src/instr/instr_private.hpp"
#include "surf/surf.h"
#include <string>
/* init the tracing module to generate the right output */
/* open the trace file(s) */
- const char* format = xbt_cfg_get_string(OPT_TRACING_FORMAT);
- XBT_DEBUG("Tracing format %s\n", format);
- if (not strcmp(format, "Paje")) {
+ std::string format = xbt_cfg_get_string(OPT_TRACING_FORMAT);
+ XBT_DEBUG("Tracing format %s\n", format.c_str());
+ if (format == "Paje") {
TRACE_paje_start();
- } else if (not strcmp(format, "TI")) {
+ } else if (format == "TI") {
instr_fmt_type = instr_fmt_TI;
TRACE_TI_start();
}else{
- xbt_die("Unknown trace format :%s ", format);
+ xbt_die("Unknown trace format :%s ", format.c_str());
}
/* activate trace */
delete root_type;
/* close the trace files */
- const char* format = xbt_cfg_get_string(OPT_TRACING_FORMAT);
- XBT_DEBUG("Tracing format %s\n", format);
- if (not strcmp(format, "Paje")) {
+ std::string format = xbt_cfg_get_string(OPT_TRACING_FORMAT);
+ XBT_DEBUG("Tracing format %s\n", format.c_str());
+ if (format == "Paje") {
TRACE_paje_end();
- } else if (not strcmp(format, "TI")) {
+ } else if (format == "TI") {
TRACE_TI_end();
}else{
- xbt_die("Unknown trace format :%s ", format);
+ xbt_die("Unknown trace format :%s ", format.c_str());
}
/* de-activate trace */
return trace_display_sizes && trace_smpi_enabled && TRACE_is_enabled();
}
-char *TRACE_get_comment ()
+std::string TRACE_get_comment()
{
return xbt_cfg_get_string(OPT_TRACING_COMMENT);
}
-char *TRACE_get_comment_file ()
+std::string TRACE_get_comment_file()
{
return xbt_cfg_get_string(OPT_TRACING_COMMENT_FILE);
}
return xbt_cfg_get_int(OPT_TRACING_PRECISION);
}
-char *TRACE_get_filename()
+std::string TRACE_get_filename()
{
return xbt_cfg_get_string(OPT_TRACING_FILENAME);
}
-char *TRACE_get_viva_uncat_conf ()
+std::string TRACE_get_viva_uncat_conf()
{
return xbt_cfg_get_string(OPT_VIVA_UNCAT_CONF);
}
-char *TRACE_get_viva_cat_conf ()
+std::string TRACE_get_viva_cat_conf()
{
return xbt_cfg_get_string(OPT_VIVA_CAT_CONF);
}
void TRACE_generate_viva_uncat_conf ()
{
- generate_uncat_configuration (TRACE_get_viva_uncat_conf (), "viva", 0);
+ generate_uncat_configuration(TRACE_get_viva_uncat_conf().c_str(), "viva", 0);
}
void TRACE_generate_viva_cat_conf ()
{
- generate_cat_configuration (TRACE_get_viva_cat_conf(), "viva", 0);
+ generate_cat_configuration(TRACE_get_viva_cat_conf().c_str(), "viva", 0);
}
static int previous_trace_state = -1;
}
if (not xbt_cfg_get_boolean("tracing/smpi/format/ti-one-file") || ti_unique_file == nullptr) {
- char* folder_name = bprintf("%s_files", TRACE_get_filename());
- char* filename = bprintf("%s/%f_%s.txt", folder_name, prefix, name_.c_str());
+ std::string folder_name = TRACE_get_filename() + "_files";
+ std::string filename = folder_name + "/" + std::to_string(prefix) + "_" + name_ + ".txt";
#ifdef WIN32
- _mkdir(folder_name);
+ _mkdir(folder_name.c_str());
#else
- mkdir(folder_name, S_IRWXU | S_IRWXG | S_IRWXO);
+ mkdir(folder_name.c_str(), S_IRWXU | S_IRWXG | S_IRWXO);
#endif
- ti_unique_file = fopen(filename, "w");
- xbt_assert(ti_unique_file, "Tracefile %s could not be opened for writing: %s", filename, strerror(errno));
- fprintf(tracing_file, "%s\n", filename);
-
- xbt_free(folder_name);
- xbt_free(filename);
+ ti_unique_file = fopen(filename.c_str(), "w");
+ xbt_assert(ti_unique_file, "Tracefile %s could not be opened for writing: %s", filename.c_str(), strerror(errno));
+ fprintf(tracing_file, "%s\n", filename.c_str());
}
tracing_files.insert({this, ti_unique_file});
} else {
}
void TRACE_paje_start() {
- char *filename = TRACE_get_filename();
- tracing_file = fopen(filename, "w");
+ std::string filename = TRACE_get_filename();
+ tracing_file = fopen(filename.c_str(), "w");
if (tracing_file == nullptr){
- THROWF (system_error, 1, "Tracefile %s could not be opened for writing.", filename);
+ THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename.c_str());
}
- XBT_DEBUG("Filename %s is open for writing", filename);
+ XBT_DEBUG("Filename %s is open for writing", filename.c_str());
/* output generator version */
fprintf (tracing_file, "#This file was generated using SimGrid-%d.%d.%d\n",
void TRACE_paje_end() {
fclose(tracing_file);
- char *filename = TRACE_get_filename();
- XBT_DEBUG("Filename %s is closed", filename);
+ XBT_DEBUG("Filename %s is closed", TRACE_get_filename().c_str());
}
void TRACE_TI_start()
{
- char *filename = TRACE_get_filename();
- tracing_file = fopen(filename, "w");
- if (tracing_file == nullptr)
- THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename);
+ std::string filename = TRACE_get_filename();
+ tracing_file = fopen(filename.c_str(), "w");
+ if (tracing_file == nullptr) {
+ THROWF(system_error, 1, "Tracefile %s could not be opened for writing.", filename.c_str());
+ }
- XBT_DEBUG("Filename %s is open for writing", filename);
+ XBT_DEBUG("Filename %s is open for writing", filename.c_str());
/* output one line comment */
dump_comment(TRACE_get_comment());
void TRACE_TI_end()
{
fclose(tracing_file);
- XBT_DEBUG("Filename %s is closed", TRACE_get_filename());
+ XBT_DEBUG("Filename %s is closed", TRACE_get_filename().c_str());
}
XBT_PRIVATE bool TRACE_disable_destroy();
XBT_PRIVATE bool TRACE_basic();
XBT_PRIVATE bool TRACE_display_sizes();
-XBT_PRIVATE char* TRACE_get_comment();
-XBT_PRIVATE char* TRACE_get_comment_file();
XBT_PRIVATE int TRACE_precision();
-XBT_PRIVATE char* TRACE_get_filename();
-XBT_PRIVATE char* TRACE_get_viva_uncat_conf();
-XBT_PRIVATE char* TRACE_get_viva_cat_conf();
+XBT_PRIVATE std::string TRACE_get_comment();
+XBT_PRIVATE std::string TRACE_get_comment_file();
+XBT_PRIVATE std::string TRACE_get_filename();
+XBT_PRIVATE std::string TRACE_get_viva_uncat_conf();
+XBT_PRIVATE std::string TRACE_get_viva_cat_conf();
XBT_PRIVATE void TRACE_generate_viva_uncat_conf();
XBT_PRIVATE void TRACE_generate_viva_cat_conf();
XBT_PRIVATE void instr_pause_tracing();
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_ModelChecker, mc, "ModelChecker");
::simgrid::mc::ModelChecker* mc_model_checker = nullptr;
+extern std::string _sg_mc_dot_output_file;
using simgrid::mc::remote;
process_->init();
- if ((_sg_mc_dot_output_file != nullptr) && (_sg_mc_dot_output_file[0] != '\0'))
+ if (not _sg_mc_dot_output_file.empty())
MC_init_dot_output();
setup_ignore();
#include "src/smpi/include/private.hpp"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_Session, mc, "Model-checker session");
+extern std::string _sg_mc_dot_output_file;
namespace simgrid {
namespace mc {
{
mc_model_checker->getChecker()->logState();
- if ((_sg_mc_dot_output_file != nullptr) && (_sg_mc_dot_output_file[0] != '\0')) {
+ if (not _sg_mc_dot_output_file.empty()) {
fprintf(dot_output, "}\n");
fclose(dot_output);
}
#include "src/mc/remote/Client.hpp"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_liveness, mc, "Logging specific to algorithms for liveness properties verification");
+extern std::string _sg_mc_property_file;
/********* Static functions *********/
void LivenessChecker::run()
{
- XBT_INFO("Check the liveness property %s", _sg_mc_property_file);
- MC_automaton_load(_sg_mc_property_file);
+ XBT_INFO("Check the liveness property %s", _sg_mc_property_file.c_str());
+ MC_automaton_load(_sg_mc_property_file.c_str());
XBT_DEBUG("Starting the liveness algorithm");
simgrid::mc::session->initialize();
#include "src/mc/remote/mc_protocol.h"
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_main, mc, "Entry point for simgrid-mc");
+extern std::string _sg_mc_property_file;
static inline
char** argvdup(int argc, char** argv)
return argv_copy;
}
-static
-std::unique_ptr<simgrid::mc::Checker> createChecker(simgrid::mc::Session& session)
+static std::unique_ptr<simgrid::mc::Checker> createChecker(simgrid::mc::Session& session)
{
if (_sg_mc_comms_determinism || _sg_mc_send_determinism)
- return std::unique_ptr<simgrid::mc::Checker>(
- simgrid::mc::createCommunicationDeterminismChecker(session));
- else if (_sg_mc_property_file == nullptr || _sg_mc_property_file[0] == '\0')
- return std::unique_ptr<simgrid::mc::Checker>(
- simgrid::mc::createSafetyChecker(session));
+ return std::unique_ptr<simgrid::mc::Checker>(simgrid::mc::createCommunicationDeterminismChecker(session));
+ else if (_sg_mc_property_file.empty())
+ return std::unique_ptr<simgrid::mc::Checker>(simgrid::mc::createSafetyChecker(session));
else
- return std::unique_ptr<simgrid::mc::Checker>(
- simgrid::mc::createLivenessChecker(session));
+ return std::unique_ptr<simgrid::mc::Checker>(simgrid::mc::createLivenessChecker(session));
}
int main(int argc, char** argv)
int simcall_HANDLER_mc_random(smx_simcall_t simcall, int min, int max)
{
- if (not MC_is_active() && not MC_record_path)
+ if (not MC_is_active() && MC_record_path.empty())
return prng_random(min, max);
return simcall->mc_value;
}
#define PROT_RWX (PROT_READ | PROT_WRITE | PROT_EXEC)
#define PROT_RW (PROT_READ | PROT_WRITE)
#define PROT_RX (PROT_READ | PROT_EXEC)
+extern std::string _sg_mc_property_file;
+extern std::string _sg_mc_dot_output_file;
namespace simgrid {
namespace mc {
snapshot->to_ignore = mc_model_checker->process().ignored_heap();
- if (_sg_mc_max_visited_states > 0 || strcmp(_sg_mc_property_file, "")) {
+ if (_sg_mc_max_visited_states > 0 || not _sg_mc_property_file.empty()) {
snapshot->stacks = take_snapshot_stacks(snapshot.get());
if (_sg_mc_hash)
snapshot->hash = simgrid::mc::hash(*snapshot);
void _mc_cfg_cb_timeout(const char *name)
{
- if (_sg_cfg_init_status && not(_sg_do_model_check || MC_record_path))
+ if (_sg_cfg_init_status && not(_sg_do_model_check || not MC_record_path.empty()))
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 bu the program was not runned under the model-checker (with simgrid-mc)). This won't work, sorry.");
_sg_mc_timeout = xbt_cfg_get_boolean(name);
int _sg_mc_checkpoint = 0;
int _sg_mc_sparse_checkpoint = 0;
int _sg_mc_ksm = 0;
-char *_sg_mc_property_file = nullptr;
+std::string _sg_mc_property_file;
int _sg_mc_hash = 0;
int _sg_mc_max_depth = 1000;
int _sg_mc_max_visited_states = 0;
-char *_sg_mc_dot_output_file = nullptr;
+std::string _sg_mc_dot_output_file;
int _sg_mc_comms_determinism = 0;
int _sg_mc_send_determinism = 0;
int _sg_mc_snapshot_fds = 0;
xbt_die
("You are specifying a reduction strategy after the initialization (through MSG_config?), but model-checking was not activated at config time (through bu the program was not runned under the model-checker (with simgrid-mc)). This won't work, sorry.");
- char *val = xbt_cfg_get_string(name);
- if (not strcasecmp(val, "none"))
+ std::string val = xbt_cfg_get_string(name);
+ if (val == "none")
simgrid::mc::reduction_mode = simgrid::mc::ReductionMode::none;
- else if (not strcasecmp(val, "dpor"))
+ else if (val == "dpor")
simgrid::mc::reduction_mode = simgrid::mc::ReductionMode::dpor;
else
- xbt_die("configuration option %s can only take 'none' or 'dpor' as a value",
- name);
+ xbt_die("configuration option %s can only take 'none' or 'dpor' as a value", name);
}
void _mc_cfg_cb_checkpoint(const char *name)
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(mc_global, mc, "Logging specific to MC (global)");
+extern std::string _sg_mc_dot_output_file;
+
namespace simgrid {
namespace mc {
void MC_init_dot_output()
{
- dot_output = fopen(_sg_mc_dot_output_file, "w");
+ dot_output = fopen(_sg_mc_dot_output_file.c_str(), "w");
if (dot_output == nullptr) {
perror("Error open dot output file");
" Logging specific to MC record/replay facility");
extern "C" {
-char* MC_record_path = nullptr;
+std::string MC_record_path;
}
namespace simgrid {
}
}
-void replay(const char* path_string)
+void replay(std::string path_string)
{
simgrid::mc::processes_time.resize(SIMIX_process_get_maxpid());
- simgrid::mc::RecordTrace trace = simgrid::mc::parseRecordTrace(path_string);
+ simgrid::mc::RecordTrace trace = simgrid::mc::parseRecordTrace(path_string.c_str());
simgrid::mc::replay(trace);
simgrid::mc::processes_time.clear();
}
XBT_PRIVATE void dumpRecordPath();
XBT_PRIVATE void replay(RecordTrace const& trace);
-XBT_PRIVATE void replay(const char* trace);
+XBT_PRIVATE void replay(std::string trace);
}
}
*
* This is using the format generated by traceToString().
*/
-XBT_PUBLIC_DATA(char*) MC_record_path;
+XBT_PUBLIC_DATA(std::string) MC_record_path;
/** Whether the replay mode is enabled */
static inline int MC_record_replay_is_active() {
- return MC_record_path != 0;
+ return not MC_record_path.empty();
}
SG_END_DECL()
return simgrid::simix::kernelImmediate([this] { return pimpl_->getProperties(); });
}
-const char* Storage::getProperty(const char* key)
+const char* Storage::getProperty(std::string key)
{
return this->pimpl_->getProperty(key);
}
-void Storage::setProperty(const char* key, const char* value)
+void Storage::setProperty(std::string key, std::string value)
{
simgrid::simix::kernelImmediate([this, key, value] { this->pimpl_->setProperty(key, value); });
}
{
xbt_assert(_sg_cfg_init_status < 2, "Cannot load a plugin after the initialization");
- char *val = xbt_cfg_get_string(name);
- if (val==nullptr || val[0] == '\0')
+ std::string val = xbt_cfg_get_string(name);
+ if (val.empty())
return;
- if (not strcmp(val, "help")) {
+ if (val == "help") {
model_help("plugin", surf_plugin_description);
sg_cfg_exit_early();
}
{
xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
- char *val = xbt_cfg_get_string(name);
- if (not strcmp(val, "help")) {
+ std::string val = xbt_cfg_get_string(name);
+ if (val == "help") {
model_help("host", surf_host_model_description);
sg_cfg_exit_early();
}
{
xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
- char *val = xbt_cfg_get_string(name);
- if (not strcmp(val, "help")) {
+ std::string val = xbt_cfg_get_string(name);
+ if (val == "help") {
model_help("CPU", surf_cpu_model_description);
sg_cfg_exit_early();
}
{
xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
- char *val = xbt_cfg_get_string(name);
- if (not strcmp(val, "help")) {
+ std::string val = xbt_cfg_get_string(name);
+ if (val == "help") {
model_help("optimization", surf_optimization_mode_description);
sg_cfg_exit_early();
}
{
xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
- char *val = xbt_cfg_get_string(name);
- if (not strcmp(val, "help")) {
+ std::string val = xbt_cfg_get_string(name);
+ if (val == "help") {
model_help("storage", surf_storage_model_description);
sg_cfg_exit_early();
}
{
xbt_assert(_sg_cfg_init_status < 2, "Cannot change the model after the initialization");
- char *val = xbt_cfg_get_string(name);
- if (not strcmp(val, "help")) {
+ std::string val = xbt_cfg_get_string(name);
+ if (val == "help") {
model_help("network", surf_network_model_description);
sg_cfg_exit_early();
}
static void _sg_cfg_cb_model_check_replay(const char *name) {
MC_record_path = xbt_cfg_get_string(name);
- if (MC_record_path[0] == '\0')
- MC_record_path = nullptr;
}
#if SIMGRID_HAVE_MC
static void _sg_cfg_cb_contexts_parallel_mode(const char *name)
{
- const char* mode_name = xbt_cfg_get_string(name);
- if (not strcmp(mode_name, "posix")) {
+ std::string mode_name = xbt_cfg_get_string(name);
+ if (mode_name == "posix") {
SIMIX_context_set_parallel_mode(XBT_PARMAP_POSIX);
- } else if (not strcmp(mode_name, "futex")) {
+ } else if (mode_name == "futex") {
SIMIX_context_set_parallel_mode(XBT_PARMAP_FUTEX);
- } else if (not strcmp(mode_name, "busy_wait")) {
+ } else if (mode_name == "busy_wait") {
SIMIX_context_set_parallel_mode(XBT_PARMAP_BUSY_WAIT);
- }
- else {
+ } else {
xbt_die("Command line setting of the parallel synchronization mode should "
"be one of \"posix\", \"futex\" or \"busy_wait\"");
}
/* Plugins configuration */
describe_model(description, descsize, surf_plugin_description, "plugin", "The plugins");
- xbt_cfg_register_string("plugin", nullptr, &_sg_cfg_cb__plugin, description);
+ xbt_cfg_register_string("plugin", "", &_sg_cfg_cb__plugin, description);
describe_model(description, descsize, surf_cpu_model_description, "model", "The model to use for the CPU");
xbt_cfg_register_string("cpu/model", "Cas01", &_sg_cfg_cb__cpu_model, description);
*/
void SIMIX_run()
{
- if (MC_record_path) {
+ if (not MC_record_path.empty()) {
simgrid::mc::replay(MC_record_path);
return;
}
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_coll, smpi, "Logging specific to SMPI (coll)");
-#define COLL_SETTER(cat, ret, args, args2)\
-int (*Colls::cat ) args;\
-void Colls::set_##cat (const char * name){\
- int id = find_coll_description(mpi_coll_## cat ##_description,\
- name,#cat);\
- cat = reinterpret_cast<ret (*) args>\
- (mpi_coll_## cat ##_description[id].coll);\
- if (cat == nullptr)\
- xbt_die("Collective "#cat" set to nullptr!");\
-}
+#define COLL_SETTER(cat, ret, args, args2) \
+ int(*Colls::cat) args; \
+ void Colls::set_##cat(std::string name) \
+ { \
+ int id = find_coll_description(mpi_coll_##cat##_description, name, #cat); \
+ cat = reinterpret_cast<ret(*) args>(mpi_coll_##cat##_description[id].coll); \
+ if (cat == nullptr) \
+ xbt_die("Collective " #cat " set to nullptr!"); \
+ }
-#define SET_COLL(coll)\
- name = xbt_cfg_get_string("smpi/"#coll);\
- if (name==nullptr || name[0] == '\0')\
- name = selector_name;\
- set_##coll(name);
+#define SET_COLL(coll) \
+ name = xbt_cfg_get_string("smpi/" #coll); \
+ if (name.empty()) \
+ name = selector_name; \
+ set_##coll(name);
namespace simgrid{
namespace smpi{
XBT_WARN(" %s: %s\n", table[i].name, table[i].description);
}
-int Colls::find_coll_description(s_mpi_coll_description_t * table, const char *name, const char *desc)
+int Colls::find_coll_description(s_mpi_coll_description_t* table, std::string name, const char* desc)
{
- char *name_list = nullptr;
for (int i = 0; table[i].name; i++)
- if (not strcmp(name, table[i].name)) {
+ if (name == table[i].name) {
if (strcmp(table[i].name,"default"))
XBT_INFO("Switch to algorithm %s for collective %s",table[i].name,desc);
return i;
}
if (not table[0].name)
- xbt_die("No collective is valid for '%s'! This is a bug.",name);
- name_list = xbt_strdup(table[0].name);
- for (int i = 1; table[i].name; i++) {
- name_list = static_cast<char*>(xbt_realloc(name_list, strlen(name_list) + strlen(table[i].name) + 3));
- strncat(name_list, ", ",2);
- strncat(name_list, table[i].name, strlen(table[i].name));
- }
- xbt_die("Collective '%s' is invalid! Valid collectives are: %s.", name, name_list);
+ xbt_die("No collective is valid for '%s'! This is a bug.", name.c_str());
+ std::string name_list = std::string(table[0].name);
+ for (int i = 1; table[i].name; i++)
+ name_list = name_list + ", " + table[i].name;
+
+ xbt_die("Collective '%s' is invalid! Valid collectives are: %s.", name.c_str(), name_list.c_str());
return -1;
}
-
-
COLL_APPLY(COLL_SETTER,COLL_GATHER_SIG,"");
COLL_APPLY(COLL_SETTER,COLL_ALLGATHER_SIG,"");
COLL_APPLY(COLL_SETTER,COLL_ALLGATHERV_SIG,"");
void Colls::set_collectives(){
- const char* selector_name = static_cast<char*>(xbt_cfg_get_string("smpi/coll-selector"));
- if (selector_name==nullptr || selector_name[0] == '\0')
- selector_name = "default";
-
- const char* name;
-
- SET_COLL(gather);
- SET_COLL(allgather);
- SET_COLL(allgatherv);
- SET_COLL(allreduce);
- SET_COLL(alltoall);
- SET_COLL(alltoallv);
- SET_COLL(reduce);
- SET_COLL(reduce_scatter);
- SET_COLL(scatter);
- SET_COLL(bcast);
- SET_COLL(barrier);
+ std::string selector_name = xbt_cfg_get_string("smpi/coll-selector");
+ if (selector_name.empty())
+ selector_name = "default";
+
+ std::string name;
+
+ SET_COLL(gather);
+ SET_COLL(allgather);
+ SET_COLL(allgatherv);
+ SET_COLL(allreduce);
+ SET_COLL(alltoall);
+ SET_COLL(alltoallv);
+ SET_COLL(reduce);
+ SET_COLL(reduce_scatter);
+ SET_COLL(scatter);
+ SET_COLL(bcast);
+ SET_COLL(barrier);
}
#ifndef SMPI_PRIVATE_HPP
#define SMPI_PRIVATE_HPP
+#include "include/xbt/config.hpp"
#include "simgrid/msg.h" // msg_bar_t
#include "smpi/smpi.h"
#include "src/instr/instr_smpi.hpp"
/** \brief MPI collective description */
-#define COLL_DEFS(cat, ret, args, args2)\
- static void set_##cat(const char* name);\
- static s_mpi_coll_description_t mpi_coll_##cat##_description[];\
- static int (*cat ) args;
+#define COLL_DEFS(cat, ret, args, args2) \
+ static void set_##cat(std::string name); \
+ static s_mpi_coll_description_t mpi_coll_##cat##_description[]; \
+ static int(*cat) args;
#define COLL_SIG(cat, ret, args, args2)\
static int cat args;
class Colls{
public:
static XBT_PUBLIC(void) coll_help(const char *category, s_mpi_coll_description_t * table);
- static XBT_PUBLIC(int) find_coll_description(s_mpi_coll_description_t * table, const char *name, const char *desc);
+ static XBT_PUBLIC(int) find_coll_description(s_mpi_coll_description_t* table, std::string name, const char* desc);
static void set_collectives();
// for each collective type, create the set_* prototype, the description array and the function pointer
return;
#if HAVE_PAPI
- if (xbt_cfg_get_string("smpi/papi-events")[0] != '\0') {
+ if (not xbt_cfg_get_string("smpi/papi-events").empty()) {
int event_set = smpi_process()->papi_event_set();
// PAPI_start sets everything to 0! See man(3) PAPI_start
if (PAPI_LOW_LEVEL_INITED == PAPI_is_initialized()) {
xbt_os_walltimer_start(global_timer);
}
- if (xbt_cfg_get_string("smpi/comp-adjustment-file")[0] != '\0') {
- std::string filename {xbt_cfg_get_string("smpi/comp-adjustment-file")};
+ std::string filename = xbt_cfg_get_string("smpi/comp-adjustment-file");
+ if (not filename.empty()) {
std::ifstream fstream(filename);
if (not fstream.is_open()) {
xbt_die("Could not open file %s. Does it exist?", filename.c_str());
// and the (computed) event_set.
std::map</* computation unit name */ std::string, papi_process_data> units2papi_setup;
- if (xbt_cfg_get_string("smpi/papi-events")[0] != '\0') {
+ if (not xbt_cfg_get_string("smpi/papi-events").empty()) {
if (PAPI_library_init(PAPI_VER_CURRENT) != PAPI_VER_CURRENT)
XBT_ERROR("Could not initialize PAPI library; is it correctly installed and linked?"
" Expected version is %i",
typedef boost::tokenizer<boost::char_separator<char>> Tokenizer;
boost::char_separator<char> separator_units(";");
- std::string str = std::string(xbt_cfg_get_string("smpi/papi-events"));
+ std::string str = xbt_cfg_get_string("smpi/papi-events");
Tokenizer tokens(str, separator_units);
// Iterate over all the computational units. This could be processes, hosts, threads, ranks... You name it.
}
static void smpi_init_options(){
- //return if already called
- if (smpi_cpu_threshold > -1)
- return;
- simgrid::smpi::Colls::set_collectives();
- simgrid::smpi::Colls::smpi_coll_cleanup_callback=nullptr;
- smpi_cpu_threshold = xbt_cfg_get_double("smpi/cpu-threshold");
- smpi_host_speed = xbt_cfg_get_double("smpi/host-speed");
- const char* smpi_privatize_option = xbt_cfg_get_string("smpi/privatization");
- if (std::strcmp(smpi_privatize_option, "no") == 0)
- smpi_privatize_global_variables = SMPI_PRIVATIZE_NONE;
- else if (std::strcmp(smpi_privatize_option, "yes") == 0)
- smpi_privatize_global_variables = SMPI_PRIVATIZE_DEFAULT;
- else if (std::strcmp(smpi_privatize_option, "mmap") == 0)
- smpi_privatize_global_variables = SMPI_PRIVATIZE_MMAP;
- else if (std::strcmp(smpi_privatize_option, "dlopen") == 0)
- smpi_privatize_global_variables = SMPI_PRIVATIZE_DLOPEN;
-
- // Some compatibility stuff:
- else if (std::strcmp(smpi_privatize_option, "1") == 0)
- smpi_privatize_global_variables = SMPI_PRIVATIZE_DEFAULT;
- else if (std::strcmp(smpi_privatize_option, "0") == 0)
- smpi_privatize_global_variables = SMPI_PRIVATIZE_NONE;
-
- else
- xbt_die("Invalid value for smpi/privatization: '%s'", smpi_privatize_option);
+ // return if already called
+ if (smpi_cpu_threshold > -1)
+ return;
+ simgrid::smpi::Colls::set_collectives();
+ simgrid::smpi::Colls::smpi_coll_cleanup_callback = nullptr;
+ smpi_cpu_threshold = xbt_cfg_get_double("smpi/cpu-threshold");
+ smpi_host_speed = xbt_cfg_get_double("smpi/host-speed");
+ std::string smpi_privatize_option = xbt_cfg_get_string("smpi/privatization");
+ if (smpi_privatize_option == "no" || smpi_privatize_option == "0")
+ smpi_privatize_global_variables = SMPI_PRIVATIZE_NONE;
+ else if (smpi_privatize_option == "yes" || smpi_privatize_option == "1")
+ smpi_privatize_global_variables = SMPI_PRIVATIZE_DEFAULT;
+ else if (smpi_privatize_option == "mmap")
+ smpi_privatize_global_variables = SMPI_PRIVATIZE_MMAP;
+ else if (smpi_privatize_option == "dlopen")
+ smpi_privatize_global_variables = SMPI_PRIVATIZE_DLOPEN;
+ else
+ xbt_die("Invalid value for smpi/privatization: '%s'", smpi_privatize_option.c_str());
#if defined(__FreeBSD__)
if (smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP) {
if (smpi_cpu_threshold < 0)
smpi_cpu_threshold = DBL_MAX;
- char* val = xbt_cfg_get_string("smpi/shared-malloc");
+ const char* val = xbt_cfg_get_string("smpi/shared-malloc").c_str();
if (not strcasecmp(val, "yes") || not strcmp(val, "1") || not strcasecmp(val, "on") ||
not strcasecmp(val, "global")) {
smpi_cfg_shared_malloc = shmalloc_global;
void* smpi_shared_malloc_partial(size_t size, size_t* shared_block_offsets, int nb_shared_blocks)
{
- char *huge_page_mount_point = xbt_cfg_get_string("smpi/shared-malloc-hugepage");
- bool use_huge_page = huge_page_mount_point[0] != '\0';
+ std::string huge_page_mount_point = xbt_cfg_get_string("smpi/shared-malloc-hugepage");
+ bool use_huge_page = not huge_page_mount_point.empty();
#ifndef MAP_HUGETLB /* If the system header don't define that mmap flag */
xbt_assert(not use_huge_page,
"Huge pages are not available on your system, you cannot use the smpi/shared-malloc-hugepage option.");
* We cannot use a same file for the two type of calls, since the first one needs to be
* opened in a hugetlbfs mount point whereas the second needs to be a "classical" file. */
if(use_huge_page && smpi_shared_malloc_bogusfile_huge_page == -1) {
- char* huge_page_filename = bprintf("%s/simgrid-shmalloc-XXXXXX", huge_page_mount_point);
- smpi_shared_malloc_bogusfile_huge_page = mkstemp(huge_page_filename);
- XBT_DEBUG("bogusfile_huge_page: %s\n", huge_page_filename);
- unlink(huge_page_filename);
- xbt_free(huge_page_filename);
+ std::string huge_page_filename = huge_page_mount_point + "/simgrid-shmalloc-XXXXXX";
+ smpi_shared_malloc_bogusfile_huge_page = mkstemp((char*)huge_page_filename.c_str());
+ XBT_DEBUG("bogusfile_huge_page: %s\n", huge_page_filename.c_str());
+ unlink(huge_page_filename.c_str());
}
if(smpi_shared_malloc_bogusfile == -1) {
char name[] = "/tmp/simgrid-shmalloc-XXXXXX";
XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_utils, smpi, "Logging specific to SMPI (utils)");
-std::vector<s_smpi_factor_t> parse_factor(const char *smpi_coef_string)
+std::vector<s_smpi_factor_t> parse_factor(std::string smpi_coef_string)
{
std::vector<s_smpi_factor_t> smpi_factor;
typedef boost::tokenizer<boost::char_separator<char>> Tokenizer;
boost::char_separator<char> sep(";");
boost::char_separator<char> factor_separator(":");
- std::string tmp_string(smpi_coef_string);
- Tokenizer tokens(tmp_string, sep);
+ Tokenizer tokens(smpi_coef_string, sep);
/**
* Iterate over patterns like A:B:C:D;E:F;G:H
Tokenizer factor_values(*token_iter, factor_separator);
s_smpi_factor_t fact;
if (factor_values.begin() == factor_values.end()) {
- xbt_die("Malformed radical for smpi factor: '%s'", smpi_coef_string);
+ xbt_die("Malformed radical for smpi factor: '%s'", smpi_coef_string.c_str());
}
unsigned int iteration = 0;
for (Tokenizer::iterator factor_iter = factor_values.begin(); factor_iter != factor_values.end(); ++factor_iter) {
}
/** @brief Return the property associated to the provided key (or nullptr if not existing) */
-const char *PropertyHolder::getProperty(const char*key) {
+const char* PropertyHolder::getProperty(std::string key)
+{
if (properties_ == nullptr)
return nullptr;
auto prop = properties_->find(key);
PropertyHolder() = default;
~PropertyHolder();
- const char *getProperty(const char*id);
+ const char* getProperty(std::string key);
void setProperty(std::string id, std::string value);
/* FIXME: This should not be exposed, as users may do bad things with the dict they got (it's not a copy).
xbt_assert(not surf_cpu_model_pm);
xbt_assert(not surf_cpu_model_vm);
- char *optim = xbt_cfg_get_string("cpu/optim");
- if (not strcmp(optim, "TI")) {
+ if (xbt_cfg_get_string("cpu/optim") == "TI") {
surf_cpu_model_init_ti();
return;
}
CpuCas01Model::CpuCas01Model() : simgrid::surf::CpuModel()
{
- char *optim = xbt_cfg_get_string("cpu/optim");
+ std::string optim = xbt_cfg_get_string("cpu/optim");
bool select = xbt_cfg_get_boolean("cpu/maxmin-selective-update");
- if (not strcmp(optim, "Full")) {
+ if (optim == "Full") {
setUpdateMechanism(UM_FULL);
selectiveUpdate_ = select;
- } else if (not strcmp(optim, "Lazy")) {
+ } else if (optim == "Lazy") {
setUpdateMechanism(UM_LAZY);
selectiveUpdate_ = true;
xbt_assert(select || (xbt_cfg_is_default_value("cpu/maxmin-selective-update")),
"Disabling selective update while using the lazy update mechanism is dumb!");
} else {
- xbt_die("Unsupported optimization (%s) for this model", optim);
+ xbt_die("Unsupported optimization (%s) for this model", optim.c_str());
}
p_cpuRunningActionSetThatDoesNotNeedBeingChecked = new ActionList();
NetworkCm02Model::NetworkCm02Model()
:NetworkModel()
{
- char *optim = xbt_cfg_get_string("network/optim");
+ std::string optim = xbt_cfg_get_string("network/optim");
bool select = xbt_cfg_get_boolean("network/maxmin-selective-update");
- if (not strcmp(optim, "Full")) {
+ if (optim == "Full") {
setUpdateMechanism(UM_FULL);
selectiveUpdate_ = select;
- } else if (not strcmp(optim, "Lazy")) {
+ } else if (optim == "Lazy") {
setUpdateMechanism(UM_LAZY);
selectiveUpdate_ = true;
xbt_assert(select || (xbt_cfg_is_default_value("network/maxmin-selective-update")),
"You cannot disable selective update when using the lazy update mechanism");
} else {
- xbt_die("Unsupported optimization (%s) for this model. Accepted: Full, Lazy.", optim);
+ xbt_die("Unsupported optimization (%s) for this model. Accepted: Full, Lazy.", optim.c_str());
}
maxminSystem_ = lmm_system_new(selectiveUpdate_);
NetworkIBModel::NetworkIBModel() : NetworkSmpiModel()
{
- const char* IB_factors_string = xbt_cfg_get_string("smpi/IB-penalty-factors");
+ std::string IB_factors_string = xbt_cfg_get_string("smpi/IB-penalty-factors");
std::vector<std::string> radical_elements;
boost::split(radical_elements, IB_factors_string, boost::is_any_of(";"));
/* Pick the right models for CPU, net and host, and call their model_init_preparse */
static void surf_config_models_setup()
{
- const char* host_model_name = xbt_cfg_get_string("host/model");
- const char* network_model_name = xbt_cfg_get_string("network/model");
- const char* cpu_model_name = xbt_cfg_get_string("cpu/model");
- const char* storage_model_name = xbt_cfg_get_string("storage/model");
+ std::string host_model_name = xbt_cfg_get_string("host/model");
+ std::string network_model_name = xbt_cfg_get_string("network/model");
+ std::string cpu_model_name = xbt_cfg_get_string("cpu/model");
+ std::string storage_model_name = xbt_cfg_get_string("storage/model");
/* The compound host model is needed when using non-default net/cpu models */
if ((not xbt_cfg_is_default_value("network/model") || not xbt_cfg_is_default_value("cpu/model")) &&
xbt_cfg_set_string("host/model", host_model_name);
}
- XBT_DEBUG("host model: %s", host_model_name);
- if (not strcmp(host_model_name, "compound")) {
- xbt_assert(cpu_model_name, "Set a cpu model to use with the 'compound' host model");
- xbt_assert(network_model_name, "Set a network model to use with the 'compound' host model");
+ XBT_DEBUG("host model: %s", host_model_name.c_str());
+ if (host_model_name == "compound") {
+ xbt_assert(not cpu_model_name.empty(), "Set a cpu model to use with the 'compound' host model");
+ xbt_assert(not network_model_name.empty(), "Set a network model to use with the 'compound' host model");
int cpu_id = find_model_description(surf_cpu_model_description, cpu_model_name);
surf_cpu_model_description[cpu_id].model_init_preparse();
printf(" %s: %s\n", table[i].name, table[i].description);
}
-int find_model_description(s_surf_model_description_t* table, const char* name)
+int find_model_description(s_surf_model_description_t* table, std::string name)
{
for (int i = 0; table[i].name; i++)
- if (not strcmp(name, table[i].name)) {
+ if (name == table[i].name)
return i;
- }
if (not table[0].name)
xbt_die("No model is valid! This is a bug.");
- char* name_list = xbt_strdup(table[0].name);
- for (int i = 1; table[i].name; i++) {
- name_list = (char *) xbt_realloc(name_list, strlen(name_list) + strlen(table[i].name) + 3);
- strncat(name_list, ", ", 2);
- strncat(name_list, table[i].name, strlen(table[i].name));
- }
- xbt_die("Model '%s' is invalid! Valid models are: %s.", name, name_list);
+ std::string name_list = std::string(table[0].name);
+ for (int i = 1; table[i].name; i++)
+ name_list = name_list + ", " + table[i].name;
+
+ xbt_die("Model '%s' is invalid! Valid models are: %s.", name.c_str(), name_list.c_str());
return -1;
}
#include <map>
#include <stdexcept>
#include <string>
+#include <string>
#include <type_traits>
#include <typeinfo>
#include <vector>
simgrid_config = xbt_cfg_new();
atexit(sg_config_finalize);
}
- simgrid_config->registerOption<std::string>(name, desc,
- default_value ? default_value : "", cb_set);
+ simgrid_config->registerOption<std::string>(name, desc, default_value ? default_value : "", cb_set);
}
void xbt_cfg_register_boolean(const char *name, const char*default_value,xbt_cfg_cb_t cb_set, const char *desc)
* @param value the value to be added
*
*/
-void xbt_cfg_set_string(const char *key, const char *value)
+void xbt_cfg_set_string(const char* key, std::string value)
{
try {
- (*simgrid_config)[key].setValue<std::string>(value ? value : "");
+ (*simgrid_config)[key].setValue<std::string>(value);
return;
}
- TRANSLATE_EXCEPTIONS("Could not set variable %s to string %s", key, value);
+ TRANSLATE_EXCEPTIONS("Could not set variable %s to string %s", key, value.c_str());
}
/** @brief Set or add a boolean value to \a name within \a cfg
*
* \warning the returned value is the actual content of the config set
*/
-char *xbt_cfg_get_string(const char *key)
+std::string xbt_cfg_get_string(const char* key)
{
try {
- return (char*) (*simgrid_config)[key].getValue<std::string>().c_str();
+ return (*simgrid_config)[key].getValue<std::string>();
}
TRANSLATE_EXCEPTIONS("Could not get variable %s", key);
}