Use the init-statement to declare variables inside the if statement (sonar).
* new dependency
*/
- auto last_scheduled_task = sg_host_get_last_scheduled_task(selected_host);
- if (last_scheduled_task && (last_scheduled_task->get_state() != sg4::Activity::State::FINISHED) &&
+ if (auto last_scheduled_task = sg_host_get_last_scheduled_task(selected_host);
+ last_scheduled_task && (last_scheduled_task->get_state() != sg4::Activity::State::FINISHED) &&
(last_scheduled_task->get_state() != sg4::Activity::State::FAILED) &&
not dependency_exists(sg_host_get_last_scheduled_task(selected_host), selected_task))
last_scheduled_task->add_successor(selected_task);
e.run();
// get user declared variables
- const auto& host_variables = simgrid::instr::get_host_variables();
- if (not host_variables.empty()) {
+ if (const auto& host_variables = simgrid::instr::get_host_variables(); not host_variables.empty()) {
XBT_INFO("Declared host variables:");
for (const auto& var : host_variables)
XBT_INFO("%s", var.c_str());
XBT_DEBUG("Simulation is over");
- const auto& categories = simgrid::instr::get_tracing_categories();
- if (not categories.empty()) {
+ if (const auto& categories = simgrid::instr::get_tracing_categories(); not categories.empty()) {
XBT_INFO("Declared tracing categories:");
for (const auto& category : categories)
XBT_INFO("%s", category.c_str());
}
- const auto& marks = simgrid::instr::get_marks();
- if (not marks.empty()) {
+ if (const auto& marks = simgrid::instr::get_marks(); not marks.empty()) {
XBT_INFO("Declared marks:");
for (const auto& mark : marks)
XBT_INFO("%s", mark.c_str());
free(pointer);
pointer = calloc(100, sizeof(int));
int rank;
- int err = MPI_Comm_rank(MPI_COMM_WORLD, &rank); /* Get id of this process */
- if (err != MPI_SUCCESS) {
+ /* Get id of this process */
+ if (int err = MPI_Comm_rank(MPI_COMM_WORLD, &rank); err != MPI_SUCCESS) {
fprintf(stderr, "MPI_Comm_rank failed: %d", err);
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
exit(EXIT_FAILURE);
{
for (auto const& job : workload) {
// Let's wait until the job's waiting time if needed
- double curr_time = simgrid::s4u::Engine::get_clock();
- if (job->starting_time > curr_time) {
+ if (double curr_time = simgrid::s4u::Engine::get_clock(); job->starting_time > curr_time) {
double time_to_sleep = (double)job->starting_time - curr_time;
XBT_INFO("Sleeping %g seconds (waiting for job %d, app '%s')", time_to_sleep, job->starting_time,
job->smpi_app_name.c_str());
paje::dump_generator_version();
/* output one line comment */
- std::string comment = simgrid::config::get_value<std::string>("tracing/comment");
- if (not comment.empty())
+ if (auto comment = simgrid::config::get_value<std::string>("tracing/comment"); not comment.empty())
tracing_file << "# " << comment << std::endl;
/* output comment file */
/* Note: the max_ may artificially increase the rate if priority < 0
* The equilibrium sets a rho which respects the C_ though */
- double rate = fair_sharing[cnst_idx] / maxA_(cnst_idx, player_idx);
- if (min_rate == -1 || double_positive(min_rate - rate, cfg_bmf_precision)) {
+ if (double rate = fair_sharing[cnst_idx] / maxA_(cnst_idx, player_idx);
+ min_rate == -1 || double_positive(min_rate - rate, cfg_bmf_precision)) {
selected_resource = cnst_idx;
min_rate = rate;
}
- double bound = initial ? -1 : phi_[player_idx];
/* Given that the priority may artificially increase the rate,
* we need to check that the bound given by user respects the resource capacity C_ */
- if (bound > 0 && bound * A_(cnst_idx, player_idx) < C_[cnst_idx] &&
- double_positive(min_rate - bound, cfg_bmf_precision)) {
+ if (double bound = initial ? -1 : phi_[player_idx];
+ (bound > 0 && bound * A_(cnst_idx, player_idx) < C_[cnst_idx] &&
+ double_positive(min_rate - bound, cfg_bmf_precision))) {
selected_resource = NO_RESOURCE;
min_rate = bound;
}
if (alloc == last_alloc) // considered stable
return true;
- std::vector<int> alloc_by_player = alloc_map_to_vector(alloc);
- bool inserted = allocations_.insert(alloc_by_player).second;
- /* oops, allocation already tried, let's pertube it a bit */
- if (not inserted) {
+ if (auto alloc_by_player = alloc_map_to_vector(alloc); not allocations_.insert(alloc_by_player).second) {
+ /* oops, allocation already tried, let's pertube it a bit */
XBT_DEBUG("Allocation already tried: %s", debug_alloc(alloc).c_str());
return disturb_allocation(alloc, alloc_by_player);
}
bool active = false;
bool linked = false; // variable is linked to some constraint (specially for selective_update)
for (const Element& elem : var.cnsts_) {
- const boost::intrusive::list_member_hook<>& cnst_hook = selective_update_active
- ? elem.constraint->modified_constraint_set_hook_
- : elem.constraint->active_constraint_set_hook_;
- if (not cnst_hook.is_linked())
+ if (const auto& cnst_hook = selective_update_active ? elem.constraint->modified_constraint_set_hook_
+ : elem.constraint->active_constraint_set_hook_;
+ not cnst_hook.is_linked())
continue;
/* active and linked variable, lets check its consumption */
linked = true;
double min = -1;
for (Action& action : *get_started_action_set()) {
- double value = action.get_rate();
- if (value > 0) {
+ if (double value = action.get_rate(); value > 0) {
if (action.get_remains() > 0)
value = action.get_remains_no_update() / value;
else
void VirtualMachineImpl::vm_destroy()
{
/* I was already removed from the allVms set if the VM was destroyed cleanly */
- auto iter = find(allVms_.begin(), allVms_.end(), piface_);
- if (iter != allVms_.end())
+ if (auto iter = find(allVms_.begin(), allVms_.end(), piface_); iter != allVms_.end())
allVms_.erase(iter);
/* Free the cpu_action of the VM. */
if (physical_host_->extension<s4u::VmHostExt>() == nullptr)
physical_host_->extension_set(new s4u::VmHostExt());
- size_t pm_ramsize = physical_host_->extension<s4u::VmHostExt>()->ramsize;
- if (pm_ramsize &&
+ if (size_t pm_ramsize = physical_host_->extension<s4u::VmHostExt>()->ramsize;
+ pm_ramsize &&
not physical_host_->extension<s4u::VmHostExt>()->overcommit) { /* Need to verify that we don't overcommit */
/* Retrieve the memory occupied by the VMs on that host. Yep, we have to traverse all VMs of all hosts for that */
size_t total_ramsize_of_vms = 0;
XBT_CRITICAL("FIXME: need copy the state(?), %f", action_->get_remains_no_update());
/* keep the bound value of the cpu action of the VM. */
- double old_bound = action_->get_bound();
- if (old_bound > 0) {
+ if (double old_bound = action_->get_bound(); old_bound > 0) {
XBT_DEBUG("migrate VM(%s): set bound (%f) at %s", vm_name.c_str(), old_bound, pm_name_dst.c_str());
new_cpu_action->set_bound(old_bound);
}
resource::StandardLinkImpl* NetZoneImpl::get_link_by_name_or_null(const std::string& name) const
{
- auto link_it = links_.find(name);
- if (link_it != links_.end())
+ if (auto link_it = links_.find(name); link_it != links_.end())
return link_it->second;
for (const auto* child : children_) {
resource::SplitDuplexLinkImpl* NetZoneImpl::get_split_duplex_link_by_name_or_null(const std::string& name) const
{
- auto link_it = split_duplex_links_.find(name);
- if (link_it != split_duplex_links_.end())
+ if (auto link_it = split_duplex_links_.find(name); link_it != split_duplex_links_.end())
return link_it->second.get();
for (const auto* child : children_) {
std::vector<ActorInformation>& actors = mc_model_checker->get_remote_process().actors();
XBT_DEBUG("Search for an actor to run. %zu actors to consider", actors.size());
for (unsigned int i = 0; i < actors.size(); i++) {
- aid_t aid = actors[i].copy.get_buffer()->get_pid();
- const ActorState* actor_state = &actor_states_[aid];
-
/* Only consider actors (1) marked as interleaving by the checker and (2) currently enabled in the application*/
- if (not actor_state->is_todo() || not Api::get().get_session().actor_is_enabled(aid))
+ if (aid_t aid = actors[i].copy.get_buffer()->get_pid();
+ not actor_states_[aid].is_todo() || not Api::get().get_session().actor_is_enabled(aid))
continue;
return i;
size_t length;
while (dwarf_nextcu(dwarf, offset, &next_offset, &length, nullptr, nullptr, nullptr) == 0) {
- Dwarf_Die unit_die;
- if (dwarf_offdie(dwarf, offset + length, &unit_die) != nullptr)
+ if (Dwarf_Die unit_die; dwarf_offdie(dwarf, offset + length, &unit_die) != nullptr)
MC_dwarf_handle_children(info, &unit_die, &unit_die, nullptr, nullptr);
offset = next_offset;
}
filename = std::string(debug_path) + ".build-id/" + to_hex(id.data(), 1) + '/' +
to_hex(id.data() + 1, id.size() - 1) + ".debug";
XBT_DEBUG("Checking debug file: %s", filename.c_str());
- int fd = open(filename.c_str(), O_RDONLY);
- if (fd != -1) {
+ if (int fd = open(filename.c_str(), O_RDONLY); fd != -1) {
XBT_DEBUG("Found debug file: %s\n", hex.c_str());
return fd;
}
// Try with NT_GNU_BUILD_ID: we find the build ID in the ELF file and then
// use this ID to find the file in some known locations in the filesystem.
- std::vector<char> build_id = get_build_id(elf);
- if (not build_id.empty()) {
+ if (std::vector<char> build_id = get_build_id(elf); not build_id.empty()) {
elf_end(elf);
close(fd);
struct iovec local = {valp, size};
struct iovec remote = {(void*)addr, size};
- ssize_t s = process_vm_readv(pid, &local, 1, &remote, 1, 0);
- if (s >= 0) {
+ if (ssize_t s = process_vm_readv(pid, &local, 1, &remote, 1, 0); s >= 0) {
if ((size_t)s != size)
return -UNW_EINVAL;
else
while (*current) {
long aid;
int times_considered;
- int count = sscanf(current, "%ld/%d", &aid, ×_considered);
- if(count != 2 && count != 1)
+ if (int count = sscanf(current, "%ld/%d", &aid, ×_considered); count != 2 && count != 1)
throw std::invalid_argument("Could not parse record path");
push_back(new simgrid::mc::Transition(simgrid::mc::Transition::Type::UNKNOWN, aid, times_considered));
std::string map_basename = simgrid::xbt::Path(pathname).get_base_name();
std::string libname;
- size_t pos = map_basename.rfind(".so");
- if (pos != std::string::npos) {
+ if (size_t pos = map_basename.rfind(".so"); pos != std::string::npos) {
// strip the extension (matching regex "\.so.*$")
libname.assign(map_basename, 0, pos);
sg_size_t write_size = 0;
/* Find the host where the file is physically located (remote or local)*/
- Host* host = local_disk_->get_host();
-
- if (host && host->get_name() != Host::current()->get_name()) {
+ if (Host* host = local_disk_->get_host(); host && host->get_name() != Host::current()->get_name()) {
/* the file is hosted on a remote host, initiate a communication between src and dest hosts for data transfer */
XBT_DEBUG("File is on %s remote host, initiate data transfer of %llu bytes.", host->get_cname(), size);
Comm::sendto(Host::current(), host, size);
void mpi_group_free_(int* group, int* ierr)
{
- MPI_Group tmp = simgrid::smpi::Group::f2c(*group);
- if(tmp != MPI_COMM_WORLD->group() && tmp != MPI_GROUP_EMPTY){
+ if (MPI_Group tmp = simgrid::smpi::Group::f2c(*group); tmp != MPI_COMM_WORLD->group() && tmp != MPI_GROUP_EMPTY) {
simgrid::smpi::Group::unref(tmp);
}
*ierr = MPI_SUCCESS;
}
void mpi_comm_free_(int* comm, int* ierr) {
- MPI_Comm tmp = simgrid::smpi::Comm::f2c(*comm);
- if(tmp != MPI_COMM_WORLD && tmp != MPI_COMM_NULL) {
+ if (MPI_Comm tmp = simgrid::smpi::Comm::f2c(*comm); tmp != MPI_COMM_WORLD && tmp != MPI_COMM_NULL) {
simgrid::smpi::Comm::destroy(tmp);
simgrid::smpi::Comm::free_f(*comm);
}
smpi_key_elem& elem = elem_it->second;
int flag = 0;
- int ret = call_deleter<T>((T*)this, elem, keyval, attr->second, &flag);
- if (ret != MPI_SUCCESS)
+ if (int ret = call_deleter<T>((T*)this, elem, keyval, attr->second, &flag); ret != MPI_SUCCESS)
return ret;
elem.refcount--;
template <typename T> int Keyval::attr_get(int keyval, void* attr_value, int* flag){
- auto elem_it = T::keyvals_.find(keyval);
- if (elem_it == T::keyvals_.end() || elem_it->second.deleted)
+ if (auto elem_it = T::keyvals_.find(keyval); elem_it == T::keyvals_.end() || elem_it->second.deleted)
return MPI_ERR_ARG;
- auto attr = attributes().find(keyval);
- if (attr != attributes().end()) {
+ if (auto attr = attributes().find(keyval); attr != attributes().end()) {
*static_cast<void**>(attr_value) = attr->second;
*flag=1;
} else {
std::string key;
std::string aux = std::to_string(src) + "#" + std::to_string(dst) + "#" + std::to_string(tag) + "#" +
std::to_string(send == 1 ? 0 : 1);
- auto it = keys.find(aux);
- if (it == keys.end()) {
+ if (auto it = keys.find(aux); it == keys.end()) {
// first posted
key = TRACE_smpi_put_key(src, dst, tag, send);
} else {
stat(executable.c_str(), &fdin_stat);
off_t fdin_size = fdin_stat.st_size;
- std::string libnames = simgrid::config::get_value<std::string>("smpi/privatize-libs");
- if (not libnames.empty()) {
+ if (std::string libnames = simgrid::config::get_value<std::string>("smpi/privatize-libs"); not libnames.empty()) {
// split option
std::vector<std::string> privatize_libs;
boost::split(privatize_libs, libnames, boost::is_any_of(";"));
double Host::orecv(size_t size, s4u::Host* src, s4u::Host* dst)
{
/* return user's callback if available */
- auto it = cost_cbs.find(SmpiOperation::RECV);
- if (it != cost_cbs.end())
+ if (auto it = cost_cbs.find(SmpiOperation::RECV); it != cost_cbs.end())
return it->second(size, src, dst);
/* fallback to smpi/or config */
double Host::osend(size_t size, s4u::Host* src, s4u::Host* dst)
{
/* return user's callback if available */
- auto it = cost_cbs.find(SmpiOperation::SEND);
- if (it != cost_cbs.end())
+ if (auto it = cost_cbs.find(SmpiOperation::SEND); it != cost_cbs.end())
return it->second(size, src, dst);
/* fallback to smpi/os config */
double Host::oisend(size_t size, s4u::Host* src, s4u::Host* dst)
{
/* return user's callback if available */
- auto it = cost_cbs.find(SmpiOperation::ISEND);
- if (it != cost_cbs.end())
+ if (auto it = cost_cbs.find(SmpiOperation::ISEND); it != cost_cbs.end())
return it->second(size, src, dst);
/* fallback to smpi/ois config */
{
unsigned int count = comm->get_collectives_count();
comm->increment_collectives_count();
- auto vec = collective_calls.find(comm->id());
- if (vec == collective_calls.end()) {
+ if (auto vec = collective_calls.find(comm->id()); vec == collective_calls.end()) {
collective_calls.try_emplace(comm->id(), std::vector<std::string>{call});
} else {
// are we the first ? add the call
int F2C::add_f()
{
allocate_lookup();
- auto loc = smpi_process()->call_location();
- if(loc && loc->linenumber != 0)
+ if (auto loc = smpi_process()->call_location(); loc && loc->linenumber != 0)
call_location_= std::string (loc->filename + ":" + std::to_string(loc->linenumber));
my_f2c_id_ = global_f2c_id();
(*f2c_lookup_)[my_f2c_id_] = this;
xbt_assert(not simgrid::s4u::Host::current()->get_disks().empty(),
"SMPI/IO : Trying to open file on a diskless host ! Add one to your platform file");
- size_t found = fullname.find('/');
// in case no fullpath is provided ... just pick the first mountpoint.
- if (found == std::string::npos || fullname.rfind("./", 1) != std::string::npos) {
+ if (size_t found = fullname.find('/'); found == std::string::npos || fullname.rfind("./", 1) != std::string::npos) {
auto disk = simgrid::s4u::Host::current()->get_disks().front();
std::string mount;
if (disk->get_host() != simgrid::s4u::Host::current())
int Info::get(const char* key, int valuelen, char* value, int* flag) const
{
*flag=false;
- auto val = map_.find(key);
- if (val != map_.end()) {
+ if (auto val = map_.find(key); val != map_.end()) {
std::string tmpvalue = val->second;
memset(value, 0, valuelen);
int Info::get_valuelen(const char* key, int* valuelen, int* flag) const
{
*flag=false;
- auto val = map_.find(key);
- if (val != map_.end()) {
+ if (auto val = map_.find(key); val != map_.end()) {
*valuelen = val->second.length();
*flag=true;
}
std::array<MPI_Request, 2> requests;
std::array<MPI_Status, 2> stats;
- aid_t myid = simgrid::s4u::this_actor::get_pid();
- if ((destination == myid) && (source == myid)) {
+ if (aid_t myid = simgrid::s4u::this_actor::get_pid(); (destination == myid) && (source == myid)) {
Datatype::copy(sendbuf, sendcount, sendtype, recvbuf, recvcount, recvtype);
if (status != MPI_STATUS_IGNORE) {
status->MPI_SOURCE = source;
to->active_comms_down_[from] -= 1;
to->nb_active_comms_down_--;
- auto it = std::find_if(begin(from->active_comms_up_), end(from->active_comms_up_),
- [action](const ActiveComm* comm) { return comm->action == action; });
- if (it != std::end(from->active_comms_up_)) {
+ if (auto it = std::find_if(begin(from->active_comms_up_), end(from->active_comms_up_),
+ [action](const ActiveComm* comm) { return comm->action == action; });
+ it != std::end(from->active_comms_up_)) {
delete *it;
from->active_comms_up_.erase(it);
}
ns3::Config::SetDefault("ns3::TcpSocket::DelAckCount", ns3::UintegerValue(1));
ns3::Config::SetDefault("ns3::TcpSocketBase::Timestamp", ns3::BooleanValue(false));
- auto const& TcpProtocol = ns3_tcp_model.get();
- if (TcpProtocol == "default") {
+ if (auto const& TcpProtocol = ns3_tcp_model.get(); TcpProtocol == "default") {
/* nothing to do */
} else if (TcpProtocol == "Reno" || TcpProtocol == "NewReno" || TcpProtocol == "Tahoe") {
const surf_model_description_t* find_model_description(const std::vector<surf_model_description_t>& table,
const std::string& name)
{
- auto pos = std::find_if(table.begin(), table.end(),
- [&name](const surf_model_description_t& item) { return item.name == name; });
- if (pos != table.end())
+ if (auto pos = std::find_if(table.begin(), table.end(),
+ [&name](const surf_model_description_t& item) { return item.name == name; });
+ pos != table.end())
return &*pos;
std::string sep;
void *res;
unsigned long old_used;
unsigned long new_used;
- long nb_shift;
_sanity_check_dynar(dynar);
_sanity_check_idx(idx);
_xbt_dynar_expand(dynar, new_used);
- nb_shift = old_used - idx;
-
- if (nb_shift>0) {
+ if (long nb_shift = old_used - idx; nb_shift > 0) {
memmove(_xbt_dynar_elm(dynar, idx + 1), _xbt_dynar_elm(dynar, idx), nb_shift * dynar->elmsize);
}
}
/* Apply the control */
- auto iset = std::find_if(begin(xbt_log_settings()), end(xbt_log_settings()),
- [category](const xbt_log_setting_t& s) { return s.catname == category->name; });
- if (iset != xbt_log_settings().end()) {
+ if (auto iset = std::find_if(begin(xbt_log_settings()), end(xbt_log_settings()),
+ [category](const xbt_log_setting_t& s) { return s.catname == category->name; });
+ iset != xbt_log_settings().end()) {
_xbt_log_cat_apply_set(category, *iset);
xbt_log_settings().erase(iset);
} else {
simgrid::s4u::this_actor::execute(size);
double end = simgrid::s4u::Engine::get_clock();
- if (0.1 - (end - begin) > 0.001) {
+ if (double duration = end - begin; 0.1 - duration > 0.001) {
xbt_assert(not FAIL_ON_ERROR, "%s with %.4g load (%dflops) took %.4fs instead of 0.1s",
- simgrid::s4u::this_actor::get_name().c_str(), ((double)size / flop_amount), size, (end - begin));
+ simgrid::s4u::this_actor::get_name().c_str(), ((double)size / flop_amount), size, duration);
XBT_INFO("FAILED TEST: %s with %.4g load (%dflops) took %.4fs instead of 0.1s",
- simgrid::s4u::this_actor::get_name().c_str(), ((double)size / flop_amount), size, (end - begin));
+ simgrid::s4u::this_actor::get_name().c_str(), ((double)size / flop_amount), size, duration);
failed_test++;
} else {
XBT_INFO("Passed: %s with %.4g load (%dflops) took 0.1s as expected", simgrid::s4u::this_actor::get_name().c_str(),