From 11667312f9c0886b8e7b6ca908266d33d2282b13 Mon Sep 17 00:00:00 2001 From: Frederic Suter Date: Tue, 14 Feb 2017 11:14:05 +0100 Subject: [PATCH] get rid of sd_workstation.cpp fix sg_host_route_bandwidth function --- .../simdag/availability/sd_availability.c | 4 +- examples/simdag/scheduling/sd_scheduling.c | 4 +- examples/simdag/test/sd_test.cpp | 39 ++++---- include/simgrid/simdag.h | 18 ---- src/include/surf/datatypes.h | 3 - src/simdag/sd_task.cpp | 4 +- src/simdag/sd_workstation.cpp | 92 ------------------- src/simgrid/host.cpp | 12 ++- .../basic-parsing-test/basic-parsing-test.c | 35 +++---- .../evaluate-get-route-time.c | 5 +- tools/cmake/DefinePackages.cmake | 1 - 11 files changed, 57 insertions(+), 160 deletions(-) delete mode 100644 src/simdag/sd_workstation.cpp diff --git a/examples/simdag/availability/sd_availability.c b/examples/simdag/availability/sd_availability.c index f5993ca18f..083c5d9617 100644 --- a/examples/simdag/availability/sd_availability.c +++ b/examples/simdag/availability/sd_availability.c @@ -79,8 +79,8 @@ int main(int argc, char **argv) xbt_dynar_t changed_tasks = SD_simulate(-1.0); if (xbt_dynar_is_empty(changed_tasks)) break; - XBT_INFO("link1: bw=%.0f, lat=%f", SD_route_get_bandwidth(hosts[0], hosts[1]), - SD_route_get_latency(hosts[0], hosts[1])); + XBT_INFO("link1: bw=%.0f, lat=%f", sg_host_route_bandwidth(hosts[0], hosts[1]), + sg_host_route_latency(hosts[0], hosts[1])); XBT_INFO("Jupiter: speed=%.0f", sg_host_speed(hosts[0])* sg_host_get_available_speed(hosts[0])); XBT_INFO("Tremblay: speed=%.0f", sg_host_speed(hosts[1])* sg_host_get_available_speed(hosts[1])); diff --git a/examples/simdag/scheduling/sd_scheduling.c b/examples/simdag/scheduling/sd_scheduling.c index eca4354bef..a95be21c20 100644 --- a/examples/simdag/scheduling/sd_scheduling.c +++ b/examples/simdag/scheduling/sd_scheduling.c @@ -84,8 +84,8 @@ static double finish_on_at(SD_task_t task, sg_host_t host) if (SD_task_get_amount(parent) <= 1e-6){ redist_time= 0; } else { - redist_time = SD_route_get_latency(parent_host[0], host) + - SD_task_get_amount(parent) / SD_route_get_bandwidth(parent_host[0], host); + redist_time = sg_host_route_latency(parent_host[0], host) + + SD_task_get_amount(parent) / sg_host_route_bandwidth(parent_host[0], host); } data_available = SD_task_get_start_time(parent) + redist_time; } diff --git a/examples/simdag/test/sd_test.cpp b/examples/simdag/test/sd_test.cpp index 8be5be92a0..37066ff02d 100644 --- a/examples/simdag/test/sd_test.cpp +++ b/examples/simdag/test/sd_test.cpp @@ -5,6 +5,7 @@ * under the terms of the license (GNU LGPL) which comes with this package. */ #include "simgrid/simdag.h" +#include "simgrid/s4u.hpp" #include "xbt/ex.h" #include #include "xbt/log.h" @@ -27,29 +28,29 @@ int main(int argc, char **argv) /* test the estimation functions */ const sg_host_t *hosts = sg_host_list(); - sg_host_t h1 = hosts[4]; - sg_host_t h2 = hosts[2]; - const char *name1 = sg_host_get_name(h1); - const char *name2 = sg_host_get_name(h2); + simgrid::s4u::Host* h1 = hosts[4]; + simgrid::s4u::Host* h2 = hosts[2]; double comp_amount1 = 2000000; double comp_amount2 = 1000000; double comm_amount12 = 2000000; double comm_amount21 = 3000000; - XBT_INFO("Computation time for %f flops on %s: %f", comp_amount1, name1, comp_amount1/sg_host_speed(h1)); - XBT_INFO("Computation time for %f flops on %s: %f", comp_amount2, name2, comp_amount2/sg_host_speed(h2)); - - XBT_INFO("Route between %s and %s:", name1, name2); - SD_link_t *route = SD_route_get_list(h1, h2); - int route_size = SD_route_get_size(h1, h2); - for (int i = 0; i < route_size; i++) - XBT_INFO(" Link %s: latency = %f, bandwidth = %f", sg_link_name(route[i]), sg_link_latency(route[i]), - sg_link_bandwidth(route[i])); - xbt_free(route); - XBT_INFO("Route latency = %f, route bandwidth = %f", SD_route_get_latency(h1, h2), SD_route_get_bandwidth(h1, h2)); - XBT_INFO("Communication time for %f bytes between %s and %s: %f", comm_amount12, name1, name2, - SD_route_get_latency(h1, h2) + comm_amount12 / SD_route_get_bandwidth(h1, h2)); - XBT_INFO("Communication time for %f bytes between %s and %s: %f", comm_amount21, name2, name1, - SD_route_get_latency(h2, h1) + comm_amount21 / SD_route_get_bandwidth(h2, h1)); + XBT_INFO("Computation time for %f flops on %s: %f", comp_amount1, h1->cname(), comp_amount1/h1->speed()); + XBT_INFO("Computation time for %f flops on %s: %f", comp_amount2, h2->cname(), comp_amount2/h2->speed()); + + XBT_INFO("Route between %s and %s:", h1->cname(), h2->cname()); + std::vector route; + double latency = 0; + h1->routeTo(h2, &route, &latency); + + for (auto link : route) + XBT_INFO(" Link %s: latency = %f, bandwidth = %f", sg_link_name(link), sg_link_latency(link), + sg_link_bandwidth(link)); + + XBT_INFO("Route latency = %f, route bandwidth = %f", latency, sg_host_route_bandwidth(h1, h2)); + XBT_INFO("Communication time for %f bytes between %s and %s: %f", comm_amount12, h1->cname(), h2->cname(), + sg_host_route_latency(h1, h2) + comm_amount12 / sg_host_route_bandwidth(h1, h2)); + XBT_INFO("Communication time for %f bytes between %s and %s: %f", comm_amount21, h2->cname(), h1->cname(), + sg_host_route_latency(h2, h1) + comm_amount21 / sg_host_route_bandwidth(h2, h1)); /* creation of the tasks and their dependencies */ SD_task_t taskA = SD_task_create("Task A", NULL, 10.0); diff --git a/include/simgrid/simdag.h b/include/simgrid/simdag.h index b41becda3a..eaf760a80d 100644 --- a/include/simgrid/simdag.h +++ b/include/simgrid/simdag.h @@ -57,24 +57,6 @@ typedef enum { SD_TASK_COMM_PAR_MXN_1D_BLOCK = 4 /**< @brief MxN data redistribution (1D Block distribution) */ } e_SD_task_kind_t; - -/************************** Workstation handling ****************************/ -/** @addtogroup SD_host_api - * - * 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 hosts are created from the description file when you call the function SD_create_environment. - * - * @see sg_host_t - * @{ - */ -XBT_PUBLIC(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(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); -/** @} */ - /************************** Task handling ************************************/ /** @defgroup SD_task_api Tasks * @brief Functions for managing the tasks diff --git a/src/include/surf/datatypes.h b/src/include/surf/datatypes.h index 1a19b75d7f..3c7dc29bcb 100644 --- a/src/include/surf/datatypes.h +++ b/src/include/surf/datatypes.h @@ -7,9 +7,6 @@ #ifndef MAXMIN_DATATYPES_H #define MAXMIN_DATATYPES_H -typedef struct surf_storage *surf_storage_t; -typedef struct surf_stat *surf_stat_t; - typedef struct lmm_element *lmm_element_t; typedef struct lmm_variable *lmm_variable_t; typedef struct lmm_constraint *lmm_constraint_t; diff --git a/src/simdag/sd_task.cpp b/src/simdag/sd_task.cpp index 8de22762d4..3cf0a0e469 100644 --- a/src/simdag/sd_task.cpp +++ b/src/simdag/sd_task.cpp @@ -690,8 +690,8 @@ double SD_task_get_execution_time(SD_task_t task, int host_count, const sg_host_ if (bytes_amount != nullptr) for (int j = 0; j < host_count; j++) if (bytes_amount[i * host_count + j] != 0) - time += (SD_route_get_latency(host_list[i], host_list[j]) + - bytes_amount[i * host_count + j] / SD_route_get_bandwidth(host_list[i], host_list[j])); + time += (sg_host_route_latency(host_list[i], host_list[j]) + + bytes_amount[i * host_count + j] / sg_host_route_bandwidth(host_list[i], host_list[j])); if (time > max_time) max_time = time; diff --git a/src/simdag/sd_workstation.cpp b/src/simdag/sd_workstation.cpp deleted file mode 100644 index 5601beea36..0000000000 --- a/src/simdag/sd_workstation.cpp +++ /dev/null @@ -1,92 +0,0 @@ -/* Copyright (c) 2006-2016. The SimGrid Team. - * All rights reserved. */ - -/* This program is free software; you can redistribute it and/or modify it - * under the terms of the license (GNU LGPL) which comes with this package. */ - -#include "simgrid/s4u/host.hpp" - -#include "simdag_private.hpp" -#include "src/surf/HostImpl.hpp" -#include "surf/surf.h" - -/** @brief Returns the route between two workstations - * - * Use SD_route_get_size() to know the array size. - * - * \param src a host - * \param dst another host - * \return an array of the \ref SD_link_t composing the route - * \see SD_route_get_size(), SD_link_t - */ -SD_link_t *SD_route_get_list(sg_host_t src, sg_host_t dst) -{ - std::vector route; - src->routeTo(dst, &route, nullptr); - - int cpt=0; - SD_link_t* list = xbt_new(SD_link_t, route.size()); - for (const auto& link : route) { - list[cpt] = link; - cpt++; - } - return list; -} - -/** - * \brief Returns the number of links on the route between two workstations - * - * \param src a workstation - * \param dst another workstation - * \return the number of links on the route between these two workstations - * \see SD_route_get_list() - */ -int SD_route_get_size(sg_host_t src, sg_host_t dst) -{ - std::vector route; - src->routeTo(dst, &route, nullptr); - int size = route.size(); - return size; -} - -/** - * \brief Returns the latency of the route between two workstations. - * - * \param src the first workstation - * \param dst the second workstation - * \return the latency of the route between the two workstations (in seconds) - * \see SD_route_get_bandwidth() - */ -double SD_route_get_latency(sg_host_t src, sg_host_t dst) -{ - double latency = 0; - std::vector route; - src->routeTo(dst, &route, &latency); - - return latency; -} - -/** - * \brief Returns the bandwidth of the route between two workstations, - * i.e. the minimum link bandwidth of all between the workstations. - * - * \param src the first workstation - * \param dst the second workstation - * \return the bandwidth of the route between the two workstations (in bytes/second) - * \see SD_route_get_latency() - */ -double SD_route_get_bandwidth(sg_host_t src, sg_host_t dst) -{ - double min_bandwidth = -1.0; - - std::vector route; - src->routeTo(dst, &route, nullptr); - - for (const auto& link : route) { - double bandwidth = sg_link_bandwidth(link); - if (bandwidth < min_bandwidth || min_bandwidth < 0.0) - min_bandwidth = bandwidth; - } - - return min_bandwidth; -} diff --git a/src/simgrid/host.cpp b/src/simgrid/host.cpp index f3c7b0bf57..5ab8cdc2a2 100644 --- a/src/simgrid/host.cpp +++ b/src/simgrid/host.cpp @@ -226,12 +226,16 @@ double sg_host_route_latency(sg_host_t from, sg_host_t to) */ double sg_host_route_bandwidth(sg_host_t from, sg_host_t to) { + double min_bandwidth = -1.0; + std::vector vlinks; from->routeTo(to, &vlinks, nullptr); - double res = 0; - for (auto link : vlinks) - res += link->bandwidth(); - return res; + for (auto link : vlinks) { + double bandwidth = link->bandwidth(); + if (bandwidth < min_bandwidth || min_bandwidth < 0.0) + min_bandwidth = bandwidth; + } + return min_bandwidth; } /** @brief Displays debugging information about a host */ diff --git a/teshsuite/simdag/basic-parsing-test/basic-parsing-test.c b/teshsuite/simdag/basic-parsing-test/basic-parsing-test.c index 5a3e621422..e8a056c6bf 100644 --- a/teshsuite/simdag/basic-parsing-test/basic-parsing-test.c +++ b/teshsuite/simdag/basic-parsing-test/basic-parsing-test.c @@ -24,15 +24,17 @@ int main(int argc, char **argv) const char *name2 = sg_host_get_name(h2); fprintf(stderr, "Route between %s and %s\n", name1, name2); - SD_link_t *route = SD_route_get_list(h1, h2); - int route_size = SD_route_get_size(h1, h2); - fprintf(stderr, "Route size %d\n", route_size); - for (int i = 0; i < route_size; i++) - fprintf(stderr, " Link %s: latency = %f, bandwidth = %f\n", sg_link_name(route[i]), - sg_link_latency(route[i]), sg_link_bandwidth(route[i])); + xbt_dynar_t route = xbt_dynar_new(sizeof(SD_link_t), NULL); + sg_host_route(h1, h2, route); + fprintf(stderr, "Route size %lu\n", xbt_dynar_length(route)); + unsigned int i; + SD_link_t link; + xbt_dynar_foreach(route, i, link) + fprintf(stderr, " Link %s: latency = %f, bandwidth = %f\n", sg_link_name(link), + sg_link_latency(link), sg_link_bandwidth(link)); fprintf(stderr, "Route latency = %f, route bandwidth = %f\n", - SD_route_get_latency(h1, h2), SD_route_get_bandwidth(h1, h2)); - xbt_free(route); + sg_host_route_latency(h1, h2), sg_host_route_bandwidth(h1, h2)); + xbt_dynar_free_container(&route); } if (!strcmp(argv[2], "FULL_LINK")) { int list_size = sg_host_count(); @@ -43,16 +45,17 @@ int main(int argc, char **argv) sg_host_t h2 = hosts[j]; const char *name2 = sg_host_get_name(h2); fprintf(stderr, "Route between %s and %s\n", name1, name2); - SD_link_t *route = SD_route_get_list(h1, h2); - int route_size = SD_route_get_size(h1, h2); - fprintf(stderr, " Route size %d\n", route_size); - for (int k = 0; k < route_size; k++) { + xbt_dynar_t route = xbt_dynar_new(sizeof(SD_link_t), NULL); + sg_host_route(h1, h2, route); + fprintf(stderr, " Route size %lu\n", xbt_dynar_length(route)); + unsigned int k; + SD_link_t link; + xbt_dynar_foreach(route, k, link) fprintf(stderr, " Link %s: latency = %f, bandwidth = %f\n", - sg_link_name(route[k]), sg_link_latency(route[k]), sg_link_bandwidth(route[k])); - } + sg_link_name(link), sg_link_latency(link), sg_link_bandwidth(link)); fprintf(stderr, " Route latency = %f, route bandwidth = %f\n", - SD_route_get_latency(h1, h2), SD_route_get_bandwidth(h1, h2)); - xbt_free(route); + sg_host_route_latency(h1, h2), sg_host_route_bandwidth(h1, h2)); + xbt_dynar_free_container(&route); } } } diff --git a/teshsuite/simdag/evaluate-get-route-time/evaluate-get-route-time.c b/teshsuite/simdag/evaluate-get-route-time/evaluate-get-route-time.c index bb81c1c40b..ea122f3869 100644 --- a/teshsuite/simdag/evaluate-get-route-time/evaluate-get-route-time.c +++ b/teshsuite/simdag/evaluate-get-route-time/evaluate-get-route-time.c @@ -35,11 +35,14 @@ int main(int argc, char **argv) sg_host_t h1 = hosts[i]; sg_host_t h2 = hosts[j]; printf("%d\tand\t%d\t\t",i,j); + xbt_dynar_t route = xbt_dynar_new(sizeof(SD_link_t), NULL); xbt_os_cputimer_start(timer); - SD_route_get_list(h1, h2); + sg_host_route(h1, h2, route); xbt_os_cputimer_stop(timer); + xbt_dynar_free(&route); + printf("%f\n", xbt_os_timer_elapsed(timer) ); xbt_free(hosts); diff --git a/tools/cmake/DefinePackages.cmake b/tools/cmake/DefinePackages.cmake index 28f94ddbce..e90c9eff37 100644 --- a/tools/cmake/DefinePackages.cmake +++ b/tools/cmake/DefinePackages.cmake @@ -432,7 +432,6 @@ set(SIMDAG_SRC src/simdag/sd_dotloader.cpp src/simdag/sd_global.cpp src/simdag/sd_task.cpp - src/simdag/sd_workstation.cpp ) set(BINDINGS_SRC -- 2.20.1