XBT_INFO("# Add one more process on each VM");
xbt_dynar_foreach(vms, i, vm) {
unsigned int index = i + xbt_dynar_length(vms);
- char *vm_name = bprintf("VM%02d", i);
- char *pr_name = bprintf("WRK%02d", index);
- char *vm_name = bprintf("VM%02u", i);
- char *pr_name = bprintf("WRK%02u", index);
++ char* vm_name = bprintf("VM%02u", i);
++ char* pr_name = bprintf("WRK%02u", index);
XBT_INFO("put a process (%s) on %s", pr_name, vm_name);
MSG_process_create(pr_name, worker_fun, NULL, (msg_host_t)vm);
static int max_simulation_time = 1000;
typedef struct s_node {
- int id; //128bits generated random(2^128 -1)
- int known_id;
- unsigned id; //128bits generated random(2^128 -1)
++ unsigned id; // 128bits generated random(2^128 -1)
+ unsigned known_id;
char mailbox[MAILBOX_NAME_SIZE]; // my mailbox name (string representation of the id)
- int namespace_set[NAMESPACE_SIZE];
- int neighborhood_set[NEIGHBORHOOD_SIZE];
- int routing_table[LEVELS_COUNT][LEVEL_SIZE];
+ unsigned namespace_set[NAMESPACE_SIZE];
+ unsigned neighborhood_set[NEIGHBORHOOD_SIZE];
+ unsigned routing_table[LEVELS_COUNT][LEVEL_SIZE];
int ready;
msg_comm_t comm_receive; // current communication to receive
xbt_dynar_t pending_tasks;
typedef struct s_task_data {
e_task_type_t type; // type of task
- int sender_id; // id parameter (used by some types of tasks)
- //int request_finger; // finger parameter (used by some types of tasks)
- int answer_id; // answer (used by some types of tasks)
+ unsigned sender_id; // id parameter (used by some types of tasks)
- //int request_finger; // finger parameter (used by some types of tasks)
++ // int request_finger; // finger parameter (used by some types of tasks)
+ unsigned answer_id; // answer (used by some types of tasks)
char answer_to[MAILBOX_NAME_SIZE]; // mailbox to send an answer to (if any)
//const char* issuer_host_name; // used for logging
int steps;
/** @brief Like malloc, but xbt_die() on error
@hideinitializer */
static XBT_ALWAYS_INLINE void *xbt_malloc(size_t n) {
- void *res;
- /* if (n==0) {
- xbt_backtrace_display_current();
- xbt_die("malloc(0) is not portable");
- }*/
-
- res = malloc(n);
- void *res = malloc(n);
++ void* res = malloc(n);
if (!res)
xbt_die("Memory allocation of %lu bytes failed", (unsigned long)n);
return res;
/** @brief like malloc, but xbt_die() on error and memset data to 0
@hideinitializer */
static XBT_ALWAYS_INLINE void *xbt_malloc0(size_t n) {
- void *res;
- //if (n==0) xbt_die("calloc(0) is not portable");
- res = calloc(n, 1);
- void *res = calloc(n, 1);
++ void* res = calloc(n, 1);
if (!res)
xbt_die("Memory callocation of %lu bytes failed", (unsigned long)n);
return res;
#include <climits>
#include <functional>
++#include <map>
#include <stdexcept>
#include <string>
-#include <typeinfo>
#include <type_traits>
- #include <unordered_map>
+#include <typeinfo>
#include <vector>
#include <xbt/ex.hpp>
class Config {
private:
// name -> ConfigElement:
- std::unordered_map<std::string, simgrid::config::ConfigurationElement*> options;
- xbt_dict_t options;
++ std::map<std::string, simgrid::config::ConfigurationElement*> options;
// alias -> xbt_dict_elm_t from options:
- std::unordered_map<std::string, simgrid::config::ConfigurationElement*> aliases;
- xbt_dict_t aliases;
- bool warn_for_aliases;
++ std::map<std::string, simgrid::config::ConfigurationElement*> aliases;
++ bool warn_for_aliases = true;
public:
- Config();
+ Config() = default;
~Config();
// No copy:
Config::~Config()
{
XBT_DEBUG("Frees cfg set %p", this);
- xbt_dict_free(&this->options);
- xbt_dict_free(&this->aliases);
+ for (auto elm : options)
+ delete elm.second;
}
-inline
-xbt_dictelm_t Config::getDictElement(const char* name)
+inline ConfigurationElement* Config::getDictElement(const char* name)
{
- // We are interested in the options dictelm:
- xbt_dictelm_t res = xbt_dict_get_elm_or_null(options, name);
- if (res)
- return res;
- // The aliases dict stores pointers to the options dictelm:
- res = (xbt_dictelm_t) xbt_dict_get_or_null(aliases, name);
- if (res && warn_for_aliases)
- XBT_INFO("Option %s has been renamed to %s. Consider switching.", name, res->key);
- return res;
+ try {
+ return options.at(name);
+ } catch (std::out_of_range& unfound) {
+ try {
+ ConfigurationElement* res = aliases.at(name);
- XBT_INFO("Option %s has been renamed to %s. Consider switching.", name, res->getKey().c_str());
++ if (warn_for_aliases)
++ XBT_INFO("Option %s has been renamed to %s. Consider switching.", name, res->getKey().c_str());
+ return res;
+ } catch (std::out_of_range& missing_key) {
+ throw simgrid::config::missing_key_error(std::string("Bad config key: ") + name);
+ }
+ }
}
-inline
-ConfigurationElement& Config::operator[](const char* name)
+inline ConfigurationElement& Config::operator[](const char* name)
{
- xbt_dictelm_t elm = getDictElement(name);
- if (elm == nullptr)
- throw simgrid::config::missing_key_error(std::string("Bad config key, ") + name);
- return *(ConfigurationElement*)elm->content;
+ return *(getDictElement(name));
}
void Config::alias(const char* realname, const char* aliasname)
/** @brief Displays the declared aliases and their description */
void Config::showAliases()
{
- std::vector<std::string> names;
- xbt_dict_cursor_t dict_cursor;
- xbt_dictelm_t dictel;
- char *name;
- std::vector<char*> names;
-
- xbt_dict_foreach(this->aliases, dict_cursor, name, dictel)
- names.push_back(name);
- std::sort(begin(names), end(names), [](char* a, char* b) { return strcmp(a, b) < 0; });
--
+ bool old_warn_for_aliases = false;
+ std::swap(warn_for_aliases, old_warn_for_aliases);
- for (auto name : names)
- printf(" %s: %s\n", name, (*this)[name].getDescription().c_str());
+ for (auto elm : aliases)
- names.push_back(elm.first);
- std::sort(names.begin(), names.end());
-
- for (auto name : names)
- printf(" %s: %s\n", name.c_str(), (*this)[name.c_str()].getDescription().c_str());
++ printf(" %s: %s\n", elm.first.c_str(), (*this)[elm.first.c_str()].getDescription().c_str());
+ std::swap(warn_for_aliases, old_warn_for_aliases);
}
/** @brief Displays the declared options and their description */
void Config::help()
{
- std::vector<std::string> names;
- xbt_dict_cursor_t dict_cursor;
- simgrid::config::ConfigurationElement* variable;
- char *name;
- std::vector<char*> names;
--
- for (auto elm : options)
- names.push_back(elm.first);
- std::sort(names.begin(), names.end());
- xbt_dict_foreach(this->options, dict_cursor, name, variable)
- names.push_back(name);
- std::sort(begin(names), end(names), [](char* a, char* b) { return strcmp(a, b) < 0; });
--
-- for (auto name : names) {
- simgrid::config::ConfigurationElement* variable = this->options.at(name);
- printf(" %s: %s\n", name.c_str(), variable->getDescription().c_str());
- variable = (simgrid::config::ConfigurationElement*) xbt_dict_get(this->options, name);
- printf(" %s: %s\n", name, variable->getDescription().c_str());
++ for (auto elm : options) {
++ simgrid::config::ConfigurationElement* variable = this->options.at(elm.first);
++ printf(" %s: %s\n", elm.first.c_str(), variable->getDescription().c_str());
printf(" Type: %s; ", variable->getTypeName());
printf("Current value: %s\n", variable->getStringValue().c_str());
}
static void print_buffer_int(void *buf, int len, char *msg, int rank)
{
- int* v;
printf("[%d] %s (#%d): ", rank, msg, len);
for (int tmp = 0; tmp < len; tmp++) {
- v = buf;
- int *v = buf;
++ int* v = buf;
printf("[%d]", v[tmp]);
}
printf("\n");
if (!rbuf)
fprintf(stderr, "\trbuf of %d bytes\n", MAX_BUF);
if (!recvcounts)
- fprintf(stderr, "\trecvcounts of %zd bytes\n", comm_size * sizeof(int));
- fprintf(stderr, "\trecvcounts of %zu bytes\n", comm_size * sizeof(int));
++ fprintf(stderr, "\trecvcounts of %zu bytes\n", comm_size * sizeof(int));
if (!displs)
- fprintf(stderr, "\tdispls of %zd bytes\n", comm_size * sizeof(int));
- fprintf(stderr, "\tdispls of %zu bytes\n", comm_size * sizeof(int));
++ fprintf(stderr, "\tdispls of %zu bytes\n", comm_size * sizeof(int));
fflush(stderr);
MPI_Abort(MPI_COMM_WORLD, -1);
}
* this can generate a file that diff, for example,
* believes is a binary file */
if (isprint((int) (s1[j].c))) {
- fprintf(stderr, "Got s[%d].c = %c; expected %c\n",
- j, s1[j].c, j + status.MPI_SOURCE + 'a');
- fprintf(stderr, "Got s[%d].c = %c; expected %c\n", j, s1[j].c, j + status.MPI_SOURCE + 'a');
++ fprintf(stderr, "Got s[%d].c = %c; expected %c\n", j, s1[j].c, j + status.MPI_SOURCE + 'a');
}
else {
- fprintf(stderr, "Got s[%d].c = %x; expected %c\n",
- j, (int) s1[j].c, j + status.MPI_SOURCE + 'a');
- fprintf(stderr, "Got s[%d].c = %hhx; expected %c\n", j, s1[j].c, j + status.MPI_SOURCE + 'a');
++ fprintf(stderr, "Got s[%d].c = %hhx; expected %c\n", j, s1[j].c, j + status.MPI_SOURCE + 'a');
}
}
}
if (MPI_LONG_DOUBLE != MPI_DATATYPE_NULL) {
MPI_Type_size(MPI_LONG_DOUBLE, &type_size);
if (type_size != sizeof(long double)) {
- printf("type_size != sizeof(long double) : (%d != %zd)\n",
- type_size, sizeof(long double));
- printf("type_size != sizeof(long double) : (%d != %zu)\n", type_size, sizeof(long double));
-- ++errs;
++ printf("type_size != sizeof(long double) : (%d != %zu)\n", type_size, sizeof(long double));
++ ++errs;
}
}
#endif
if (MPI_C_LONG_DOUBLE_COMPLEX != MPI_DATATYPE_NULL) {
MPI_Type_size(MPI_C_LONG_DOUBLE_COMPLEX, &type_size);
if (type_size != sizeof(long double _Complex)) {
- printf("type_size != sizeof(long double _Complex) : (%d != %zd)\n",
- type_size, sizeof(long double _Complex));
- printf("type_size != sizeof(long double _Complex) : (%d != %zu)\n", type_size,
- sizeof(long double _Complex));
-- ++errs;
++ printf("type_size != sizeof(long double _Complex) : (%d != %zu)\n", type_size,
++ sizeof(long double _Complex));
++ ++errs;
}
}
#endif