From 2fd15b45d25da87fc9c2ae646c7ff50cc303dfb1 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Wed, 27 Jan 2016 00:20:45 +0100 Subject: [PATCH] tidying and cosmetics --- examples/simdag/properties/sd_prop.c | 4 +- examples/simdag/properties/test_prop.tesh | 14 ++-- include/simgrid/host.h | 10 ++- include/simgrid/simdag.h | 38 ++++------- src/simdag/sd_workstation.cpp | 81 ++--------------------- src/simgrid/host.cpp | 64 +++++++++++++++++- src/xbt/log.c | 6 +- 7 files changed, 100 insertions(+), 117 deletions(-) diff --git a/examples/simdag/properties/sd_prop.c b/examples/simdag/properties/sd_prop.c index 4af031c2c5..ad340f4a5d 100644 --- a/examples/simdag/properties/sd_prop.c +++ b/examples/simdag/properties/sd_prop.c @@ -44,7 +44,7 @@ int main(int argc, char **argv) /* The host properties can be retrieved from all interfaces */ - XBT_INFO("Property list for workstation %s", name1); + XBT_INFO("Property list for host %s", name1); /* Get the property list of the workstation 1 */ props = sg_host_get_properties(w1); @@ -63,7 +63,7 @@ int main(int argc, char **argv) XBT_INFO("\tProperty: %s has value: %s", noexist, value?value:"Undefined (NULL)"); - XBT_INFO("Property list for workstation %s", name2); + XBT_INFO("Property list for host %s", name2); /* Get the property list of the workstation 2 */ props = sg_host_get_properties(w2); cursor = NULL; diff --git a/examples/simdag/properties/test_prop.tesh b/examples/simdag/properties/test_prop.tesh index 0748d8d6dc..bb27cf84f4 100755 --- a/examples/simdag/properties/test_prop.tesh +++ b/examples/simdag/properties/test_prop.tesh @@ -4,18 +4,18 @@ p Simple test of simdag with properties $ $SG_TEST_EXENV properties/sd_prop ${srcdir:=.}/../platforms/prop.xml > [0.000000] [xbt_cfg/INFO] Switching to the L07 model to handle parallel tasks. -> [0.000000] [test/INFO] Property list for workstation host1 +> [0.000000] [test/INFO] Property list for host host1 > [0.000000] [test/INFO] Property: mem has value: 4 > [0.000000] [test/INFO] Property: NewProp has value: newValue > [0.000000] [test/INFO] Property: Hdd has value: 180 > [0.000000] [test/INFO] Property: NoProp has value: Undefined (NULL) -> [0.000000] [test/INFO] Property list for workstation host2 +> [0.000000] [test/INFO] Property list for host host2 > [0.000000] [test/INFO] Property: Hdd on host: 120 > [0.000000] [test/INFO] Modify an existing property > [0.000000] [test/INFO] Property: Hdd old value: 120 > [0.000000] [test/INFO] Property: Hdd new value: 250 -> [0.000000] [sd_workstation/INFO] Displaying workstation host2 -> [0.000000] [sd_workstation/INFO] - speed: 1000000000 -> [0.000000] [sd_workstation/INFO] - available speed: 1.00 -> [0.000000] [sd_workstation/INFO] - properties: -> [0.000000] [sd_workstation/INFO] Hdd->250 +> [0.000000] [sg_host/INFO] Displaying host host2 +> [0.000000] [sg_host/INFO] - speed: 1000000000 +> [0.000000] [sg_host/INFO] - available speed: 1.00 +> [0.000000] [sg_host/INFO] - properties: +> [0.000000] [sg_host/INFO] Hdd->250 diff --git a/include/simgrid/host.h b/include/simgrid/host.h index 2e2ee13556..410091f56f 100644 --- a/include/simgrid/host.h +++ b/include/simgrid/host.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2013-2015. The SimGrid Team. +/* Copyright (c) 2013-2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -21,6 +21,8 @@ SG_BEGIN_DECL() XBT_PUBLIC(size_t) sg_host_count(); +XBT_PUBLIC(const sg_host_t *) sg_host_list(void); + XBT_PUBLIC(size_t) sg_host_extension_create(void(*deleter)(void*)); XBT_PUBLIC(void*) sg_host_extension_get(sg_host_t host, size_t rank); XBT_PUBLIC(sg_host_t) sg_host_by_name(const char *name); @@ -47,8 +49,13 @@ XBT_PUBLIC(void) sg_host_simix_destroy(sg_host_t host); // Module initializer. Won't survive the conversion to C++. Hopefully. XBT_PUBLIC(void) sg_host_init(void); +// ========= storage related functions ============ +XBT_PUBLIC(xbt_dict_t) sg_host_get_mounted_storage_list(sg_host_t host); +XBT_PUBLIC(xbt_dynar_t) sg_host_get_attached_storage_list(sg_host_t host); // =========== user-level functions =============== +XBT_PUBLIC(double) sg_host_speed(sg_host_t host); XBT_PUBLIC(double) sg_host_get_available_speed(sg_host_t host); +XBT_PUBLIC(int) sg_host_core_count(sg_host_t host); XBT_PUBLIC(int) sg_host_is_on(sg_host_t host); XBT_PUBLIC(int) sg_host_get_nb_pstates(sg_host_t host); @@ -57,6 +64,7 @@ XBT_PUBLIC(void) sg_host_set_pstate(sg_host_t host,int pstate); XBT_PUBLIC(xbt_dict_t) sg_host_get_properties(sg_host_t host); XBT_PUBLIC(const char *) sg_host_get_property_value(sg_host_t host, const char *name); +XBT_PUBLIC(void) sg_host_dump(sg_host_t ws); SG_END_DECL() #endif /* SIMGRID_HOST_H_ */ diff --git a/include/simgrid/simdag.h b/include/simgrid/simdag.h index 0e149b0116..8fd4c49e54 100644 --- a/include/simgrid/simdag.h +++ b/include/simgrid/simdag.h @@ -1,4 +1,4 @@ -/* Copyright (c) 2006-2010, 2012-2015. The SimGrid Team. +/* Copyright (c) 2006-2010, 2012-2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -75,41 +75,29 @@ typedef xbt_dictelm_t SD_storage_t; /************************** Workstation handling ****************************/ -/** @defgroup sg_host_management Workstations - * @brief Functions for managing the workstations +/** @defgroup sg_host_management Hosts + * @brief Functions for managing the Hosts * - * This section describes the functions for managing the workstations. + * This section describes the functions for managing the hosts. * - * A workstation is a place where a task can be executed. - * A workstation is represented as a physical - * resource with computing capabilities and has a name. + * A host is a place where a task can be executed. + * A host is represented as a physical resource with computing + * capabilities and has a name. * - * The workstations are created when you call the function SD_create_environment. + * The hosts are created when you call the function SD_create_environment. * * @see sg_host_t * @{ */ -XBT_PUBLIC(const sg_host_t *) sg_host_list(void); - -XBT_PUBLIC(void) sg_host_dump(sg_host_t ws); -XBT_PUBLIC(double) sg_host_speed(sg_host_t workstation); -XBT_PUBLIC(int) sg_host_core_count(sg_host_t workstation); -XBT_PUBLIC(double) sg_host_computation_time(sg_host_t workstation, - double flops_amount); -XBT_PUBLIC(xbt_dict_t) - sg_host_get_mounted_storage_list(sg_host_t workstation); -XBT_PUBLIC(xbt_dynar_t) - sg_host_get_attached_storage_list(sg_host_t workstation); +XBT_PUBLIC(double) sg_host_computation_time(sg_host_t host, + double flops_amount); XBT_PUBLIC(const SD_link_t *) SD_route_get_list(sg_host_t src, sg_host_t dst); -XBT_PUBLIC(int) SD_route_get_size(sg_host_t src, - sg_host_t dst); +XBT_PUBLIC(int) SD_route_get_size(sg_host_t src, sg_host_t dst); -XBT_PUBLIC(double) SD_route_get_latency(sg_host_t src, - sg_host_t dst); -XBT_PUBLIC(double) SD_route_get_bandwidth(sg_host_t src, - sg_host_t dst); +XBT_PUBLIC(double) SD_route_get_latency(sg_host_t src, sg_host_t dst); +XBT_PUBLIC(double) SD_route_get_bandwidth(sg_host_t src, sg_host_t dst); XBT_PUBLIC(double) SD_route_get_communication_time(sg_host_t src, sg_host_t dst, double bytes_amount); diff --git a/src/simdag/sd_workstation.cpp b/src/simdag/sd_workstation.cpp index 838f731f8c..1413ad352e 100644 --- a/src/simdag/sd_workstation.cpp +++ b/src/simdag/sd_workstation.cpp @@ -14,9 +14,6 @@ #include "xbt/sysdep.h" #include "surf/surf.h" -XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_workstation, sd, - "Logging specific to SimDag (workstation)"); - /* Creates a storage and registers it in SD. */ SD_storage_t __SD_storage_create(void *surf_storage, void *data) @@ -43,43 +40,11 @@ void __SD_storage_destroy(void *storage) xbt_free(s); } -/** - * \brief Returns the workstation list - * - * Use sg_host_count() to know the array size. - * - * \return an array of \ref sg_host_t containing all workstations - * \remark The workstation order in the returned array is generally different from the workstation creation/declaration order in the XML platform (we use a hash table internally). - * \see sg_host_count() - */ -const sg_host_t *sg_host_list(void) { - xbt_assert(sg_host_count() > 0, "There is no workstation!"); - - if (sd_global->host_list == NULL) /* this is the first time the function is called */ - sd_global->host_list = (sg_host_t*)xbt_dynar_to_array(sg_hosts_as_dynar()); - - return sd_global->host_list; -} - -/** @brief Displays debugging informations about a workstation */ -void sg_host_dump(sg_host_t ws) +double sg_host_computation_time(sg_host_t host, double flops_amount) { - xbt_dict_t props; - xbt_dict_cursor_t cursor=NULL; - char *key,*data; - - XBT_INFO("Displaying workstation %s", sg_host_get_name(ws)); - XBT_INFO(" - speed: %.0f", ws->speed()); - XBT_INFO(" - available speed: %.2f", sg_host_get_available_speed(ws)); - props = sg_host_get_properties(ws); - - if (!xbt_dict_is_empty(props)){ - XBT_INFO(" - properties:"); - - xbt_dict_foreach(props,cursor,key,data) { - XBT_INFO(" %s->%s",key,data); - } - } + xbt_assert(flops_amount >= 0, + "flops_amount must be greater than or equal to zero"); + return flops_amount / sg_host_speed(host); } /** @@ -92,31 +57,6 @@ void sg_host_dump(sg_host_t ws) * \return a new array of \ref SD_link_t representing the route between these two workstations * \see SD_route_get_size(), SD_link_t */ -double sg_host_speed(sg_host_t workstation) -{ - return workstation->speed(); -} -int sg_host_core_count(sg_host_t workstation) { - return workstation->core_count(); -} - - -double sg_host_computation_time(sg_host_t workstation, - double flops_amount) -{ - xbt_assert(flops_amount >= 0, - "flops_amount must be greater than or equal to zero"); - return flops_amount / workstation->speed(); -} - -xbt_dict_t sg_host_get_mounted_storage_list(sg_host_t workstation){ - return workstation->extension()->getMountedStorageList(); -} - -xbt_dynar_t sg_host_get_attached_storage_list(sg_host_t workstation){ - return surf_host_get_attached_storage_list(workstation); -} - const SD_link_t *SD_route_get_list(sg_host_t src, sg_host_t dst) { @@ -151,19 +91,6 @@ int SD_route_get_size(sg_host_t src, sg_host_t dst) (surf_host_model_t)surf_host_model, src, dst)); } -/** - * \brief Returns the total speed of a workstation - * - * \param workstation a workstation - * \return the total speed of this workstation - * \see sg_host_get_available_speed() - */ -/** - * \brief Returns the amount of cores of a workstation - * - * \param workstation a workstation - * \return the amount of cores of this workstation - */ /** * \brief Returns an approximative estimated time for the given computation amount on a workstation * diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index b11ac9c783..94def06371 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -1,4 +1,4 @@ -/* Copyright (c) 2013-201. The SimGrid Team. +/* Copyright (c) 2013-2016. The SimGrid Team. * All rights reserved. */ /* This program is free software; you can redistribute it and/or modify it @@ -13,10 +13,26 @@ #include "src/simix/smx_private.hpp" #include "src/surf/host_interface.hpp" +XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sg_host, sd, "Logging specific to sg_hosts"); + size_t sg_host_count() { return xbt_dict_length(host_list); } +/** @brief Returns the host list + * + * Uses sg_host_count() to know the array size. + * + * \return an array of \ref sg_host_t containing all the hosts in the platform. + * \remark The host order in this array is generally different from the + * creation/declaration order in the XML platform (we use a hash table + * internally). + * \see sg_host_count() + */ +const sg_host_t *sg_host_list(void) { + xbt_assert(sg_host_count() > 0, "There is no host!"); + return (sg_host_t*)xbt_dynar_to_array(sg_hosts_as_dynar()); +} const char *sg_host_get_name(sg_host_t host) { @@ -108,17 +124,40 @@ void sg_host_simix_destroy(sg_host_t host) { host->extension_set(SIMIX_HOST_LEVEL, nullptr); } +// ========= storage related functions ============ +xbt_dict_t sg_host_get_mounted_storage_list(sg_host_t host){ + return host->extension()->getMountedStorageList(); +} + +xbt_dynar_t sg_host_get_attached_storage_list(sg_host_t host){ + return host->extension()->getAttachedStorageList(); +} + + // =========== user-level functions =============== // ================================================ +/** @brief Returns the total speed of a host + */ +double sg_host_speed(sg_host_t host) +{ + return host->speed(); +} + double sg_host_get_available_speed(sg_host_t host){ return surf_host_get_available_speed(host); } +/** @brief Returns the number of cores of a host +*/ +int sg_host_core_count(sg_host_t host) { + return host->core_count(); +} + /** @brief Returns the state of a host. * @return 1 if the host is active or 0 if it has crashed. */ int sg_host_is_on(sg_host_t host) { - return host->is_on(); + return host->is_on(); } /** @brief Returns the number of power states for a host. @@ -149,7 +188,6 @@ xbt_dict_t sg_host_get_properties(sg_host_t host) { return host->properties(); } - /** \ingroup m_host_management * \brief Returns the value of a given host property * @@ -162,3 +200,23 @@ const char *sg_host_get_property_value(sg_host_t host, const char *name) return (const char*) xbt_dict_get_or_null(sg_host_get_properties(host), name); } +/** @brief Displays debugging informations about a host */ +void sg_host_dump(sg_host_t host) +{ + xbt_dict_t props; + xbt_dict_cursor_t cursor=NULL; + char *key,*data; + + XBT_INFO("Displaying host %s", sg_host_get_name(host)); + XBT_INFO(" - speed: %.0f", sg_host_speed(host)); + XBT_INFO(" - available speed: %.2f", sg_host_get_available_speed(host)); + props = sg_host_get_properties(host); + + if (!xbt_dict_is_empty(props)){ + XBT_INFO(" - properties:"); + + xbt_dict_foreach(props,cursor,key,data) { + XBT_INFO(" %s->%s",key,data); + } + } +} diff --git a/src/xbt/log.c b/src/xbt/log.c index 85e33d3788..6592d41e0e 100644 --- a/src/xbt/log.c +++ b/src/xbt/log.c @@ -663,7 +663,10 @@ static void xbt_log_connect_categories(void) XBT_LOG_CONNECT(msg_synchro); XBT_LOG_CONNECT(msg_task); XBT_LOG_CONNECT(msg_vm); - + + /* sg */ + XBT_LOG_CONNECT(sg_host); + /* simdag */ XBT_LOG_CONNECT(sd); XBT_LOG_CONNECT(sd_daxparse); @@ -672,7 +675,6 @@ static void xbt_log_connect_categories(void) #endif XBT_LOG_CONNECT(sd_kernel); XBT_LOG_CONNECT(sd_task); - XBT_LOG_CONNECT(sd_workstation); /* simix */ XBT_LOG_CONNECT(simix); -- 2.20.1