XBT_INFO("There are %zu hosts in the environment", totalHosts);
std::vector<simgrid::s4u::Host*> hosts = e.get_all_hosts();
- for (unsigned int i = 0; i < hosts.size(); i++)
- XBT_INFO("Host '%s' runs at %.0f flops/s", hosts[i]->get_cname(), hosts[i]->get_speed());
+ for (simgrid::s4u::Host const* host : hosts)
+ XBT_INFO("Host '%s' runs at %.0f flops/s", host->get_cname(), host->get_speed());
e.load_deployment(argv[2]);
e.run();
FatTreeZone::~FatTreeZone()
{
- for (unsigned int i = 0; i < this->nodes_.size(); i++) {
- delete this->nodes_[i];
+ for (FatTreeNode const* node : this->nodes_) {
+ delete node;
}
- for (unsigned int i = 0; i < this->links_.size(); i++) {
- delete this->links_[i];
+ for (FatTreeLink const* link : this->links_) {
+ delete link;
}
}
msgBuffer.str("");
msgBuffer << "Nodes are : ";
- for (unsigned int i = 0; i < this->nodes_.size(); i++) {
- msgBuffer << this->nodes_[i]->id << "(" << this->nodes_[i]->level << "," << this->nodes_[i]->position << ") ";
+ for (FatTreeNode const* node : this->nodes_) {
+ msgBuffer << node->id << "(" << node->level << "," << node->position << ") ";
}
XBT_DEBUG("%s", msgBuffer.str().c_str());
}
if (XBT_LOG_ISENABLED(surf_route_fat_tree, xbt_log_priority_debug)) {
std::stringstream msgBuffer;
msgBuffer << "Links are : ";
- for (unsigned int i = 0; i < this->links_.size(); i++) {
- msgBuffer << "(" << this->links_[i]->up_node_->id << "," << this->links_[i]->down_node_->id << ") ";
+ for (FatTreeLink const* link : this->links_) {
+ msgBuffer << "(" << link->up_node_->id << "," << link->down_node_->id << ") ";
}
XBT_DEBUG("%s", msgBuffer.str().c_str());
}
" levels but the child count vector (the first one) contains " +
std::to_string(tmp.size()) + " levels.");
- for (size_t i = 0; i < tmp.size(); i++) {
+ for (std::string const& level : tmp) {
try {
- this->num_children_per_node_.push_back(std::stoi(tmp[i]));
+ this->num_children_per_node_.push_back(std::stoi(level));
} catch (const std::invalid_argument&) {
- surf_parse_error(std::string("Invalid child count: ") + tmp[i]);
+ surf_parse_error(std::string("Invalid child count: ") + level);
}
}
surf_parse_assert(tmp.size() == this->levels_, std::string("You specified ") + std::to_string(this->levels_) +
" levels but the parent count vector (the second one) contains " +
std::to_string(tmp.size()) + " levels.");
- for (size_t i = 0; i < tmp.size(); i++) {
+ for (std::string const& parent : tmp) {
try {
- this->num_parents_per_node_.push_back(std::stoi(tmp[i]));
+ this->num_parents_per_node_.push_back(std::stoi(parent));
} catch (const std::invalid_argument&) {
- surf_parse_error(std::string("Invalid parent count: ") + tmp[i]);
+ surf_parse_error(std::string("Invalid parent count: ") + parent);
}
}
surf_parse_assert(tmp.size() == this->levels_, std::string("You specified ") + std::to_string(this->levels_) +
" levels but the port count vector (the third one) contains " +
std::to_string(tmp.size()) + " levels.");
- for (size_t i = 0; i < tmp.size(); i++) {
+ for (std::string const& port : tmp) {
try {
- this->num_port_lower_level_.push_back(std::stoi(tmp[i]));
+ this->num_port_lower_level_.push_back(std::stoi(port));
} catch (const std::invalid_argument&) {
- throw std::invalid_argument(std::string("Invalid lower level port number:") + tmp[i]);
+ throw std::invalid_argument(std::string("Invalid lower level port number:") + port);
}
}
this->cluster_ = cluster;
xbt_assert(file.is_open(), "Unable to open file %s", filename.c_str());
file << "graph AsClusterFatTree {\n";
- for (unsigned int i = 0; i < this->nodes_.size(); i++) {
- file << this->nodes_[i]->id;
- if (this->nodes_[i]->id < 0)
+ for (FatTreeNode const* node : this->nodes_) {
+ file << node->id;
+ if (node->id < 0)
file << " [shape=circle];\n";
else
file << " [shape=hexagon];\n";
}
- for (unsigned int i = 0; i < this->links_.size(); i++) {
- file << this->links_[i]->down_node_->id << " -- " << this->links_[i]->up_node_->id << ";\n";
+ for (FatTreeLink const* link : this->links_) {
+ file << link->down_node_->id << " -- " << link->up_node_->id << ";\n";
}
file << "}";
file.close();
static void on_simulation_end()
{
- std::vector<simgrid::s4u::Host*> hosts = simgrid::s4u::Engine::get_instance()->get_all_hosts();
-
double total_energy = 0.0; // Total energy consumption (whole platform)
double used_hosts_energy = 0.0; // Energy consumed by hosts that computed something
- for (size_t i = 0; i < hosts.size(); i++) {
- if (dynamic_cast<simgrid::s4u::VirtualMachine*>(hosts[i]) == nullptr) { // Ignore virtual machines
- double energy = hosts[i]->extension<HostEnergy>()->get_consumed_energy();
+ for (simgrid::s4u::Host const* host : simgrid::s4u::Engine::get_instance()->get_all_hosts()) {
+ if (dynamic_cast<const simgrid::s4u::VirtualMachine*>(host) == nullptr) { // Ignore virtual machines
+ double energy = host->extension<HostEnergy>()->get_consumed_energy();
total_energy += energy;
- if (hosts[i]->extension<HostEnergy>()->host_was_used_)
+ if (host->extension<HostEnergy>()->host_was_used_)
used_hosts_energy += energy;
}
}
double num_comm_out = root->ActiveCommsUp.size();
double max_penalty_out = 0.0;
// first, compute all outbound penalties to get their max
- for (std::vector<ActiveComm*>::iterator it = root->ActiveCommsUp.begin(); it != root->ActiveCommsUp.end(); ++it) {
+ for (ActiveComm const* comm : root->ActiveCommsUp) {
double my_penalty_out = 1.0;
if (num_comm_out != 1) {
- if ((*it)->destination->nbActiveCommsDown > 2) // number of comms sent to the receiving node
+ if (comm->destination->nbActiveCommsDown > 2) // number of comms sent to the receiving node
my_penalty_out = num_comm_out * Bs * ys;
else
my_penalty_out = num_comm_out * Bs;
max_penalty_out = std::max(max_penalty_out, my_penalty_out);
}
- for (std::vector<ActiveComm*>::iterator it = root->ActiveCommsUp.begin(); it != root->ActiveCommsUp.end(); ++it) {
+ for (ActiveComm* comm : root->ActiveCommsUp) {
// compute inbound penalty
double my_penalty_in = 1.0;
- int nb_comms = (*it)->destination->nbActiveCommsDown; // total number of incoming comms
+ int nb_comms = comm->destination->nbActiveCommsDown; // total number of incoming comms
if (nb_comms != 1)
- my_penalty_in = ((*it)->destination->ActiveCommsDown)[root] // number of comm sent to dest by root node
- * Be * (*it)->destination->ActiveCommsDown.size(); // number of different nodes sending to dest
+ my_penalty_in = (comm->destination->ActiveCommsDown)[root] // number of comm sent to dest by root node
+ * Be * comm->destination->ActiveCommsDown.size(); // number of different nodes sending to dest
double penalty = std::max(my_penalty_in, max_penalty_out);
- double rate_before_update = (*it)->action->get_bound();
+ double rate_before_update = comm->action->get_bound();
// save initial rate of the action
- if ((*it)->init_rate == -1)
- (*it)->init_rate = rate_before_update;
+ if (comm->init_rate == -1)
+ comm->init_rate = rate_before_update;
- double penalized_bw = num_comm_out ? (*it)->init_rate / penalty : (*it)->init_rate;
+ double penalized_bw = num_comm_out ? comm->init_rate / penalty : comm->init_rate;
if (not double_equals(penalized_bw, rate_before_update, sg_surf_precision)) {
XBT_DEBUG("%d->%d action %p penalty updated : bw now %f, before %f , initial rate %f", root->id,
- (*it)->destination->id, (*it)->action, penalized_bw, (*it)->action->get_bound(), (*it)->init_rate);
- get_maxmin_system()->update_variable_bound((*it)->action->get_variable(), penalized_bw);
+ comm->destination->id, comm->action, penalized_bw, comm->action->get_bound(), comm->init_rate);
+ get_maxmin_system()->update_variable_bound(comm->action->get_variable(), penalized_bw);
} else {
- XBT_DEBUG("%d->%d action %p penalty not updated : bw %f, initial rate %f", root->id, (*it)->destination->id,
- (*it)->action, penalized_bw, (*it)->init_rate);
+ XBT_DEBUG("%d->%d action %p penalty not updated : bw %f, initial rate %f", root->id, comm->destination->id,
+ comm->action, penalized_bw, comm->init_rate);
}
}
XBT_DEBUG("Finished computing IB penalties");
XBT_DEBUG("IB - Updating rec %d", root->id);
computeIBfactors(root);
updatedlist[root->id] = true;
- for (std::vector<ActiveComm*>::iterator it = root->ActiveCommsUp.begin(); it != root->ActiveCommsUp.end(); ++it) {
- if (not updatedlist[(*it)->destination->id])
- updateIBfactors_rec((*it)->destination, updatedlist);
+ for (ActiveComm const* comm : root->ActiveCommsUp) {
+ if (not updatedlist[comm->destination->id])
+ updateIBfactors_rec(comm->destination, updatedlist);
}
- for (std::map<IBNode*, int>::iterator it = root->ActiveCommsDown.begin(); it != root->ActiveCommsDown.end(); ++it) {
- if (not updatedlist[it->first->id])
- updateIBfactors_rec(it->first, updatedlist);
+ for (std::map<IBNode*, int>::value_type const& comm : root->ActiveCommsDown) {
+ if (not updatedlist[comm.first->id])
+ updateIBfactors_rec(comm.first, updatedlist);
}
}
}
to->ActiveCommsDown[from] -= 1;
to->nbActiveCommsDown--;
- for (std::vector<ActiveComm*>::iterator it = from->ActiveCommsUp.begin(); it != from->ActiveCommsUp.end(); ++it) {
- if ((*it)->action == action) {
- delete *it;
- from->ActiveCommsUp.erase(it);
- break;
- }
+ std::vector<ActiveComm*>::iterator it =
+ std::find_if(begin(from->ActiveCommsUp), end(from->ActiveCommsUp),
+ [action](const ActiveComm* comm) { return comm->action == action; });
+ if (it != std::end(from->ActiveCommsUp)) {
+ delete *it;
+ from->ActiveCommsUp.erase(it);
}
action->unref();
} else {
simgrid::s4u::ActorPtr receiver = simgrid::s4u::Actor::create("receiver", all_hosts[1], [&start]() {
assert_exit(true, 9);
double milestone[5] = {0.5, 3.5, 4.5, 7.5, 9.0};
- for (int i = 0; i < 5; i++)
- milestone[i] += start;
+ for (double& m : milestone)
+ m += start;
for (int i = 0; i < 4; i++) {
simgrid::s4u::this_actor::sleep_until(milestone[i]);
REQUIRE_NETWORK_FAILURE({
assert_exit(true, 9);
int data = 42;
double milestone[5] = {1.5, 2.5, 5.5, 6.5, 9.0};
- for (int i = 0; i < 5; i++)
- milestone[i] += start;
+ for (double& m : milestone)
+ m += start;
for (int i = 0; i < 2; i++) {
simgrid::s4u::this_actor::sleep_until(milestone[i]);
XBT_VERB("dsend(%c)", 'A' + i);
std::thread crashers[crasher_amount];
/* spawn threads */
- for (int i = 0; i < crasher_amount; i++) {
- crashers[i] = std::thread(crasher_thread, i);
- }
+ int id = 0;
+ for (std::thread& thr : crashers)
+ thr = std::thread(crasher_thread, id++);
/* wait for them */
- for (int i = 0; i < crasher_amount; i++)
- crashers[i].join();
+ for (std::thread& thr : crashers)
+ thr.join();
return 0;
}