Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Adding test for SURF concurrency feature
[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/surf/host_interface.hpp"
8 #include "src/simdag/simdag_private.h"
9 #include "simgrid/simdag.h"
10 #include "simgrid/host.h"
11 #include <simgrid/s4u/host.hpp>
12 #include "xbt/dict.h"
13 #include "xbt/lib.h"
14 #include "xbt/sysdep.h"
15 #include "surf/surf.h"
16
17 /** @brief Returns the route between two workstations
18  *
19  * Use SD_route_get_size() to know the array size.
20  *
21  * \param src a host
22  * \param dst another host
23  * \return an array of the \ref SD_link_t composing the route
24  * \see SD_route_get_size(), SD_link_t
25  */
26 const SD_link_t *SD_route_get_list(sg_host_t src, sg_host_t dst)
27 {
28   xbt_dynar_t surf_route;
29   SD_link_t* list;
30   void *surf_link;
31   unsigned int cpt;
32   surf_route = surf_host_model_get_route((surf_host_model_t)surf_host_model,
33                                          src, dst);
34
35   list = xbt_new(SD_link_t, xbt_dynar_length(surf_route));
36   xbt_dynar_foreach(surf_route, cpt, surf_link) {
37     list[cpt] = (SD_link_t)surf_link;
38   }
39   return list;
40 }
41
42 /**
43  * \brief Returns the number of links on the route between two workstations
44  *
45  * \param src a workstation
46  * \param dst another workstation
47  * \return the number of links on the route between these two workstations
48  * \see SD_route_get_list()
49  */
50 int SD_route_get_size(sg_host_t src, sg_host_t dst)
51 {
52   return xbt_dynar_length(surf_host_model_get_route(
53       (surf_host_model_t)surf_host_model, src, dst));
54 }
55
56 /**
57  * \brief Returns the latency of the route between two workstations.
58  *
59  * \param src the first workstation
60  * \param dst the second workstation
61  * \return the latency of the route between the two workstations (in seconds)
62  * \see SD_route_get_bandwidth()
63  */
64 double SD_route_get_latency(sg_host_t src, sg_host_t dst)
65 {
66   xbt_dynar_t route = NULL;
67   double latency = 0;
68
69   routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard,
70                                     &route, &latency);
71
72   return latency;
73 }
74
75 /**
76  * \brief Returns the bandwidth of the route between two workstations,
77  * i.e. the minimum link bandwidth of all between the workstations.
78  *
79  * \param src the first workstation
80  * \param dst the second workstation
81  * \return the bandwidth of the route between the two workstations
82  * (in bytes/second)
83  * \see SD_route_get_latency()
84  */
85 double SD_route_get_bandwidth(sg_host_t src, sg_host_t dst)
86 {
87   xbt_dynar_t route = NULL;
88   unsigned int cpt;
89   double latency = 0;
90   double bandwidth;
91   double min_bandwidth = -1.0;
92   SD_link_t link;
93
94   routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard,
95                                     &route, &latency);
96
97   xbt_dynar_foreach(route, cpt, link){
98     bandwidth = sg_link_bandwidth(link);
99     if (bandwidth < min_bandwidth || min_bandwidth == -1.0)
100       min_bandwidth = bandwidth;
101   }
102
103   return min_bandwidth;
104 }