Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Reduce scope for temporary variables.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 6 May 2022 08:17:57 +0000 (10:17 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Fri, 6 May 2022 08:32:07 +0000 (10:32 +0200)
Use the init-statement to declare variables inside the if statement (sonar).

33 files changed:
examples/cpp/dag-scheduling/s4u-dag-scheduling.cpp
examples/cpp/trace-host-user-variables/s4u-trace-host-user-variables.cpp
examples/cpp/trace-masterworkers/s4u-trace-masterworkers.cpp
examples/smpi/ampi_test/ampi_test.cpp
examples/smpi/replay_multiple_manual_deploy/replay_multiple_manual.cpp
src/instr/instr_config.cpp
src/kernel/lmm/bmf.cpp
src/kernel/resource/Model.cpp
src/kernel/resource/VirtualMachineImpl.cpp
src/kernel/routing/NetZoneImpl.cpp
src/mc/api/State.cpp
src/mc/inspect/mc_dwarf.cpp
src/mc/inspect/mc_unw_vmread.cpp
src/mc/mc_record.cpp
src/mc/remote/RemoteProcess.cpp
src/plugins/file_system/s4u_FileSystem.cpp
src/smpi/bindings/smpi_f77.cpp
src/smpi/bindings/smpi_f77_comm.cpp
src/smpi/include/smpi_keyvals.hpp
src/smpi/internals/instr_smpi.cpp
src/smpi/internals/smpi_global.cpp
src/smpi/internals/smpi_host.cpp
src/smpi/internals/smpi_utils.cpp
src/smpi/mpi/smpi_f2c.cpp
src/smpi/mpi/smpi_file.cpp
src/smpi/mpi/smpi_info.cpp
src/smpi/mpi/smpi_request.cpp
src/surf/network_ib.cpp
src/surf/network_ns3.cpp
src/surf/surf_interface.cpp
src/xbt/dynar.cpp
src/xbt/log.cpp
teshsuite/models/cloud-sharing/cloud-sharing.cpp

index da4e24b..47c77e4 100644 (file)
@@ -225,8 +225,8 @@ int main(int argc, char** argv)
      * 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);
index 7e2ea6f..6b587ad 100644 (file)
@@ -55,8 +55,7 @@ int main(int argc, char* argv[])
   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());
index 7700fee..76175f5 100644 (file)
@@ -105,15 +105,13 @@ int main(int argc, char* argv[])
 
   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());
index 7599c8a..5e8d430 100644 (file)
@@ -20,8 +20,8 @@ int main(int argc, char* argv[])
   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);
index 7495814..a45fe98 100644 (file)
@@ -100,8 +100,7 @@ static int workload_executor_process(const std::vector<std::unique_ptr<Job>>& wo
 {
   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());
index 688ff68..22ad0fe 100644 (file)
@@ -395,8 +395,7 @@ static void on_simulation_start()
     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 */
index 1fe15cb..af1b5ff 100644 (file)
@@ -254,16 +254,16 @@ bool BmfSolver::get_alloc(const Eigen::VectorXd& fair_sharing, const allocation_
 
       /* 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;
       }
@@ -273,10 +273,8 @@ bool BmfSolver::get_alloc(const Eigen::VectorXd& fair_sharing, const allocation_
   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);
   }
@@ -433,10 +431,9 @@ void BmfSystem::get_flows_data(Eigen::Index number_cnsts, Eigen::MatrixXd& A, Ei
     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;
index 1ae513a..84946da 100644 (file)
@@ -119,8 +119,7 @@ double Model::next_occurring_event_full(double /*now*/)
   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
index ac601e9..e698ccb 100644 (file)
@@ -216,8 +216,7 @@ void VirtualMachineImpl::set_piface(s4u::VirtualMachine* piface)
 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. */
@@ -242,8 +241,8 @@ void VirtualMachineImpl::start()
   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;
@@ -362,8 +361,7 @@ void VirtualMachineImpl::set_physical_host(s4u::Host* destination)
     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);
   }
index e2baf29..6792cc7 100644 (file)
@@ -292,8 +292,7 @@ std::vector<resource::StandardLinkImpl*> NetZoneImpl::get_link_list_impl(const s
 
 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_) {
@@ -306,8 +305,7 @@ resource::StandardLinkImpl* NetZoneImpl::get_link_by_name_or_null(const std::str
 
 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_) {
index eba88b3..161135d 100644 (file)
@@ -45,11 +45,9 @@ int State::next_transition() const
   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;
index 21bb7a3..636d47e 100644 (file)
@@ -857,8 +857,7 @@ static void read_dwarf_info(simgrid::mc::ObjectInformation* info, Dwarf* dwarf)
   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;
   }
@@ -961,8 +960,7 @@ static int find_by_build_id(std::vector<char> id)
     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;
     }
@@ -1009,8 +1007,7 @@ static void MC_load_dwarf(simgrid::mc::ObjectInformation* info)
 
   // 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);
 
index ac8d259..6588e36 100644 (file)
@@ -51,8 +51,7 @@ static int access_mem(const unw_addr_space_t as, const unw_word_t addr, unw_word
 
   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
index 8330582..e074d8e 100644 (file)
@@ -61,9 +61,8 @@ simgrid::mc::RecordTrace::RecordTrace(const char* data)
   while (*current) {
     long aid;
     int times_considered;
-    int count = sscanf(current, "%ld/%d", &aid, &times_considered);
 
-    if(count != 2 && count != 1)
+    if (int count = sscanf(current, "%ld/%d", &aid, &times_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));
 
index 6862899..1ae6a20 100644 (file)
@@ -41,8 +41,7 @@ static std::string get_lib_name(const std::string& pathname)
   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);
 
index bedefd7..20e5c27 100644 (file)
@@ -176,9 +176,7 @@ sg_size_t File::write(sg_size_t size, bool write_inside)
 
   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);
index 6face77..7a2578a 100644 (file)
@@ -568,8 +568,7 @@ void mpi_op_commutative_(int* op, int* commute, int* ierr)
 
 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;
index 61b9fdc..7c1d738 100644 (file)
@@ -38,8 +38,7 @@ void mpi_comm_create_(int* comm, int* group, int* newcomm, int* ierr) {
 }
 
 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);
   }
index 66b5e2f..4c00298 100644 (file)
@@ -106,8 +106,7 @@ template <typename T> int Keyval::attr_delete(int keyval){
 
   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--;
@@ -119,12 +118,10 @@ template <typename T> int Keyval::attr_delete(int keyval){
 
 
 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 {
index 36f00c7..335b79e 100644 (file)
@@ -120,8 +120,7 @@ static std::string TRACE_smpi_get_key(aid_t src, aid_t dst, int tag, int send)
   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 {
index ced6d29..03048a0 100644 (file)
@@ -402,8 +402,7 @@ static void smpi_init_privatization_dlopen(const std::string& executable)
   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(";"));
index e3ed322..bef0db3 100644 (file)
@@ -37,8 +37,7 @@ xbt::Extension<s4u::Host, smpi::Host> Host::EXTENSION_ID;
 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 */
@@ -66,8 +65,7 @@ double Host::orecv(size_t size, s4u::Host* src, s4u::Host* dst)
 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 */
@@ -94,8 +92,7 @@ double Host::osend(size_t size, s4u::Host* src, s4u::Host* dst)
 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 */
index e4cbc80..e463b08 100644 (file)
@@ -349,8 +349,7 @@ int check_collectives_ordering(MPI_Comm comm, const std::string& call)
 {
   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
index aff6ef4..746a3b4 100644 (file)
@@ -26,8 +26,7 @@ F2C::F2C() = default;
 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;
index 5318322..38dbf19 100644 (file)
@@ -34,9 +34,8 @@ File::File(MPI_Comm comm, const char* filename, int amode, MPI_Info info) : comm
   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())
index b969e2a..dfcc335 100644 (file)
@@ -33,8 +33,7 @@ void Info::unref(Info* info){
 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);
@@ -74,8 +73,7 @@ int Info::get_nthkey(int n, char* key) const
 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;
   }
index 74fa8f6..77e49ab 100644 (file)
@@ -424,8 +424,7 @@ void Request::sendrecv(const void *sendbuf, int sendcount, MPI_Datatype sendtype
 
   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;
index 693a90f..a272167 100644 (file)
@@ -183,9 +183,9 @@ void NetworkIBModel::update_IB_factors(NetworkAction* action, IBNode* from, IBNo
       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);
     }
index a3ad27a..9255c7e 100644 (file)
@@ -322,8 +322,7 @@ NetworkNS3Model::NetworkNS3Model(const std::string& name) : NetworkModel(name)
   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") {
index 766f547..4766cdb 100644 (file)
@@ -165,9 +165,9 @@ void model_help(const char* category, const std::vector<surf_model_description_t
 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;
index a1c8d99..58633d1 100644 (file)
@@ -192,7 +192,6 @@ void* xbt_dynar_insert_at_ptr(xbt_dynar_t dynar, int idx)
   void *res;
   unsigned long old_used;
   unsigned long new_used;
-  long nb_shift;
 
   _sanity_check_dynar(dynar);
   _sanity_check_idx(idx);
@@ -202,9 +201,7 @@ void* xbt_dynar_insert_at_ptr(xbt_dynar_t dynar, int 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);
   }
 
index 2852cf8..916c77b 100644 (file)
@@ -280,9 +280,9 @@ int _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority
   }
 
   /* 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 {
index 9ceadae..fa19ad5 100644 (file)
@@ -23,11 +23,11 @@ static int computation_fun(std::vector<std::string> argv)
   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(),