Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Let's call sg::surf::host a HostImplem
[simgrid.git] / src / simdag / sd_workstation.cpp
1 /* Copyright (c) 2006-2016. The SimGrid Team.
2  * All rights reserved.                                                     */
3
4 /* This program is free software; you can redistribute it and/or modify it
5  * under the terms of the license (GNU LGPL) which comes with this package. */
6
7 #include "src/simdag/simdag_private.h"
8 #include <simgrid/s4u/host.hpp>
9 #include "src/surf/HostImplem.hpp"
10 #include "surf/surf.h"
11
12 /** @brief Returns the route between two workstations
13  *
14  * Use SD_route_get_size() to know the array size.
15  *
16  * \param src a host
17  * \param dst another host
18  * \return an array of the \ref SD_link_t composing the route
19  * \see SD_route_get_size(), SD_link_t
20  */
21 SD_link_t *SD_route_get_list(sg_host_t src, sg_host_t dst)
22 {
23   void *surf_link;
24   unsigned int cpt;
25   xbt_dynar_t surf_route = NULL;
26   routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, &surf_route, NULL);
27
28   SD_link_t *list = xbt_new(SD_link_t, xbt_dynar_length(surf_route));
29   xbt_dynar_foreach(surf_route, cpt, surf_link) {
30     list[cpt] = (SD_link_t)surf_link;
31   }
32   return list;
33 }
34
35 /**
36  * \brief Returns the number of links on the route between two workstations
37  *
38  * \param src a workstation
39  * \param dst another workstation
40  * \return the number of links on the route between these two workstations
41  * \see SD_route_get_list()
42  */
43 int SD_route_get_size(sg_host_t src, sg_host_t dst)
44 {
45   xbt_dynar_t surf_route = NULL;
46   routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, &surf_route, NULL);
47   return xbt_dynar_length(surf_route);
48 }
49
50 /**
51  * \brief Returns the latency of the route between two workstations.
52  *
53  * \param src the first workstation
54  * \param dst the second workstation
55  * \return the latency of the route between the two workstations (in seconds)
56  * \see SD_route_get_bandwidth()
57  */
58 double SD_route_get_latency(sg_host_t src, sg_host_t dst)
59 {
60   xbt_dynar_t route = NULL;
61   double latency = 0;
62
63   routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, &route, &latency);
64
65   return latency;
66 }
67
68 /**
69  * \brief Returns the bandwidth of the route between two workstations,
70  * i.e. the minimum link bandwidth of all between the workstations.
71  *
72  * \param src the first workstation
73  * \param dst the second workstation
74  * \return the bandwidth of the route between the two workstations (in bytes/second)
75  * \see SD_route_get_latency()
76  */
77 double SD_route_get_bandwidth(sg_host_t src, sg_host_t dst)
78 {
79   xbt_dynar_t route = NULL;
80   unsigned int cpt;
81   double latency = 0;
82   double min_bandwidth = -1.0;
83   SD_link_t link;
84
85   routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, &route, &latency);
86
87   xbt_dynar_foreach(route, cpt, link){
88     double bandwidth = sg_link_bandwidth(link);
89     if (bandwidth < min_bandwidth || min_bandwidth == -1.0)
90       min_bandwidth = bandwidth;
91   }
92
93   return min_bandwidth;
94 }