From 48de0a86062b36931ca0f1bc73dc4a579292ddf7 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 5 Jan 2016 01:05:59 +0100 Subject: [PATCH 1/1] convert some C bits into C++ in surf --- include/simgrid/Host.hpp | 8 ++++++-- include/simgrid/host.h | 2 -- src/msg/msg_host.cpp | 14 ++++---------- src/simdag/sd_workstation.cpp | 6 +++--- src/simgrid/host.cpp | 17 +++++++++-------- 5 files changed, 22 insertions(+), 25 deletions(-) diff --git a/include/simgrid/Host.hpp b/include/simgrid/Host.hpp index 2810c162be..99494dc76c 100644 --- a/include/simgrid/Host.hpp +++ b/include/simgrid/Host.hpp @@ -16,15 +16,19 @@ #include #include + namespace simgrid { XBT_PUBLIC_CLASS Host : public simgrid::xbt::Extendable { public: - surf::Cpu *p_cpu = nullptr; - surf::NetCard *p_netcard = nullptr; + double getSpeed(); + int getCoreAmount(); + /* FIXME: these should be protected, but it leads to many errors */ + surf::Cpu *p_cpu = nullptr; + surf::NetCard *p_netcard = nullptr; private: simgrid::xbt::string name_ = "noname"; public: diff --git a/include/simgrid/host.h b/include/simgrid/host.h index 87abdf24ba..cd948d6a07 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -55,9 +55,7 @@ XBT_PUBLIC(void) sg_host_simix_destroy(sg_host_t host); XBT_PUBLIC(void) sg_host_init(void); // =========== user-level functions =============== -XBT_PUBLIC(double) sg_host_get_speed(sg_host_t host); XBT_PUBLIC(double) sg_host_get_available_speed(sg_host_t host); -XBT_PUBLIC(int) sg_host_get_core(sg_host_t host); XBT_PUBLIC(int) sg_host_get_state(sg_host_t host); XBT_PUBLIC(int) sg_host_get_nb_pstates(sg_host_t host); diff --git a/src/msg/msg_host.cpp b/src/msg/msg_host.cpp index c6a6e3ecbc..db76c6641f 100644 --- a/src/msg/msg_host.cpp +++ b/src/msg/msg_host.cpp @@ -214,11 +214,8 @@ xbt_dynar_t MSG_hosts_as_dynar(void) { * \brief Return the speed of the processor (in flop/s), regardless of the current load on the machine. */ -double MSG_get_host_speed(msg_host_t h) -{ - xbt_assert((h != NULL), "Invalid parameters"); - - return sg_host_get_speed(h); +double MSG_get_host_speed(msg_host_t host) { + return host->getSpeed(); } @@ -228,11 +225,8 @@ double MSG_get_host_speed(msg_host_t h) * \param host a host * \return the number of cores */ -int MSG_host_get_core_number(msg_host_t host) -{ - xbt_assert((host != NULL), "Invalid parameters"); - - return sg_host_get_core(host); +int MSG_host_get_core_number(msg_host_t host) { + return host->getCoreAmount(); } /** \ingroup m_host_management diff --git a/src/simdag/sd_workstation.cpp b/src/simdag/sd_workstation.cpp index 6a984413d9..b43f8ab3f4 100644 --- a/src/simdag/sd_workstation.cpp +++ b/src/simdag/sd_workstation.cpp @@ -6,7 +6,7 @@ #include "src/simdag/simdag_private.h" #include "simgrid/simdag.h" -#include "simgrid/host.h" +#include "simgrid/Host.hpp" #include "xbt/dict.h" #include "xbt/lib.h" #include "xbt/sysdep.h" @@ -255,7 +255,7 @@ int SD_route_get_size(SD_workstation_t src, SD_workstation_t dst) */ double SD_workstation_get_power(SD_workstation_t workstation) { - return sg_host_get_speed(workstation); + return workstation->getSpeed(); } /** * \brief Returns the amount of cores of a workstation @@ -264,7 +264,7 @@ double SD_workstation_get_power(SD_workstation_t workstation) * \return the amount of cores of this workstation */ int SD_workstation_get_cores(SD_workstation_t workstation) { - return sg_host_get_core(workstation); + return workstation->getCoreAmount(); } /** diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index 5c881b0d14..5efe860476 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -126,18 +126,10 @@ void sg_host_simix_destroy(sg_host_t host) { // =========== user-level functions =============== // ================================================ -/** @brief Get the speed of the cpu associated to a host */ -double sg_host_get_speed(sg_host_t host){ - return host->p_cpu->getSpeed(1.0); -} double sg_host_get_available_speed(sg_host_t host){ return surf_host_get_available_speed(host); } -/** @brief Returns the number of core of the processor. */ -int sg_host_get_core(sg_host_t host) { - return host->p_cpu->getCore(); -} /** @brief Returns the state of a host. * @return 1 if the host is active or 0 if it has crashed. */ @@ -180,6 +172,15 @@ Host::~Host() { } +/** @brief Get the speed of the cpu associated to a host */ +double Host::getSpeed() { + return p_cpu->getSpeed(1.0); +} +/** @brief Returns the number of core of the processor. */ +int Host::getCoreAmount() { + return p_cpu->getCore(); +} + Host* Host::by_name_or_null(const char* name) { return (Host*) xbt_dict_get_or_null(host_list, name); -- 2.20.1