void Peer::sendHandshakeToAllPeers()
{
- for (auto const& kv : connected_peers) {
- const Connection& remote_peer = kv.second;
+ for (auto const& [_, remote_peer] : connected_peers) {
auto* handshake = new Message(MessageType::HANDSHAKE, id, mailbox_);
remote_peer.mailbox_->put_init(handshake, message_size(MessageType::HANDSHAKE))->detach();
XBT_DEBUG("Sending a HANDSHAKE to %d", remote_peer.id);
void Peer::sendHaveToAllPeers(unsigned int piece)
{
XBT_DEBUG("Sending HAVE message to all my peers");
- for (auto const& kv : connected_peers) {
- const Connection& remote_peer = kv.second;
+ for (auto const& [_, remote_peer] : connected_peers) {
remote_peer.mailbox_->put_init(new Message(MessageType::HAVE, id, mailbox_, piece), message_size(MessageType::HAVE))
->detach();
}
/**If we are currently seeding, we unchoke the peer which has been unchoked the last time.*/
if (hasFinished()) {
double unchoke_time = sg4::Engine::get_clock() + 1;
- for (auto& kv : connected_peers) {
- Connection& remote_peer = kv.second;
+ for (auto& [_, remote_peer] : connected_peers) {
if (remote_peer.last_unchoke < unchoke_time && remote_peer.interested && remote_peer.choked_upload) {
unchoke_time = remote_peer.last_unchoke;
chosen_peer = &remote_peer;
} else {
// Use the "fastest download" policy.
double fastest_speed = 0.0;
- for (auto& kv : connected_peers) {
- Connection& remote_peer = kv.second;
+ for (auto& [_, remote_peer] : connected_peers) {
if (remote_peer.peer_speed > fastest_speed && remote_peer.choked_upload && remote_peer.interested) {
fastest_speed = remote_peer.peer_speed;
chosen_peer = &remote_peer;
/** @brief Update "interested" state of peers: send "not interested" to peers that don't have any more pieces we want.*/
void Peer::updateInterestedAfterReceive()
{
- for (auto& kv : connected_peers) {
- Connection& remote_peer = kv.second;
+ for (auto& [_, remote_peer] : connected_peers) {
if (remote_peer.am_interested) {
bool interested = false;
// Check if the peer still has a piece we want.
{
XBT_INFO("Searching %08x, size %zu", destination_id_, nodes_.size());
unsigned int i = 0;
- for (auto const& contact : nodes_)
- XBT_INFO("Node %08x: %08x is at distance %u", i++, contact.first, contact.second);
+ for (auto const& [contact, distance] : nodes_)
+ XBT_INFO("Node %08x: %08x is at distance %u", i++, contact, distance);
}
/** @brief Merge two answers together, only keeping the best nodes
// retrieve the node list and ping them.
const Answer* node_list = msg->answer_.get();
if (node_list) {
- for (auto const& contact : node_list->getNodes())
- routingTableUpdate(contact.first);
+ for (auto const& [contact, _] : node_list->getNodes())
+ routingTableUpdate(contact);
} else {
handleFindNode(msg);
}
unsigned int i = 0;
unsigned int j = 0;
unsigned int destination = node_list->getDestinationId();
- for (auto const& node_to_query : node_list->getNodes()) {
+ for (auto const& [node_to_query, _] : node_list->getNodes()) {
/* We need to have at most "KADEMLIA_ALPHA" requests each time, according to the protocol */
/* Gets the node we want to send the query to */
- if (node_to_query.first != id_) { /* No need to query ourselves */
- sendFindNode(node_to_query.first, destination);
+ if (node_to_query != id_) { /* No need to query ourselves */
+ sendFindNode(node_to_query, destination);
j++;
}
i++;
if (msg->answer_ && msg->answer_->getDestinationId() == id_to_find) {
routingTableUpdate(msg->sender_id_);
// Handle the answer
- for (auto const& contact : node_list->getNodes())
- routingTableUpdate(contact.first);
+ for (auto const& [contact, _] : node_list->getNodes())
+ routingTableUpdate(contact);
answers++;
nodes_added = node_list->merge(msg->answer_.get());
/* - Display Host properties */
for (auto h : e.get_all_hosts()) {
XBT_INFO("*** %s properties ****", h->get_cname());
- for (auto const& kv : *h->get_properties())
- XBT_INFO(" %s -> %s", kv.first.c_str(), kv.second.c_str());
+ for (auto const& [key, value] : *h->get_properties())
+ XBT_INFO(" %s -> %s", key.c_str(), value.c_str());
}
sg4::Actor::create("", e.host_by_name("bob"), host);
static double get_factor_from_map(const std::map<double, double>& factors, double size)
{
double factor = 1.0;
- for (auto const& fact : factors) {
- if (size < fact.first) {
+ for (auto const& [factor_size, factor_value] : factors) {
+ if (size < factor_size) {
break;
} else {
- factor = fact.second;
+ factor = factor_value;
}
}
return factor;
XBT_INFO("== Print the properties of the host '%s'", hostname.c_str());
// Sort the properties before displaying them, so that the tests are perfectly reproducible
std::vector<std::string> keys;
- for (auto const& kv : *hostprops)
- keys.push_back(kv.first);
+ for (auto const& [key, _] : *hostprops)
+ keys.push_back(key);
std::sort(keys.begin(), keys.end());
for (const std::string& key : keys)
XBT_INFO(" Host property: '%s' -> '%s'", key.c_str(), hostprops->at(key).c_str());
XBT_INFO("== Print the properties of the zone '%s' that contains '%s'", thezone->get_cname(), hostname.c_str());
const std::unordered_map<std::string, std::string>* zoneprops = thezone->get_properties();
keys.clear();
- for (auto const& kv : *zoneprops)
- keys.push_back(kv.first);
+ for (auto const& [key, _] : *zoneprops)
+ keys.push_back(key);
std::sort(keys.begin(), keys.end());
for (const std::string& key : keys)
XBT_INFO(" Zone property: '%s' -> '%s'", key.c_str(), zoneprops->at(key).c_str());
/* Get the property list of current bob actor */
const std::unordered_map<std::string, std::string>* props = sg4::Actor::self()->get_properties();
const char* noexist = "UnknownProcessProp";
- XBT_ATTRIB_UNUSED const char* value;
XBT_INFO("== Print the properties of the actor");
- for (const auto& kv : *props)
- XBT_INFO(" Actor property: %s -> %s", kv.first.c_str(), kv.second.c_str());
+ for (const auto& [key, value] : *props)
+ XBT_INFO(" Actor property: %s -> %s", key.c_str(), value.c_str());
XBT_INFO("== Try to get an actor property that does not exist");
- value = sg4::Actor::self()->get_property(noexist);
+ const char* value = sg4::Actor::self()->get_property(noexist);
xbt_assert(not value, "The property is defined (it should not)");
}
* Files not produced in the system are said to be produced by root task (top of DAG).
* Files not consumed in the system are said to be consumed by end task (bottom of DAG).
*/
- CommPtr file;
-
- for (auto const& elm : files) {
- file = elm.second;
+ for (auto const& [_, elm] : files) {
+ CommPtr file = elm;
CommPtr newfile;
if (file->dependencies_solved()) {
for (auto const& it : file->get_successors()) {
{
XBT_DEBUG("destroy container %s", get_cname());
// Begin with destroying my own children
- for (auto child : children_)
- delete child.second;
+ for (auto [_, child] : children_)
+ delete child;
// remove me from the all_containers_ data structure
all_containers_.erase(name_);
Type* Type::by_name(const std::string& name)
{
Type* ret = nullptr;
- for (auto const& elm : children_) {
- if (elm.second->name_ == name) {
+ for (auto const& [_, child] : children_) {
+ if (child->name_ == name) {
if (ret != nullptr) {
throw TracingError(XBT_THROW_POINT, "there are two children types with the same name?");
} else {
- ret = elm.second.get();
+ ret = child.get();
}
}
}
std::map<std::string, xbt_edge_t, std::less<>> edges;
netzone->get_impl()->get_graph(graph, &nodes, &edges);
- for (auto const& elm : edges) {
- const xbt_edge* edge = elm.second;
+ for (auto const& [_, edge] : edges) {
linkContainers(simgrid::instr::Container::by_name(static_cast<const char*>(edge->src->data)),
simgrid::instr::Container::by_name(static_cast<const char*>(edge->dst->data)), filter);
}
if (root->get_name() == "LINK")
root->by_name_or_create(std::string("b") + new_typename, color);
- for (auto const& elm : root->get_children()) {
- recursiveNewVariableType(new_typename, color, elm.second.get());
+ for (auto const& [_, child] : root->get_children()) {
+ recursiveNewVariableType(new_typename, color, child.get());
}
}
if (root->get_name() == parent_type) {
root->by_name_or_create(new_typename, color);
}
- for (auto const& elm : root->get_children())
- recursiveNewUserVariableType(parent_type, new_typename, color, elm.second.get());
+ for (auto const& [_, child] : root->get_children())
+ recursiveNewUserVariableType(parent_type, new_typename, color, child.get());
}
void instr_new_user_variable_type(const std::string& parent_type, const std::string& new_typename,
if (root->get_name() == parent_type)
root->by_name_or_create<simgrid::instr::StateType>(new_typename);
- for (auto const& elm : root->get_children())
- recursiveNewUserStateType(parent_type, new_typename, elm.second.get());
+ for (auto const& [_, child] : root->get_children())
+ recursiveNewUserStateType(parent_type, new_typename, child.get());
}
void instr_new_user_state_type(const std::string& parent_type, const std::string& new_typename)
if (root->get_name() == type_name)
static_cast<simgrid::instr::StateType*>(root)->add_entity_value(val, color);
- for (auto const& elm : root->get_children())
- recursiveNewValueForUserStateType(type_name, val, color, elm.second.get());
+ for (auto const& [_, child] : root->get_children())
+ recursiveNewValueForUserStateType(type_name, val, color, child.get());
}
void instr_new_value_for_user_state_type(const std::string& type_name, const char* value, const std::string& color)
fs << " node [shape=box, style=filled]" << std::endl;
fs << " node [width=.3, height=.3, style=filled, color=skyblue]" << std::endl << std::endl;
- for (auto const& elm : nodes)
- fs << " \"" << elm.first << "\";" << std::endl;
+ for (auto const& [node, _] : nodes)
+ fs << " \"" << node << "\";" << std::endl;
- for (auto const& elm : edges) {
- const char* src_s = static_cast<char*>(elm.second->src->data);
- const char* dst_s = static_cast<char*>(elm.second->dst->data);
+ for (auto const& [_, edge] : edges) {
+ const char* src_s = static_cast<char*>(edge->src->data);
+ const char* dst_s = static_cast<char*>(edge->dst->data);
if (g->directed)
fs << " \"" << src_s << "\" -> \"" << dst_s << "\";" << std::endl;
else
{
std::string res;
std::string sep = "";
- for (auto const& factory : context_factories) {
- res += sep + factory.first;
+ for (auto const& [factory_name, _] : context_factories) {
+ res += sep + factory_name;
sep = ", ";
}
return res;
{
/* Also delete the other data */
delete netzone_root_;
- for (auto const& kv : netpoints_)
- delete kv.second;
+ for (auto const& [_, netpoint] : netpoints_)
+ delete netpoint;
- for (auto const& kv : mailboxes_)
- delete kv.second;
+ for (auto const& [_, mailbox] : mailboxes_)
+ delete mailbox;
/* Kill all actors (but maestro) */
maestro_->kill_all();
return;
}
/* use the factory specified by --cfg=contexts/factory:value */
- for (auto const& factory : context_factories)
- if (context_factory_name == factory.first) {
- instance_->set_context_factory(factory.second());
+ for (auto const& [factory_name, factory] : context_factories)
+ if (context_factory_name == factory_name) {
+ instance_->set_context_factory(factory());
break;
}
XBT_INFO("%zu actors are still running, waiting for something.", actor_list_.size());
/* List the actors and their state */
XBT_INFO("Legend of the following listing: \"Actor <pid> (<name>@<host>): <status>\"");
- for (auto const& kv : actor_list_) {
- const actor::ActorImpl* actor = kv.second;
-
+ for (auto const& [_, actor] : actor_list_) {
if (actor->waiting_synchro_) {
const char* synchro_description = "unknown";
}
display_all_actor_status();
simgrid::s4u::Engine::on_deadlock();
- for (auto const& kv : actor_list_) {
- XBT_DEBUG("Kill %s", kv.second->get_cname());
- maestro_->kill(kv.second);
+ for (auto const& [_, actor] : actor_list_) {
+ XBT_DEBUG("Kill %s", actor->get_cname());
+ maestro_->kill(actor);
}
}
} while ((vetoed_activities == nullptr || vetoed_activities->empty()) &&
void ActorImpl::kill_all() const
{
- for (auto const& kv : EngineImpl::get_instance()->get_actor_list())
- if (kv.second != this)
- this->kill(kv.second);
+ for (auto const& [_, actor] : EngineImpl::get_instance()->get_actor_list())
+ if (actor != this)
+ this->kill(actor);
}
void ActorImpl::set_kill_time(double kill_time)
std::string BmfSolver::debug_alloc(const allocation_map_t& alloc) const
{
std::stringstream debug;
- for (const auto& e : alloc) {
- debug << "{" + std::to_string(e.first) + ": [" + debug_vector(e.second) + "]}, ";
+ for (const auto& [resource, players] : alloc) {
+ debug << "{" + std::to_string(resource) + ": [" + debug_vector(players) + "]}, ";
}
return debug.str();
}
std::vector<int> BmfSolver::alloc_map_to_vector(const allocation_map_t& alloc) const
{
std::vector<int> alloc_by_player(A_.cols(), -1);
- for (const auto& it : alloc) {
- for (auto p : it.second) {
- alloc_by_player[p] = it.first;
+ for (const auto& [resource, players] : alloc) {
+ for (auto p : players) {
+ alloc_by_player[p] = resource;
}
}
return alloc_by_player;
std::vector<int> BmfSolver::get_bounded_players(const allocation_map_t& alloc) const
{
std::vector<int> bounded_players;
- for (const auto& e : alloc) {
- if (e.first == NO_RESOURCE) {
- bounded_players.insert(bounded_players.end(), e.second.begin(), e.second.end());
+ for (const auto& [resource, players] : alloc) {
+ if (resource == NO_RESOURCE) {
+ bounded_players.insert(bounded_players.end(), players.begin(), players.end());
}
}
return bounded_players;
int row = 0;
auto bounded_players = get_bounded_players(alloc);
- for (const auto& e : alloc) {
+ for (const auto& [resource, players] : alloc) {
// add one row for the resource with A[r,]
- int cur_resource = e.first;
/* bounded players, nothing to do */
- if (cur_resource == NO_RESOURCE)
+ if (resource == NO_RESOURCE)
continue;
/* not shared resource, each player can receive the full capacity of the resource */
- if (not C_shared_[cur_resource]) {
- for (int i : e.second) {
- C_p[row] = get_resource_capacity(cur_resource, bounded_players);
- A_p(row, i) = A_(cur_resource, i);
+ if (not C_shared_[resource]) {
+ for (int i : players) {
+ C_p[row] = get_resource_capacity(resource, bounded_players);
+ A_p(row, i) = A_(resource, i);
row++;
}
continue;
}
/* shared resource: fairly share it between players */
- A_p.row(row) = A_.row(cur_resource);
- C_p[row] = get_resource_capacity(cur_resource, bounded_players);
+ A_p.row(row) = A_.row(resource);
+ C_p[row] = get_resource_capacity(resource, bounded_players);
row++;
- if (e.second.size() > 1) {
+ if (players.size() > 1) {
// if 2 players have chosen the same resource
// they must have a fair sharing of this resource, adjust A_p and C_p accordingly
- auto it = e.second.begin();
+ auto it = players.begin();
int i = *it; // first player
/* for each other player sharing this resource */
- for (++it; it != e.second.end(); ++it) {
+ for (++it; it != players.end(); ++it) {
/* player i and k on this resource j: so maxA_ji*rho_i - maxA_jk*rho_k = 0 */
int k = *it;
C_p[row] = 0;
- A_p(row, i) = maxA_(cur_resource, i);
- A_p(row, k) = -maxA_(cur_resource, k);
+ A_p(row, i) = maxA_(resource, i);
+ A_p(row, k) = -maxA_(resource, k);
row++;
}
}
void tmgr_finalize()
{
- for (auto const& kv : trace_list)
- delete kv.second;
+ for (auto const& [_, trace] : trace_list)
+ delete trace;
trace_list.clear();
}
insert_link_latency(route->link_list_, e_route->link_list_, lat);
}
- auto elm = route_cache_.try_emplace(src_id);
- std::vector<unsigned long>& pred_arr = elm.first->second;
+ auto [elm, inserted] = route_cache_.try_emplace(src_id);
+ std::vector<unsigned long>& pred_arr = elm->second;
- if (elm.second) { /* new element was inserted (not cached mode, or cache miss) */
+ if (inserted) { /* new element was inserted (not cached mode, or cache miss) */
unsigned long nr_nodes = xbt_dynar_length(nodes);
std::vector<unsigned long> cost_arr(nr_nodes); /* link cost from src to other hosts */
pred_arr.resize(nr_nodes); /* predecessors in path from src */
/* Since hosts_ and links_ are a std::map, the hosts are destroyed in the lexicographic order, which ensures that the
* output is reproducible.
*/
- for (auto& host : hosts_) {
- host.second->destroy();
+ for (auto& [_, host] : hosts_) {
+ host->destroy();
}
hosts_.clear();
- for (auto& link : links_) {
- link.second->destroy();
+ for (auto& [_, link] : links_) {
+ link->destroy();
}
links_.clear();
- for (auto const& kv : bypass_routes_)
- delete kv.second;
+ for (auto const& [_, route] : bypass_routes_)
+ delete route;
s4u::Engine::get_instance()->netpoint_unregister(netpoint_);
}
std::vector<s4u::Link*> NetZoneImpl::get_filtered_links(const std::function<bool(s4u::Link*)>& filter) const
{
std::vector<s4u::Link*> filtered_list;
- for (auto const& kv : links_) {
- s4u::Link* l = kv.second->get_iface();
+ for (auto const& [_, link] : links_) {
+ s4u::Link* l = link->get_iface();
if (filter(l))
filtered_list.push_back(l);
}
resource::HostImpl* NetZoneImpl::get_host_by_name_or_null(const std::string& name) const
{
- for (auto const& kv : hosts_) {
- auto* host = kv.second;
+ for (auto const& [_, host] : hosts_) {
if (host->get_name() == name)
return host;
/* keep old behavior where host and VMs were saved together on EngineImpl::hosts_
std::vector<s4u::Host*> NetZoneImpl::get_filtered_hosts(const std::function<bool(s4u::Host*)>& filter) const
{
std::vector<s4u::Host*> filtered_list;
- for (auto const& kv : hosts_) {
- s4u::Host* h = kv.second->get_iface();
+ for (auto const& [_, host] : hosts_) {
+ s4u::Host* h = host->get_iface();
if (filter(h))
filtered_list.push_back(h);
/* Engine::get_hosts returns the VMs too */
}
/* sealing links */
- for (auto const& kv : links_)
- kv.second->get_iface()->seal();
+ for (auto const& [_, link] : links_)
+ link->get_iface()->seal();
for (auto* sub_net : get_children()) {
sub_net->seal();
{
/* add default empty links if nothing was configured by user */
for (auto const& node : get_vertices()) {
- auto route = routes_.try_emplace(node->id());
- if (route.second) {
- route.first->second.links_down_set = true;
- route.first->second.links_up_set = true;
+ auto [route, inserted] = routes_.try_emplace(node->id());
+ if (inserted) {
+ route->second.links_down_set = true;
+ route->second.links_up_set = true;
}
}
}
void ModelChecker::setup_ignore()
{
const RemoteProcess& process = this->get_remote_process();
- for (auto const& var : ignored_local_variables)
- process.ignore_local_variable(var.first, var.second);
+ for (auto const& [var, frame] : ignored_local_variables)
+ process.ignore_local_variable(var, frame);
/* Static variable used for tracing */
process.ignore_global_variable("counter");
XBT_DEBUG("Snapshot %p of visited state %ld (exploration stack state %ld)", new_state->system_state.get(),
new_state->num, graph_state->get_num());
- auto range = boost::range::equal_range(states_, new_state.get(), Api::get().compare_pair());
+ auto [range_begin, range_end] = boost::range::equal_range(states_, new_state.get(), Api::get().compare_pair());
if (compare_snapshots)
- for (auto i = range.first; i != range.second; ++i) {
+ for (auto i = range_begin; i != range_end; ++i) {
auto& visited_state = *i;
if (Api::get().snapshot_equal(visited_state->system_state.get(), new_state->system_state.get())) {
// The state has been visited:
}
XBT_DEBUG("Insert new visited state %ld (total : %lu)", new_state->num, (unsigned long)states_.size());
- states_.insert(range.first, std::move(new_state));
+ states_.insert(range_begin, std::move(new_state));
this->prune();
return nullptr;
}
auto new_pair =
std::make_shared<VisitedPair>(pair->num, pair->automaton_state, pair->atomic_propositions, pair->graph_state);
- auto res = boost::range::equal_range(acceptance_pairs_, new_pair.get(), Api::get().compare_pair());
+ auto [res_begin, res_end] = boost::range::equal_range(acceptance_pairs_, new_pair.get(), Api::get().compare_pair());
if (pair->search_cycle)
- for (auto i = res.first; i != res.second; ++i) {
+ for (auto i = res_begin; i != res_end; ++i) {
std::shared_ptr<simgrid::mc::VisitedPair> const& pair_test = *i;
if (xbt_automaton_state_compare(pair_test->automaton_state, new_pair->automaton_state) != 0 ||
*(pair_test->atomic_propositions) != *(new_pair->atomic_propositions) ||
return nullptr;
}
- acceptance_pairs_.insert(res.first, new_pair);
+ acceptance_pairs_.insert(res_begin, new_pair);
return new_pair;
}
visited_pair =
std::make_shared<VisitedPair>(pair->num, pair->automaton_state, pair->atomic_propositions, pair->graph_state);
- auto range = boost::range::equal_range(visited_pairs_, visited_pair.get(), Api::get().compare_pair());
+ auto [range_begin, range_end] =
+ boost::range::equal_range(visited_pairs_, visited_pair.get(), Api::get().compare_pair());
- for (auto i = range.first; i != range.second; ++i) {
+ for (auto i = range_begin; i != range_end; ++i) {
const VisitedPair* pair_test = i->get();
if (xbt_automaton_state_compare(pair_test->automaton_state, visited_pair->automaton_state) != 0 ||
*(pair_test->atomic_propositions) != *(visited_pair->atomic_propositions) ||
return (*i)->other_num;
}
- visited_pairs_.insert(range.first, std::move(visited_pair));
+ visited_pairs_.insert(range_begin, std::move(visited_pair));
this->purge_visited_pairs();
return -1;
}
void ObjectInformation::remove_local_variable(const char* var_name, const char* subprogram_name)
{
- for (auto& entry : this->subprograms)
- mc::remove_local_variable(entry.second, var_name, subprogram_name, entry.second);
+ for (auto& [_, entry] : this->subprograms)
+ mc::remove_local_variable(entry, var_name, subprogram_name, entry);
}
/** @brief Fills the position of the segments (executable, read-only, read/write) */
{
info->functions_index.clear();
- for (auto& e : info->subprograms) {
- if (e.second.range.begin() == 0)
+ for (auto& [_, e] : info->subprograms) {
+ if (e.range.begin() == 0)
continue;
simgrid::mc::FunctionIndexEntry entry;
- entry.low_pc = (void*)e.second.range.begin();
- entry.function = &e.second;
+ entry.low_pc = (void*)e.range.begin();
+ entry.function = &e;
info->functions_index.push_back(entry);
}
static void MC_post_process_types(simgrid::mc::ObjectInformation* info)
{
// Lookup "subtype" field:
- for (auto& i : info->types) {
- i.second.subtype = MC_resolve_type(info, i.second.type_id);
- for (simgrid::mc::Member& member : i.second.members)
+ for (auto& [_, i] : info->types) {
+ i.subtype = MC_resolve_type(info, i.type_id);
+ for (simgrid::mc::Member& member : i.members)
member.type = MC_resolve_type(info, member.type_id);
}
}
MC_load_dwarf(this);
MC_post_process_variables(this);
MC_post_process_types(this);
- for (auto& entry : this->subprograms)
- mc_post_process_scope(this, &entry.second);
+ for (auto& [_, entry] : this->subprograms)
+ mc_post_process_scope(this, &entry);
MC_make_functions_index(this);
}
void postProcessObjectInformation(const RemoteProcess* process, ObjectInformation* info)
{
- for (auto& t : info->types) {
- Type* type = &(t.second);
+ for (auto& [_, t] : info->types) {
+ Type* type = &t;
Type* subtype = type;
while (subtype->type == DW_TAG_typedef || subtype->type == DW_TAG_volatile_type ||
subtype->type == DW_TAG_const_type)
}
#if SIMGRID_HAVE_MC
engine->reset_actor_dynar();
- for (auto const& kv : engine->get_actor_list()) {
- auto actor = kv.second;
+ for (auto const& [_, actor] : engine->get_actor_list()) {
// Only visible requests remain at this point, and they all have an observer
actor->simcall_.mc_max_consider_ = actor->simcall_.observer_->get_max_consider();
static XBT_ALWAYS_INLINE void* mc_translate_address_region(uintptr_t addr, const simgrid::mc::Region* region)
{
- auto split = simgrid::mc::mmu::split(addr - region->start().address());
- auto pageno = split.first;
- auto offset = split.second;
- void* snapshot_page = region->get_chunks().page(pageno);
+ auto [pageno, offset] = simgrid::mc::mmu::split(addr - region->start().address());
+ void* snapshot_page = region->get_chunks().page(pageno);
return (char*)snapshot_page + offset;
}
void DirtyPageTrackingExt::start_tracking()
{
dp_tracking_ = true;
- for (auto const& elm : dp_objs_)
- dp_objs_[elm.first] = elm.first->get_remaining();
+ for (auto const& [exec, _] : dp_objs_)
+ dp_objs_[exec] = exec->get_remaining();
}
double DirtyPageTrackingExt::computed_flops_lookup()
{
double total = 0;
- for (auto const& elm : dp_objs_) {
- total += elm.second - elm.first->get_remaining();
- dp_objs_[elm.first] = elm.first->get_remaining();
+ for (auto const& [exec, flops] : dp_objs_) {
+ total += flops - exec->get_remaining();
+ dp_objs_[exec] = exec->get_remaining();
}
total += dp_updated_by_deleted_tasks_;
const std::unordered_map<std::string, std::string>* props = actor->get_properties();
if (props == nullptr)
return nullptr;
- for (auto const& kv : *props) {
- xbt_dict_set(as_dict, kv.first.c_str(), xbt_strdup(kv.second.c_str()));
+ for (auto const& [key, value] : *props) {
+ xbt_dict_set(as_dict, key.c_str(), xbt_strdup(value.c_str()));
}
return as_dict;
}
{
/* two actors may have pushed the same mbox_create simcall at the same time */
kernel::activity::MailboxImpl* mbox = kernel::actor::simcall_answered([&name, this] {
- auto m = pimpl->mailboxes_.try_emplace(name, nullptr);
- if (m.second) {
- m.first->second = new kernel::activity::MailboxImpl(name);
- XBT_DEBUG("Creating a mailbox at %p with name %s", m.first->second, name.c_str());
+ auto [m, inserted] = pimpl->mailboxes_.try_emplace(name, nullptr);
+ if (inserted) {
+ m->second = new kernel::activity::MailboxImpl(name);
+ XBT_DEBUG("Creating a mailbox at %p with name %s", m->second, name.c_str());
}
- return m.first->second;
+ return m->second;
});
return mbox->get_iface();
}
std::vector<ActorPtr> Engine::get_all_actors() const
{
std::vector<ActorPtr> actor_list;
- for (auto const& kv : pimpl->get_actor_list()) {
- actor_list.push_back(kv.second->get_iface());
+ for (auto const& [_, actor] : pimpl->get_actor_list()) {
+ actor_list.push_back(actor->get_iface());
}
return actor_list;
}
std::vector<ActorPtr> Engine::get_filtered_actors(const std::function<bool(ActorPtr)>& filter) const
{
std::vector<ActorPtr> actor_list;
- for (auto const& kv : pimpl->get_actor_list()) {
- if (filter(kv.second->get_iface()))
- actor_list.push_back(kv.second->get_iface());
+ for (auto const& [_, actor] : pimpl->get_actor_list()) {
+ if (filter(actor->get_iface()))
+ actor_list.push_back(actor->get_iface());
}
return actor_list;
}
std::vector<kernel::routing::NetPoint*> Engine::get_all_netpoints() const
{
std::vector<kernel::routing::NetPoint*> res;
- for (auto const& kv : pimpl->netpoints_)
- res.push_back(kv.second);
+ for (auto const& [_, netpoint] : pimpl->netpoints_)
+ res.push_back(netpoint);
return res;
}
if (props == nullptr)
return nullptr;
- for (auto const& elm : *props) {
- xbt_dict_set(as_dict, elm.first.c_str(), xbt_strdup(elm.second.c_str()));
+ for (auto const& [key, value] : *props) {
+ xbt_dict_set(as_dict, key.c_str(), xbt_strdup(value.c_str()));
}
return as_dict;
}
if (not props->empty()) {
XBT_INFO(" - properties:");
- for (auto const& elm : *props) {
- XBT_INFO(" %s->%s", elm.first.c_str(), elm.second.c_str());
+ for (auto const& [key, value] : *props) {
+ XBT_INFO(" %s->%s", key.c_str(), value.c_str());
}
}
}
}
// what do I need to read ?
MPI_Offset totreads = 0;
- for (auto const& chunk : chunks) {
- if (chunk.second < my_chunk_start)
+ for (auto const& [chunk_start, chunk_end] : chunks) {
+ if (chunk_end < my_chunk_start)
continue;
- else if (chunk.first > my_chunk_end)
+ else if (chunk_start > my_chunk_end)
continue;
else
- totreads += (std::min(chunk.second, my_chunk_end - 1) - std::max(chunk.first, my_chunk_start));
+ totreads += (std::min(chunk_end, my_chunk_end - 1) - std::max(chunk_start, my_chunk_start));
}
XBT_CDEBUG(smpi_pmpi, "will have to access %lld from my chunk", totreads);
return MPI_ERR_ARG;
smpi_key_elem& elem = elem_it->second;
- int flag=0;
- auto p = attributes().emplace(keyval, attr_value);
- if (p.second) {
+ if (auto [attr, inserted] = attributes().try_emplace(keyval, attr_value); inserted) {
elem.refcount++;
} else {
- int ret = call_deleter<T>((T*)this, elem, keyval,p.first->second,&flag);
+ int flag = 0;
+ int ret = call_deleter<T>((T*)this, elem, keyval, attr->second, &flag);
// overwrite previous value
- p.first->second = attr_value;
+ attr->second = attr_value;
if(ret!=MPI_SUCCESS)
return ret;
}
}
template <typename T> void Keyval::cleanup_attr(){
- for (auto const& it : attributes()) {
- auto elem_it = T::keyvals_.find(it.first);
+ for (auto const& [key, value] : attributes()) {
+ auto elem_it = T::keyvals_.find(key);
xbt_assert(elem_it != T::keyvals_.end());
smpi_key_elem& elem = elem_it->second;
int flag = 0;
- call_deleter<T>((T*)this, elem, it.first, it.second, &flag);
+ call_deleter<T>((T*)this, elem, key, value, &flag);
elem.refcount--;
if (elem.deleted && elem.refcount == 0)
T::keyvals_.erase(elem_it);
#include "private.hpp"
#include <boost/algorithm/string.hpp>
-#include <cctype>
-#include <cstdarg>
-#include <cwchar>
#include <deque>
#include <simgrid/host.h>
#include <simgrid/s4u/Actor.hpp>
if (smpi_colors.find(state) != smpi_colors.end()) { // Exact match in the map?
return smpi_colors.find(state)->second.c_str();
}
- for (const auto& pair : smpi_colors) { // Is an entry of our map a substring of this state name?
- if (std::strstr(state.c_str(), pair.first.c_str()) != nullptr)
- return pair.second.c_str();
+ for (const auto& [smpi_state, color] : smpi_colors) { // Is an entry of our map a substring of this state name?
+ if (state.find(smpi_state) != std::string::npos)
+ return color.c_str();
}
return "0.5 0.5 0.5"; // Just in case we find nothing in the map ...
const simgrid::instr::Container* container = smpi_container(pid);
papi_counter_t counters = smpi_process()->papi_counters();
- for (auto const& it : counters) {
+ for (auto const& [counter, _] : counters) {
/**
* Check whether this variable already exists or not. Otherwise, it will be created
* multiple times but only the last one would be used...
*/
- container->get_type()->by_name_or_create(it.first, "");
+ container->get_type()->by_name_or_create(counter, "");
}
#endif
}
simgrid::instr::Container::by_name(std::string("rank-") + std::to_string(simgrid::s4u::this_actor::get_pid()));
const papi_counter_t& counter_data = smpi_process()->papi_counters();
- for (auto const& pair : counter_data) {
- container->get_variable(pair.first)->set_event(simgrid::s4u::Engine::get_clock(), pair.second);
+ for (auto const& [counter, value] : counter_data) {
+ container->get_variable(counter)->set_event(simgrid::s4u::Engine::get_clock(), value);
}
}
#endif
smpi_process()->set_sampling(1);
}
- auto insert = samples.try_emplace(loc, LocalData{
- threshold, // threshold
- 0.0, // relstderr
- 0.0, // mean
- 0.0, // sum
- 0.0, // sum_pow2
- iters, // iters
- 0, // count
- true // benching (if we have no data, we need at least one)
- });
- if (insert.second) {
+ auto [sample, inserted] = samples.try_emplace(loc,
+ LocalData{
+ threshold, // threshold
+ 0.0, // relstderr
+ 0.0, // mean
+ 0.0, // sum
+ 0.0, // sum_pow2
+ iters, // iters
+ 0, // count
+ true // benching (if we have no data, we need at least one)
+ });
+ if (inserted) {
XBT_DEBUG("XXXXX First time ever on benched nest %s.", loc.c_str());
xbt_assert(threshold > 0 || iters > 0,
"You should provide either a positive amount of iterations to bench, or a positive maximal stderr (or both)");
} else {
- LocalData& data = insert.first->second;
+ LocalData& data = sample->second;
if (data.iters != iters || data.threshold != threshold) {
XBT_ERROR("Asked to bench block %s with different settings %d, %f is not %d, %f. "
"How did you manage to give two numbers at the same line??",
}
void smpi_deployment_cleanup_instances(){
- for (auto const& item : smpi_instances) {
- XBT_INFO("Stalling SMPI instance: %s. Do all your MPI ranks call MPI_Finalize()?", item.first.c_str());
- Instance instance = item.second;
+ for (auto const& [name, instance] : smpi_instances) {
+ XBT_INFO("Stalling SMPI instance: %s. Do all your MPI ranks call MPI_Finalize()?", name.c_str());
simgrid::smpi::Comm::destroy(instance.comm_world_);
}
smpi_instances.clear();
static void memcpy_private(void* dest, const void* src, const std::vector<std::pair<size_t, size_t>>& private_blocks)
{
- for (auto const& block : private_blocks)
- memcpy((uint8_t*)dest+block.first, (uint8_t*)src+block.first, block.second-block.first);
+ for (auto const& [block_begin, block_end] : private_blocks)
+ memcpy((uint8_t*)dest + block_begin, (uint8_t*)src + block_begin, block_end - block_begin);
}
static void check_blocks(const std::vector<std::pair<size_t, size_t>>& private_blocks, size_t buff_size)
{
- for (auto const& block : private_blocks)
- xbt_assert(block.first <= block.second && block.second <= buff_size, "Oops, bug in shared malloc.");
+ for (auto const& [block_begin, block_end] : private_blocks)
+ xbt_assert(block_begin <= block_end && block_end <= buff_size, "Oops, bug in shared malloc.");
}
static void smpi_cleanup_comm_after_copy(simgrid::kernel::activity::CommImpl* comm, void* buff){
void get_requests(std::vector<MPI_Request>& vec) const
{
- for (auto const& pair : store) {
- auto& reqs = pair.second;
+ for (auto const& [_, reqs] : store) {
aid_t my_proc_id = simgrid::s4u::this_actor::get_pid();
for (auto& req: reqs){
if (req != MPI_REQUEST_NULL && (req->src() == my_proc_id || req->dst() == my_proc_id)) {
if (req != MPI_REQUEST_NULL)
Request::unref(&req);
- for (auto const& pair : sender_receiver) {
- TRACE_smpi_recv(pair.first, pair.second, 0);
+ for (auto const& [src, dst] : sender_receiver) {
+ TRACE_smpi_recv(src, dst, 0);
}
TRACE_smpi_comm_out(get_pid());
}
{
void* mem;
smpi_source_location loc(file, line);
- auto res = allocs.try_emplace(loc);
- auto data = res.first;
- if (res.second) {
+ auto [data, inserted] = allocs.try_emplace(loc);
+ if (inserted) {
// The new element was inserted.
int fd = smpi_temp_shm_get();
data->second.fd = fd;
size_t offset, size_t buff_size)
{
std::vector<std::pair<size_t, size_t>> result;
- for (auto const& block : vec) {
- auto new_block = std::make_pair(std::min(std::max((size_t)0, block.first - offset), buff_size),
- std::min(std::max((size_t)0, block.second - offset), buff_size));
+ for (auto const& [block_begin, block_end] : vec) {
+ auto new_block = std::make_pair(std::clamp(block_begin - offset, (size_t)0, buff_size),
+ std::clamp(block_end - offset, (size_t)0, buff_size));
if (new_block.second > 0 && new_block.first < buff_size)
result.push_back(new_block);
}
// freed at this point
bool display_advice = false;
std::map<std::string, int, std::less<>> count;
- for (const auto& elem : handles) {
- std::string key = elem.second->name();
- if ((not xbt_log_no_loc) && (not elem.second->call_location().empty()))
- key += " at " + elem.second->call_location();
+ for (const auto& [_, elem] : handles) {
+ std::string key = elem->name();
+ if ((not xbt_log_no_loc) && (not elem->call_location().empty()))
+ key += " at " + elem->call_location();
else
display_advice = true;
- auto result = count.try_emplace(key, 1);
- if (result.second == false)
- result.first->second++;
+ auto& result = count.try_emplace(key, 0).first->second;
+ result++;
}
if (display_advice)
XBT_WARN("To get more information (location of allocations), compile your code with -trace-call-location flag of "
"smpicc/f90");
unsigned int i = 0;
- for (const auto& p : count) {
- if (p.second == 1)
- XBT_INFO("leaked handle of type %s", p.first.c_str());
+ for (const auto& [key, value] : count) {
+ if (value == 1)
+ XBT_INFO("leaked handle of type %s", key.c_str());
else
- XBT_INFO("%d leaked handles of type %s", p.second, p.first.c_str());
+ XBT_INFO("%d leaked handles of type %s", value, key.c_str());
i++;
if (i == max)
break;
size_t max_size;
};
std::map<std::string, struct buff_leak, std::less<>> leaks_aggreg;
- for (const auto& elem : allocs) {
+ for (const auto& [_, elem] : allocs) {
std::string key = "leaked allocations";
if (not xbt_log_no_loc)
- key = elem.second.file + ":" + std::to_string(elem.second.line) + ": " + key;
- auto result = leaks_aggreg.try_emplace(key, buff_leak{1, elem.second.size, elem.second.size, elem.second.size});
- if (result.second == false) {
- result.first->second.count++;
- result.first->second.total_size += elem.second.size;
- if (elem.second.size > result.first->second.max_size)
- result.first->second.max_size = elem.second.size;
- else if (elem.second.size < result.first->second.min_size)
- result.first->second.min_size = elem.second.size;
- }
+ key = elem.file + ":" + std::to_string(elem.line) + ": " + key;
+ auto& result = leaks_aggreg.try_emplace(key, buff_leak{0, 0, elem.size, elem.size}).first->second;
+ result.count++;
+ result.total_size += elem.size;
+ if (elem.size > result.max_size)
+ result.max_size = elem.size;
+ else if (elem.size < result.min_size)
+ result.min_size = elem.size;
}
// now we can order by total size.
std::vector<std::pair<std::string, buff_leak>> leaks(leaks_aggreg.begin(), leaks_aggreg.end());
[](auto const& a, auto const& b) { return a.second.total_size > b.second.total_size; });
unsigned int i = 0;
- for (const auto& p : leaks) {
- if (p.second.min_size == p.second.max_size)
- XBT_INFO("%s of total size %zu, called %d times, each with size %zu", p.first.c_str(), p.second.total_size,
- p.second.count, p.second.min_size);
+ for (const auto& [key, value] : leaks) {
+ if (value.min_size == value.max_size)
+ XBT_INFO("%s of total size %zu, called %d times, each with size %zu", key.c_str(), value.total_size, value.count,
+ value.min_size);
else
- XBT_INFO("%s of total size %zu, called %d times, with minimum size %zu and maximum size %zu", p.first.c_str(),
- p.second.total_size, p.second.count, p.second.min_size, p.second.max_size);
+ XBT_INFO("%s of total size %zu, called %d times, with minimum size %zu and maximum size %zu", key.c_str(),
+ value.total_size, value.count, value.min_size, value.max_size);
i++;
if (i == max)
break;
auto* cp = new Group(this->group());
(*newcomm) = new Comm(cp, this->topo());
- for (auto const& it : attributes()) {
- auto elem_it = keyvals_.find(it.first);
- xbt_assert(elem_it != keyvals_.end(), "Keyval not found for Comm: %d", it.first);
+ for (auto const& [key, value] : attributes()) {
+ auto elem_it = keyvals_.find(key);
+ xbt_assert(elem_it != keyvals_.end(), "Keyval not found for Comm: %d", key);
smpi_key_elem& elem = elem_it->second;
int ret = MPI_SUCCESS;
int flag = 0;
void* value_out = nullptr;
if (elem.copy_fn.comm_copy_fn == MPI_COMM_DUP_FN) {
- value_out = it.second;
+ value_out = value;
flag = 1;
} else if (elem.copy_fn.comm_copy_fn != MPI_NULL_COPY_FN) {
- ret = elem.copy_fn.comm_copy_fn(this, it.first, elem.extra_state, it.second, &value_out, &flag);
+ ret = elem.copy_fn.comm_copy_fn(this, key, elem.extra_state, value, &value_out, &flag);
}
if (elem.copy_fn.comm_copy_fn_fort != MPI_NULL_COPY_FN) {
value_out = xbt_new(int, 1);
if (*(int*)*elem.copy_fn.comm_copy_fn_fort == 1) { // MPI_COMM_DUP_FN
- memcpy(value_out, it.second, sizeof(int));
+ memcpy(value_out, value, sizeof(int));
flag = 1;
} else { // not null, nor dup
- elem.copy_fn.comm_copy_fn_fort(this, it.first, elem.extra_state, it.second, value_out, &flag, &ret);
+ elem.copy_fn.comm_copy_fn_fort(this, key, elem.extra_state, value, value_out, &flag, &ret);
}
if (ret != MPI_SUCCESS)
xbt_free(value_out);
}
if (flag) {
elem.refcount++;
- (*newcomm)->attributes().emplace(it.first, value_out);
+ (*newcomm)->attributes().try_emplace(key, value_out);
}
}
//duplicate info if present
}
std::vector<MPI_Request> requests(rankmap.size());
int reqs = 0;
- for (auto const& rank : rankmap) {
- if (rank.second != 0) {
+ for (auto const& [_, rank] : rankmap) {
+ if (rank != 0) {
group_snd[reqs]=new Group(group_out);
- requests[reqs] = Request::isend(&(group_snd[reqs]), 1, MPI_PTR, rank.second, system_tag, this);
+ requests[reqs] = Request::isend(&(group_snd[reqs]), 1, MPI_PTR, rank, system_tag, this);
reqs++;
}
}
flags_ &= ~DT_FLAG_PREDEFINED;
set_contents(MPI_COMBINER_DUP, 0, nullptr, 0, nullptr, 1, &datatype);
- for (auto const& it : datatype->attributes()) {
- auto elem_it = keyvals_.find(it.first);
- xbt_assert(elem_it != keyvals_.end(), "Keyval not found for Datatype: %d", it.first);
+ for (auto const& [key, value] : datatype->attributes()) {
+ auto elem_it = keyvals_.find(key);
+ xbt_assert(elem_it != keyvals_.end(), "Keyval not found for Datatype: %d", key);
smpi_key_elem& elem = elem_it->second;
int ret = MPI_SUCCESS;
int flag = 0;
void* value_out = nullptr;
if (elem.copy_fn.type_copy_fn == MPI_TYPE_DUP_FN) {
- value_out = it.second;
+ value_out = value;
flag = 1;
} else if (elem.copy_fn.type_copy_fn != MPI_NULL_COPY_FN) {
- ret = elem.copy_fn.type_copy_fn(datatype, it.first, elem.extra_state, it.second, &value_out, &flag);
+ ret = elem.copy_fn.type_copy_fn(datatype, key, elem.extra_state, value, &value_out, &flag);
}
if (ret != MPI_SUCCESS)
return ret;
if (elem.copy_fn.type_copy_fn_fort != MPI_NULL_COPY_FN) {
value_out = xbt_new(int, 1);
if (*(int*)*elem.copy_fn.type_copy_fn_fort == 1) { // MPI_TYPE_DUP_FN
- memcpy(value_out, it.second, sizeof(int));
+ memcpy(value_out, value, sizeof(int));
flag = 1;
} else { // not null, nor dup
- elem.copy_fn.type_copy_fn_fort(datatype, it.first, elem.extra_state, it.second, value_out, &flag, &ret);
+ elem.copy_fn.type_copy_fn_fort(datatype, key, elem.extra_state, value, value_out, &flag, &ret);
}
if (ret != MPI_SUCCESS) {
xbt_free(value_out);
}
if (flag) {
elem.refcount++;
- attributes().emplace(it.first, value_out);
+ attributes().try_emplace(key, value_out);
}
}
return MPI_SUCCESS;
int Info::get_nthkey(int n, char* key) const
{
int num=0;
- for (auto const& elm : map_) {
+ for (auto const& [elm, _] : map_) {
if (num == n) {
- strncpy(key, elm.first.c_str(), elm.first.length() + 1);
+ strncpy(key, elm.c_str(), elm.length() + 1);
return MPI_SUCCESS;
}
num++;
delete arg;
actors_at_boot_.clear();
- for (auto const& d : disks_)
- d.second->destroy();
+ for (auto const& [_, d] : disks_)
+ d->destroy();
- for (auto const& vm : vms_)
- vm.second->vm_destroy();
+ for (auto const& [_, vm] : vms_)
+ vm->vm_destroy();
}
/** @brief Fire the required callbacks and destroy the object
void HostImpl::turn_off(const actor::ActorImpl* issuer)
{
/* turn_off VMs running on host */
- for (const auto& kv : vms_) {
+ for (const auto& [_, vm] : vms_) {
// call s4u functions to generate the good on_state_change signal, maybe one day this wont be necessary
- kv.second->get_iface()->shutdown();
- kv.second->get_iface()->turn_off();
+ vm->get_iface()->shutdown();
+ vm->get_iface()->turn_off();
}
for (auto& actor : actor_list_) {
XBT_DEBUG("Killing Actor %s@%s on behalf of %s which turned off that host.", actor.get_cname(),
std::vector<s4u::Disk*> HostImpl::get_disks() const
{
std::vector<s4u::Disk*> disks;
- for (auto const& d : disks_)
- disks.push_back(d.second->get_iface());
+ for (auto const& [_, d] : disks_)
+ disks.push_back(d->get_iface());
return disks;
}
std::vector<s4u::VirtualMachine*> HostImpl::get_vms() const
{
std::vector<s4u::VirtualMachine*> vms;
- for (const auto& kv : vms_) {
- vms.push_back(kv.second->get_iface());
+ for (const auto& [_, vm] : vms_) {
+ vms.push_back(vm->get_iface());
}
return vms;
}
sealed_ = true;
/* seal its disks */
- for (auto const& disk : disks_)
- disk.second->seal();
+ for (auto const& [_, disk] : disks_)
+ disk->seal();
/* seal its VMs */
- for (auto const& vm : vms_)
- vm.second->seal();
+ for (auto const& [_, vm] : vms_)
+ vm->seal();
}
} // namespace resource
} // namespace kernel
{
if (action.get_state() != Action::State::FINISHED)
return;
- auto* ibModel = static_cast<NetworkIBModel*>(action.get_model());
- std::pair<IBNode*, IBNode*> pair = ibModel->active_comms[&action];
+ auto* ibModel = static_cast<NetworkIBModel*>(action.get_model());
+ auto [src, dst] = ibModel->active_comms[&action];
XBT_DEBUG("IB callback - action %p finished", &action);
- ibModel->update_IB_factors(&action, pair.first, pair.second, 1);
+ ibModel->update_IB_factors(&action, src, dst, 1);
ibModel->active_comms.erase(&action);
}
if (not updatedlist[comm->destination->id_])
update_IB_factors_rec(comm->destination, updatedlist);
}
- for (std::map<IBNode*, int>::value_type const& comm : root->active_comms_down_) {
- if (not updatedlist[comm.first->id_])
- update_IB_factors_rec(comm.first, updatedlist);
+ for (auto const& [comm, _] : root->active_comms_down_) {
+ if (not updatedlist[comm->id_])
+ update_IB_factors_rec(comm, updatedlist);
}
}
}
{
static std::vector<std::string> socket_to_destroy;
- std::string ns3_socket;
- for (const auto& elm : flow_from_sock) {
- ns3_socket = elm.first;
- SgFlow* sgFlow = elm.second;
+ for (const auto& [ns3_socket, sgFlow] : flow_from_sock) {
NetworkNS3Action* action = sgFlow->action_;
XBT_DEBUG("Processing flow %p (socket %s, action %p)", sgFlow, ns3_socket.c_str(), action);
// Because NS3 stops as soon as a flow is finished, the other flows that ends at the same time may remains in an
}
while (not socket_to_destroy.empty()) {
- ns3_socket = socket_to_destroy.back();
+ std::string ns3_socket = socket_to_destroy.back();
socket_to_destroy.pop_back();
SgFlow* flow = flow_from_sock.at(ns3_socket);
if (XBT_LOG_ISENABLED(res_ns3, xbt_log_priority_debug)) {
zone->set_parent(parent);
/* set properties */
- for (auto const& elm : cluster->properties)
- zone->set_property(elm.first, elm.second);
+ for (auto const& [key, value] : cluster->properties)
+ zone->set_property(key, value);
/* Make the backbone */
const simgrid::s4u::Link* backbone = nullptr;
const auto engine = simgrid::s4u::Engine::get_instance();
/* connect all profiles relative to hosts */
- for (auto const& elm : trace_connect_list_host_avail) {
- surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(),
- std::string("<trace_connect kind=\"HOST_AVAIL\">: Trace ") + elm.first + " undefined.");
- auto profile = traces_set_list.at(elm.first);
+ for (auto const& [trace, name] : trace_connect_list_host_avail) {
+ surf_parse_assert(traces_set_list.find(trace) != traces_set_list.end(),
+ std::string("<trace_connect kind=\"HOST_AVAIL\">: Trace ") + trace + " undefined.");
+ auto profile = traces_set_list.at(trace);
- auto host = engine->host_by_name_or_null(elm.second);
- surf_parse_assert(host, std::string("<trace_connect kind=\"HOST_AVAIL\">: Host ") + elm.second + " undefined.");
+ auto host = engine->host_by_name_or_null(name);
+ surf_parse_assert(host, std::string("<trace_connect kind=\"HOST_AVAIL\">: Host ") + name + " undefined.");
host->set_state_profile(profile);
}
- for (auto const& elm : trace_connect_list_host_speed) {
- surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(),
- std::string("<trace_connect kind=\"SPEED\">: Trace ") + elm.first + " undefined.");
- auto profile = traces_set_list.at(elm.first);
+ for (auto const& [trace, name] : trace_connect_list_host_speed) {
+ surf_parse_assert(traces_set_list.find(trace) != traces_set_list.end(),
+ std::string("<trace_connect kind=\"SPEED\">: Trace ") + trace + " undefined.");
+ auto profile = traces_set_list.at(trace);
- auto host = engine->host_by_name_or_null(elm.second);
- surf_parse_assert(host, std::string("<trace_connect kind=\"SPEED\">: Host ") + elm.second + " undefined.");
+ auto host = engine->host_by_name_or_null(name);
+ surf_parse_assert(host, std::string("<trace_connect kind=\"SPEED\">: Host ") + name + " undefined.");
host->set_speed_profile(profile);
}
- for (auto const& elm : trace_connect_list_link_avail) {
- surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(),
- std::string("<trace_connect kind=\"LINK_AVAIL\">: Trace ") + elm.first + " undefined.");
- auto profile = traces_set_list.at(elm.first);
+ for (auto const& [trace, name] : trace_connect_list_link_avail) {
+ surf_parse_assert(traces_set_list.find(trace) != traces_set_list.end(),
+ std::string("<trace_connect kind=\"LINK_AVAIL\">: Trace ") + trace + " undefined.");
+ auto profile = traces_set_list.at(trace);
- auto link = engine->link_by_name_or_null(elm.second);
- surf_parse_assert(link, std::string("<trace_connect kind=\"LINK_AVAIL\">: Link ") + elm.second + " undefined.");
+ auto link = engine->link_by_name_or_null(name);
+ surf_parse_assert(link, std::string("<trace_connect kind=\"LINK_AVAIL\">: Link ") + name + " undefined.");
link->set_state_profile(profile);
}
- for (auto const& elm : trace_connect_list_link_bw) {
- surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(),
- std::string("<trace_connect kind=\"BANDWIDTH\">: Trace ") + elm.first + " undefined.");
- auto profile = traces_set_list.at(elm.first);
+ for (auto const& [trace, name] : trace_connect_list_link_bw) {
+ surf_parse_assert(traces_set_list.find(trace) != traces_set_list.end(),
+ std::string("<trace_connect kind=\"BANDWIDTH\">: Trace ") + trace + " undefined.");
+ auto profile = traces_set_list.at(trace);
- auto link = engine->link_by_name_or_null(elm.second);
- surf_parse_assert(link, std::string("<trace_connect kind=\"BANDWIDTH\">: Link ") + elm.second + " undefined.");
+ auto link = engine->link_by_name_or_null(name);
+ surf_parse_assert(link, std::string("<trace_connect kind=\"BANDWIDTH\">: Link ") + name + " undefined.");
link->set_bandwidth_profile(profile);
}
- for (auto const& elm : trace_connect_list_link_lat) {
- surf_parse_assert(traces_set_list.find(elm.first) != traces_set_list.end(),
- std::string("<trace_connect kind=\"LATENCY\">: Trace ") + elm.first + " undefined.");
- auto profile = traces_set_list.at(elm.first);
+ for (auto const& [trace, name] : trace_connect_list_link_lat) {
+ surf_parse_assert(traces_set_list.find(trace) != traces_set_list.end(),
+ std::string("<trace_connect kind=\"LATENCY\">: Trace ") + trace + " undefined.");
+ auto profile = traces_set_list.at(trace);
- auto link = engine->link_by_name_or_null(elm.second);
- surf_parse_assert(link, std::string("<trace_connect kind=\"LATENCY\">: Link ") + elm.second + " undefined.");
+ auto link = engine->link_by_name_or_null(name);
+ surf_parse_assert(link, std::string("<trace_connect kind=\"LATENCY\">: Link ") + name + " undefined.");
link->set_latency_profile(profile);
}
auto current_property_set = property_sets.back();
std::vector<std::string> keys;
- for (auto const& kv : current_property_set) {
- keys.push_back(kv.first);
+ for (auto const& [key, _] : current_property_set) {
+ keys.push_back(key);
}
std::sort(keys.begin(), keys.end());
for (const std::string& key : keys) {
inline ConfigurationElement* Config::get_dict_element(const std::string& name)
{
- auto opt = options.find(name);
- if (opt != options.end()) {
+ if (auto opt = options.find(name); opt != options.end())
return opt->second.get();
- } else {
- auto als = aliases.find(name);
- if (als != aliases.end()) {
- ConfigurationElement* res = als->second;
- if (warn_for_aliases)
- XBT_INFO("Option %s has been renamed to %s. Consider switching.", name.c_str(), res->get_key().c_str());
- return res;
- } else {
- std::string msg = "Bad config key: " + name + "\n";
- std::string kebab = name;
- std::replace(begin(kebab), end(kebab), '_', '-'); // convert from snake_case to kebab-case
- if (options.count(kebab) > 0)
- msg += "Did you mean '" + kebab + "'?\n";
- msg += "Existing config keys:\n";
- for (auto const& elm : options)
- msg += " " + elm.first + ": (" + elm.second->get_type_name() + ")" + elm.second->get_string_value() + "\n";
- throw std::out_of_range(msg);
- }
+
+ if (auto als = aliases.find(name); als != aliases.end()) {
+ ConfigurationElement* res = als->second;
+ if (warn_for_aliases)
+ XBT_INFO("Option %s has been renamed to %s. Consider switching.", name.c_str(), res->get_key().c_str());
+ return res;
}
+
+ std::string msg = "Bad config key: " + name + "\n";
+ std::string kebab = name;
+ std::replace(begin(kebab), end(kebab), '_', '-'); // convert from snake_case to kebab-case
+ if (options.count(kebab) > 0)
+ msg += "Did you mean '" + kebab + "'?\n";
+ msg += "Existing config keys:\n";
+ for (auto const& [opt_name, opt] : options)
+ msg += " " + opt_name + ": (" + opt->get_type_name() + ")" + opt->get_string_value() + "\n";
+ throw std::out_of_range(msg);
}
inline ConfigurationElement& Config::operator[](const std::string& name)
/** @brief Displays the declared aliases and their replacement */
void Config::show_aliases() const
{
- for (auto const& elm : aliases)
- XBT_HELP(" %-40s %s", elm.first.c_str(), elm.second->get_key().c_str());
+ for (auto const& [name, alias] : aliases)
+ XBT_HELP(" %-40s %s", name.c_str(), alias->get_key().c_str());
}
/** @brief Displays the declared options and their description */
void Config::help() const
{
- for (auto const& elm : options) {
- simgrid::config::ConfigurationElement* variable = elm.second.get();
- XBT_HELP(" %s: %s", elm.first.c_str(), variable->get_description().c_str());
- XBT_HELP(" Type: %s; Current value: %s", variable->get_type_name(), variable->get_string_value().c_str());
+ for (auto const& [name, opt] : options) {
+ XBT_HELP(" %s: %s", name.c_str(), opt->get_description().c_str());
+ XBT_HELP(" Type: %s; Current value: %s", opt->get_type_name(), opt->get_string_value().c_str());
}
}
unit_scale::unit_scale(std::initializer_list<std::tuple<const std::string, double, int, bool>> generators)
{
- for (const auto& gen : generators) {
- const std::string& unit = std::get<0>(gen);
- double value = std::get<1>(gen);
- const int base = std::get<2>(gen);
- const bool abbrev = std::get<3>(gen);
+ for (auto [unit, value, base, abbrev] : generators) {
double mult;
std::vector<std::string> prefixes;
switch (base) {
static simgrid::mc::Frame* find_function_by_name(
simgrid::mc::ObjectInformation* info, const char* name)
{
- for (auto& entry : info->subprograms)
- if(entry.second.name == name)
- return &entry.second;
+ for (auto& [_, entry] : info->subprograms)
+ if (entry.name == name)
+ return &entry;
return nullptr;
}
}
// Sort the properties before displaying them, so that the tests are perfectly reproducible
std::vector<std::string> keys;
- for (auto const& kv : *props)
- keys.push_back(kv.first);
+ for (auto const& [key, _] : *props)
+ keys.push_back(key);
if (not keys.empty()) {
std::printf(">\n");
std::sort(keys.begin(), keys.end());
if (not props->empty()) {
XBT_INFO(" Properties of disk: %s", disk->get_cname());
- for (auto const& elm : *props) {
- XBT_INFO(" %s->%s", elm.first.c_str(), elm.second.c_str());
+ for (auto const& [key, value] : *props) {
+ XBT_INFO(" %s->%s", key.c_str(), value.c_str());
}
} else {
XBT_INFO(" No property attached.");
XBT_INFO("Print the content of the disk: %s", disk->get_cname());
const auto* content = disk->extension<simgrid::s4u::FileSystemDiskExt>()->get_content();
if (not content->empty()) {
- for (auto const& entry : *content)
- XBT_INFO(" %s size: %llu bytes", entry.first.c_str(), entry.second);
+ for (auto const& [name, size] : *content)
+ XBT_INFO(" %s size: %llu bytes", name.c_str(), size);
} else {
XBT_INFO(" No content.");
}