From 485fa582bda7c51fb184bf0f82d0eb250be9f805 Mon Sep 17 00:00:00 2001 From: SUTER Frederic Date: Thu, 2 Sep 2021 16:52:45 +0200 Subject: [PATCH] [procrasticommit] less implicit casts and more consistency --- examples/cpp/exec-dvfs/s4u-exec-dvfs.cpp | 6 +++--- include/simgrid/host.h | 2 +- include/simgrid/kernel/routing/NetZoneImpl.hpp | 16 +++++++--------- include/simgrid/s4u/Comm.hpp | 6 +++--- include/simgrid/s4u/Host.hpp | 2 +- src/kernel/routing/NetZoneImpl.cpp | 3 ++- src/kernel/routing/TorusZone.cpp | 4 ++-- src/plugins/host_dvfs.cpp | 11 +++++------ src/plugins/host_energy.cpp | 4 ++-- src/plugins/vm/s4u_VirtualMachine.cpp | 2 +- src/s4u/s4u_Comm.cpp | 6 +++--- src/s4u/s4u_Host.cpp | 4 ++-- src/surf/cpu_interface.hpp | 2 +- src/surf/cpu_ti.cpp | 12 ++++++------ src/surf/cpu_ti.hpp | 2 +- 15 files changed, 40 insertions(+), 42 deletions(-) diff --git a/examples/cpp/exec-dvfs/s4u-exec-dvfs.cpp b/examples/cpp/exec-dvfs/s4u-exec-dvfs.cpp index d281d640fb..1f4e28be35 100644 --- a/examples/cpp/exec-dvfs/s4u-exec-dvfs.cpp +++ b/examples/cpp/exec-dvfs/s4u-exec-dvfs.cpp @@ -12,8 +12,8 @@ static int dvfs() double workload = 100E6; simgrid::s4u::Host* host = simgrid::s4u::this_actor::get_host(); - int nb = host->get_pstate_count(); - XBT_INFO("Count of Processor states=%d", nb); + unsigned long nb = host->get_pstate_count(); + XBT_INFO("Count of Processor states=%lu", nb); XBT_INFO("Current power peak=%f", host->get_speed()); @@ -40,7 +40,7 @@ static int dvfs() // Verify that the default pstate is set to 0 host = simgrid::s4u::Host::by_name_or_null("MyHost2"); - XBT_INFO("Count of Processor states=%d", host->get_pstate_count()); + XBT_INFO("Count of Processor states=%lu", host->get_pstate_count()); XBT_INFO("Current power peak=%f", host->get_speed()); return 0; diff --git a/include/simgrid/host.h b/include/simgrid/host.h index 0a872a65ed..bb73630c0b 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -89,7 +89,7 @@ XBT_PUBLIC const char* sg_host_self_get_name(); * * @param host host to test */ -XBT_PUBLIC int sg_host_get_nb_pstates(const_sg_host_t host); +XBT_PUBLIC unsigned long sg_host_get_nb_pstates(const_sg_host_t host); XBT_PUBLIC int sg_host_get_pstate(const_sg_host_t host); XBT_PUBLIC void sg_host_set_pstate(sg_host_t host, int pstate); diff --git a/include/simgrid/kernel/routing/NetZoneImpl.hpp b/include/simgrid/kernel/routing/NetZoneImpl.hpp index cb5f12c836..6acc05b29d 100644 --- a/include/simgrid/kernel/routing/NetZoneImpl.hpp +++ b/include/simgrid/kernel/routing/NetZoneImpl.hpp @@ -171,9 +171,8 @@ public: void seal(); /** @brief Check if netpoint is a member of this NetZone or some of the childrens */ bool is_component_recursive(const NetPoint* netpoint) const; - virtual int add_component(kernel::routing::NetPoint* elm); /* A host, a router or a netzone, whatever */ - virtual void add_route(kernel::routing::NetPoint* src, kernel::routing::NetPoint* dst, - kernel::routing::NetPoint* gw_src, kernel::routing::NetPoint* gw_dst, + virtual unsigned long add_component(NetPoint* elm); /* A host, a router or a netzone, whatever */ + virtual void add_route(NetPoint* src, NetPoint* dst, NetPoint* gw_src, NetPoint* gw_dst, const std::vector& link_list, bool symmetrical); /** @brief Set parent of this Netzone */ void set_parent(NetZoneImpl* parent); @@ -191,11 +190,11 @@ public: * @param links Accumulator in which all traversed links should be pushed (caller must empty it) * @param latency Accumulator in which the latencies should be added (caller must set it to 0) */ - static void get_global_route(const routing::NetPoint* src, const routing::NetPoint* dst, + static void get_global_route(const NetPoint* src, const NetPoint* dst, /* OUT */ std::vector& links, double* latency); /** @brief Similar to get_global_route but get the NetZones traversed by route */ - static void get_global_route_with_netzones(const routing::NetPoint* src, const routing::NetPoint* dst, + static void get_global_route_with_netzones(const NetPoint* src, const NetPoint* dst, /* OUT */ std::vector& links, double* latency, std::unordered_set& netzones); @@ -203,9 +202,8 @@ public: std::map>* edges) = 0; /*** Called on each newly created regular route (not on bypass routes) */ - static xbt::signal const& link_list)> + static xbt::signal const& link_list)> on_route_creation; // XBT_ATTRIB_DEPRECATED_v332 : should be an internal signal used by NS3.. if necessary, // callback shouldn't use LinkImpl* @@ -215,7 +213,7 @@ private: std::shared_ptr cpu_model_vm_; std::shared_ptr cpu_model_pm_; std::shared_ptr disk_model_; - std::shared_ptr host_model_; + std::shared_ptr host_model_; /** @brief Perform sealing procedure for derived classes, if necessary */ virtual void do_seal() { /* obviously nothing to do by default */ diff --git a/include/simgrid/s4u/Comm.hpp b/include/simgrid/s4u/Comm.hpp index 1be8e564eb..e45f2ae3e7 100644 --- a/include/simgrid/s4u/Comm.hpp +++ b/include/simgrid/s4u/Comm.hpp @@ -55,14 +55,14 @@ public: * There is really no limit on the hosts involved. In particular, the actor does not have to be on one of the involved * hosts. */ - static CommPtr sendto_async(Host* from, Host* to, double simulated_size_in_bytes); + static CommPtr sendto_async(Host* from, Host* to, uint64_t simulated_size_in_bytes); /** Do a blocking communication between two arbitrary hosts. * * This starts a blocking communication right away, bypassing the mailbox and actors mechanism. * The calling actor is blocked until the end of the communication; there is really no limit on the hosts involved. * In particular, the actor does not have to be on one of the involved hosts. Enjoy the comfort of the simulator :) */ - static void sendto(Host* from, Host* to, double simulated_size_in_bytes); + static void sendto(Host* from, Host* to, uint64_t simulated_size_in_bytes); static xbt::signal on_start; static xbt::signal on_completion; @@ -136,7 +136,7 @@ public: * :cpp:func:`simgrid::s4u::Comm::set_src_data_size`). * @endrst */ - CommPtr set_payload_size(double bytes); + CommPtr set_payload_size(uint64_t bytes); /** Specify the data to send and its size (not to be mixed with set_payload_size()) * diff --git a/include/simgrid/s4u/Host.hpp b/include/simgrid/s4u/Host.hpp index 37921b3fc0..5ca3ce37b8 100644 --- a/include/simgrid/s4u/Host.hpp +++ b/include/simgrid/s4u/Host.hpp @@ -187,7 +187,7 @@ public: */ double get_load() const; - int get_pstate_count() const; + unsigned long get_pstate_count() const; int get_pstate() const; double get_pstate_speed(int pstate_index) const; Host* set_pstate(int pstate_index); diff --git a/src/kernel/routing/NetZoneImpl.cpp b/src/kernel/routing/NetZoneImpl.cpp index cd0cc7e4fe..b803a4c24b 100644 --- a/src/kernel/routing/NetZoneImpl.cpp +++ b/src/kernel/routing/NetZoneImpl.cpp @@ -195,7 +195,8 @@ NetPoint* NetZoneImpl::create_router(const std::string& name) return (new NetPoint(name, NetPoint::Type::Router))->set_englobing_zone(this); } -int NetZoneImpl::add_component(NetPoint* elm) + +unsigned long NetZoneImpl::add_component(NetPoint* elm) { vertices_.push_back(elm); return vertices_.size() - 1; // The rank of the newly created object diff --git a/src/kernel/routing/TorusZone.cpp b/src/kernel/routing/TorusZone.cpp index 1ef89555d0..f17a7d3a8f 100644 --- a/src/kernel/routing/TorusZone.cpp +++ b/src/kernel/routing/TorusZone.cpp @@ -115,7 +115,7 @@ void TorusZone::get_local_route(const NetPoint* src, const NetPoint* dst, Route* * linkOffset describes the offset where the link we want to use is stored(+1 is added because each node has a link * from itself to itself, which can only be the case if src->m_id == dst->m_id -- see above for this special case) */ - unsigned int linkOffset = (dsize + 1) * src->id(); + unsigned long linkOffset = (dsize + 1) * src->id(); bool use_lnk_up = false; // Is this link of the form "cur -> next" or "next -> cur"? false means: next -> cur unsigned int current_node = src->id(); @@ -149,7 +149,7 @@ void TorusZone::get_local_route(const NetPoint* src, const NetPoint* dst, Route* linkOffset = node_pos_with_loopback_limiter(next_node) + j; use_lnk_up = false; } - XBT_DEBUG("torus_get_route_and_latency - current_node: %u, next_node: %u, linkOffset is %u", current_node, + XBT_DEBUG("torus_get_route_and_latency - current_node: %u, next_node: %u, linkOffset is %lu", current_node, next_node, linkOffset); break; } diff --git a/src/plugins/host_dvfs.cpp b/src/plugins/host_dvfs.cpp index 5becbc1b3f..9ab9a25765 100644 --- a/src/plugins/host_dvfs.cpp +++ b/src/plugins/host_dvfs.cpp @@ -89,8 +89,8 @@ namespace dvfs { class Governor { simgrid::s4u::Host* const host_; double sampling_rate_; - int min_pstate = cfg_min_pstate; //< Never use a pstate less than this one - int max_pstate = cfg_max_pstate; //< Never use a pstate larger than this one + unsigned long min_pstate = cfg_min_pstate; //< Never use a pstate less than this one + unsigned long max_pstate = cfg_max_pstate; //< Never use a pstate larger than this one public: explicit Governor(simgrid::s4u::Host* ptr) @@ -116,16 +116,15 @@ public: } const char* local_min_pstate_config = host_->get_property(cfg_min_pstate.get_name()); if (local_min_pstate_config != nullptr) { - min_pstate = std::stoi(local_min_pstate_config); + min_pstate = std::stoul(local_min_pstate_config); } const char* local_max_pstate_config = host_->get_property(cfg_max_pstate.get_name()); if (local_max_pstate_config != nullptr) { - max_pstate = std::stoi(local_max_pstate_config); + max_pstate = std::stoul(local_max_pstate_config); } xbt_assert(max_pstate <= host_->get_pstate_count() - 1, "Value for max_pstate too large!"); xbt_assert(min_pstate <= max_pstate, "min_pstate is larger than max_pstate!"); - xbt_assert(0 <= min_pstate, "min_pstate is negative!"); } virtual void update() = 0; @@ -341,7 +340,7 @@ public: bool is_initialized = rates[task_id][best_pstate] != 0; rates[task_id][best_pstate] = computed_flops / comp_timer; if (not is_initialized) { - for (int i = 1; i < get_host()->get_pstate_count(); i++) { + for (unsigned long i = 1; i < get_host()->get_pstate_count(); i++) { rates[task_id][i] = rates[task_id][0] * (get_host()->get_pstate_speed(i) / get_host()->get_speed()); } } diff --git a/src/plugins/host_energy.cpp b/src/plugins/host_energy.cpp index 81f1162a12..7917c2df1c 100644 --- a/src/plugins/host_energy.cpp +++ b/src/plugins/host_energy.cpp @@ -349,8 +349,8 @@ void HostEnergy::init_watts_range_list() boost::split(all_power_values, all_power_values_str, boost::is_any_of(",")); XBT_DEBUG("%s: power properties: %s", host_->get_cname(), all_power_values_str); - xbt_assert(all_power_values.size() == (unsigned)host_->get_pstate_count(), - "Invalid XML file. Found %zu energetic profiles for %d pstates", all_power_values.size(), + xbt_assert(all_power_values.size() == host_->get_pstate_count(), + "Invalid XML file. Found %zu energetic profiles for %lu pstates", all_power_values.size(), host_->get_pstate_count()); int i = 0; diff --git a/src/plugins/vm/s4u_VirtualMachine.cpp b/src/plugins/vm/s4u_VirtualMachine.cpp index 4818d15444..9eadb22a37 100644 --- a/src/plugins/vm/s4u_VirtualMachine.cpp +++ b/src/plugins/vm/s4u_VirtualMachine.cpp @@ -40,7 +40,7 @@ VirtualMachine::VirtualMachine(const std::string& name, s4u::Host* physical_host // Create a VCPU for this VM std::vector speeds; - for (int i = 0; i < physical_host->get_pstate_count(); i++) + for (unsigned long i = 0; i < physical_host->get_pstate_count(); i++) speeds.push_back(physical_host->get_pstate_speed(i)); physical_host->get_netpoint() diff --git a/src/s4u/s4u_Comm.cpp b/src/s4u/s4u_Comm.cpp index ca60e6fbfe..a359f506d5 100644 --- a/src/s4u/s4u_Comm.cpp +++ b/src/s4u/s4u_Comm.cpp @@ -151,7 +151,7 @@ CommPtr Comm::set_dst_data(void** buff, size_t size) dst_buff_size_ = size; return this; } -CommPtr Comm::set_payload_size(double bytes) +CommPtr Comm::set_payload_size(uint64_t bytes) { Activity::set_remaining(bytes); return this; @@ -166,14 +166,14 @@ CommPtr Comm::sendto_init(Host* from, Host* to) return res; } -CommPtr Comm::sendto_async(Host* from, Host* to, double simulated_size_in_bytes) +CommPtr Comm::sendto_async(Host* from, Host* to, uint64_t simulated_size_in_bytes) { auto res = Comm::sendto_init(from, to)->set_payload_size(simulated_size_in_bytes); res->vetoable_start(); return res; } -void Comm::sendto(Host* from, Host* to, double simulated_size_in_bytes) +void Comm::sendto(Host* from, Host* to, uint64_t simulated_size_in_bytes) { sendto_async(from, to, simulated_size_in_bytes)->wait(); } diff --git a/src/s4u/s4u_Host.cpp b/src/s4u/s4u_Host.cpp index fb079bf84a..fba8ef40ed 100644 --- a/src/s4u/s4u_Host.cpp +++ b/src/s4u/s4u_Host.cpp @@ -126,7 +126,7 @@ bool Host::is_on() const return this->pimpl_cpu_->is_on(); } -int Host::get_pstate_count() const +unsigned long Host::get_pstate_count() const { return this->pimpl_cpu_->get_pstate_count(); } @@ -538,7 +538,7 @@ double sg_host_get_available_speed(const_sg_host_t host) * * See also @ref plugin_host_energy. */ -int sg_host_get_nb_pstates(const_sg_host_t host) +unsigned long sg_host_get_nb_pstates(const_sg_host_t host) { return host->get_pstate_count(); } diff --git a/src/surf/cpu_interface.hpp b/src/surf/cpu_interface.hpp index a8b3440a15..82c24bee11 100644 --- a/src/surf/cpu_interface.hpp +++ b/src/surf/cpu_interface.hpp @@ -99,7 +99,7 @@ public: /** @brief Get the peak processor speed (in flops/s), at the specified pstate */ virtual double get_pstate_peak_speed(int pstate_index) const; - virtual int get_pstate_count() const { return speed_per_pstate_.size(); } + virtual unsigned long get_pstate_count() const { return speed_per_pstate_.size(); } virtual int get_pstate() const { return pstate_; } virtual CpuImpl* set_pstate(int pstate_index); diff --git a/src/surf/cpu_ti.cpp b/src/surf/cpu_ti.cpp index ec6191d4dd..7df0d784ae 100644 --- a/src/surf/cpu_ti.cpp +++ b/src/surf/cpu_ti.cpp @@ -31,7 +31,7 @@ CpuTiProfile::CpuTiProfile(const profile::Profile* profile) { double integral = 0; double time = 0; - unsigned nb_points = profile->get_event_list().size() + 1; + unsigned long nb_points = profile->get_event_list().size() + 1; time_points_.reserve(nb_points); integral_.reserve(nb_points); for (auto const& val : profile->get_event_list()) { @@ -106,10 +106,10 @@ double CpuTiProfile::integrate_simple_point(double a) const { double integral = 0; double a_aux = a; - int ind = binary_search(time_points_, a); + long ind = binary_search(time_points_, a); integral += integral_[ind]; - XBT_DEBUG("a %f ind %d integral %f ind + 1 %f ind %f time +1 %f time %f", a, ind, integral, integral_[ind + 1], + XBT_DEBUG("a %f ind %ld integral %f ind + 1 %f ind %f time +1 %f time %f", a, ind, integral, integral_[ind + 1], integral_[ind], time_points_[ind + 1], time_points_[ind]); double_update(&a_aux, time_points_[ind], sg_maxmin_precision * sg_surf_precision); if (a_aux > 0) @@ -187,7 +187,7 @@ double CpuTiTmgr::solve(double a, double amount) const double CpuTiProfile::solve_simple(double a, double amount) const { double integral_a = integrate_simple_point(a); - int ind = binary_search(integral_, integral_a + amount); + long ind = binary_search(integral_, integral_a + amount); double time = time_points_[ind]; time += (integral_a + amount - integral_[ind]) / ((integral_[ind + 1] - integral_[ind]) / (time_points_[ind + 1] - time_points_[ind])); @@ -205,7 +205,7 @@ double CpuTiProfile::solve_simple(double a, double amount) const double CpuTiTmgr::get_power_scale(double a) const { double reduced_a = a - floor(a / last_time_) * last_time_; - int point = CpuTiProfile::binary_search(profile_->time_points_, reduced_a); + long point = CpuTiProfile::binary_search(profile_->time_points_, reduced_a); kernel::profile::DatedValue val = speed_profile_->get_event_list().at(point); return val.value_; } @@ -255,7 +255,7 @@ CpuTiTmgr::CpuTiTmgr(kernel::profile::Profile* speed_profile, double value) : sp * @param a Value to search * @return Index of point */ -int CpuTiProfile::binary_search(const std::vector& array, double a) +long CpuTiProfile::binary_search(const std::vector& array, double a) { if (array[0] > a) return 0; diff --git a/src/surf/cpu_ti.hpp b/src/surf/cpu_ti.hpp index 9557b0566f..4d6cd178bd 100644 --- a/src/surf/cpu_ti.hpp +++ b/src/surf/cpu_ti.hpp @@ -34,7 +34,7 @@ public: std::vector time_points_; std::vector integral_; - static int binary_search(const std::vector& array, double a); + static long binary_search(const std::vector& array, double a); }; class CpuTiTmgr { -- 2.20.1