Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
nice error message when SD_dotload() is called without graphviz installed
[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 "simgrid/s4u/host.hpp"
8
9 #include "simdag_private.hpp"
10 #include "src/surf/HostImpl.hpp"
11 #include "surf/surf.h"
12
13 /** @brief Returns the route between two workstations
14  *
15  * Use SD_route_get_size() to know the array size.
16  *
17  * \param src a host
18  * \param dst another host
19  * \return an array of the \ref SD_link_t composing the route
20  * \see SD_route_get_size(), SD_link_t
21  */
22 SD_link_t *SD_route_get_list(sg_host_t src, sg_host_t dst)
23 {
24   std::vector<Link*> *route = new std::vector<Link*>();
25   routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, route, nullptr);
26
27   int cpt=0;
28   SD_link_t *list = xbt_new(SD_link_t, route->size());
29   for (auto link : *route){
30     list[cpt] = link;
31     cpt++;
32   }
33   delete route;
34   return list;
35 }
36
37 /**
38  * \brief Returns the number of links on the route between two workstations
39  *
40  * \param src a workstation
41  * \param dst another workstation
42  * \return the number of links on the route between these two workstations
43  * \see SD_route_get_list()
44  */
45 int SD_route_get_size(sg_host_t src, sg_host_t dst)
46 {
47   std::vector<Link*> *route = new std::vector<Link*>();
48   routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, route, nullptr);
49   int size = route->size();
50   delete route;
51   return size;
52 }
53
54 /**
55  * \brief Returns the latency of the route between two workstations.
56  *
57  * \param src the first workstation
58  * \param dst the second workstation
59  * \return the latency of the route between the two workstations (in seconds)
60  * \see SD_route_get_bandwidth()
61  */
62 double SD_route_get_latency(sg_host_t src, sg_host_t dst)
63 {
64   double latency = 0;
65   std::vector<Link*> *route = new std::vector<Link*>();
66   routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, route, &latency);
67   delete route;
68
69   return latency;
70 }
71
72 /**
73  * \brief Returns the bandwidth of the route between two workstations,
74  * i.e. the minimum link bandwidth of all between the workstations.
75  *
76  * \param src the first workstation
77  * \param dst the second workstation
78  * \return the bandwidth of the route between the two workstations (in bytes/second)
79  * \see SD_route_get_latency()
80  */
81 double SD_route_get_bandwidth(sg_host_t src, sg_host_t dst)
82 {
83   double min_bandwidth = -1.0;
84
85   std::vector<Link*> *route = new std::vector<Link*>();
86   routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard, route, nullptr);
87
88   for (auto link : *route) {
89     double bandwidth = sg_link_bandwidth(link);
90     if (bandwidth < min_bandwidth || min_bandwidth < 0.0)
91       min_bandwidth = bandwidth;
92   }
93   delete route;
94
95   return min_bandwidth;
96 }