Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
kill dumb function
[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 /* Creates a storage and registers it in SD.
18  */
19 SD_storage_t __SD_storage_create(void *surf_storage, void *data)
20 {
21
22   SD_storage_priv_t storage;
23   const char *name;
24
25   storage = xbt_new(s_SD_storage_priv_t, 1);
26   storage->data = data;     /* user data */
27   name = surf_resource_name((surf_cpp_resource_t)surf_storage);
28   storage->host = (const char*)surf_storage_get_host( (surf_resource_t )surf_storage_resource_by_name(name));
29   xbt_lib_set(storage_lib,name, SD_STORAGE_LEVEL, storage);
30   return xbt_lib_get_elm_or_null(storage_lib, name);
31 }
32
33 /* Destroys a storage.
34  */
35 void __SD_storage_destroy(void *storage)
36 {
37   SD_storage_priv_t s;
38
39   s = (SD_storage_priv_t) storage;
40   xbt_free(s);
41 }
42
43 /**
44  * \brief Returns the route between two workstations
45  *
46  * Use SD_route_get_size() to know the array size.
47  *
48  * \param src a workstation
49  * \param dst another workstation
50  * \return a new array of \ref SD_link_t representing the route between these two workstations
51  * \see SD_route_get_size(), SD_link_t
52  */
53 const SD_link_t *SD_route_get_list(sg_host_t src,
54                                    sg_host_t dst)
55 {
56   xbt_dynar_t surf_route;
57   void *surf_link;
58   unsigned int cpt;
59
60   if (sd_global->recyclable_route == NULL) {
61     /* first run */
62     sd_global->recyclable_route = xbt_new(SD_link_t, sg_link_count());
63   }
64
65   surf_route = surf_host_model_get_route((surf_host_model_t)surf_host_model, src, dst);
66
67   xbt_dynar_foreach(surf_route, cpt, surf_link) {
68     sd_global->recyclable_route[cpt] = (SD_link_t)surf_link;
69   }
70   return sd_global->recyclable_route;
71 }
72
73 /**
74  * \brief Returns the number of links on the route between two workstations
75  *
76  * \param src a workstation
77  * \param dst another workstation
78  * \return the number of links on the route between these two workstations
79  * \see SD_route_get_list()
80  */
81 int SD_route_get_size(sg_host_t src, sg_host_t dst)
82 {
83   return xbt_dynar_length(surf_host_model_get_route(
84                     (surf_host_model_t)surf_host_model, src, dst));
85 }
86
87 /**
88  * \brief Returns an approximative estimated time for the given computation amount on a workstation
89  *
90  * \param workstation a workstation
91  * \param flops_amount the computation amount you want to evaluate (in flops)
92  * \return an approximative estimated computation time for the given computation amount on this workstation (in seconds)
93  */
94 /**
95  * \brief Returns the latency of the route between two workstations.
96  *
97  * \param src the first workstation
98  * \param dst the second workstation
99  * \return the latency of the route between the two workstations (in seconds)
100  * \see SD_route_get_bandwidth()
101  */
102 double SD_route_get_latency(sg_host_t src, sg_host_t dst)
103 {
104   xbt_dynar_t route = NULL;
105   double latency = 0;
106
107   routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard,
108                                     &route, &latency);
109
110   return latency;
111 }
112
113 /**
114  * \brief Returns the bandwidth of the route between two workstations,
115  * i.e. the minimum link bandwidth of all between the workstations.
116  *
117  * \param src the first workstation
118  * \param dst the second workstation
119  * \return the bandwidth of the route between the two workstations
120  * (in bytes/second)
121  * \see SD_route_get_latency()
122  */
123 double SD_route_get_bandwidth(sg_host_t src, sg_host_t dst)
124 {
125
126   const SD_link_t *links;
127   int nb_links;
128   double bandwidth;
129   double min_bandwidth;
130   int i;
131
132   links = SD_route_get_list(src, dst);
133   nb_links = SD_route_get_size(src, dst);
134   min_bandwidth = -1.0;
135
136   for (i = 0; i < nb_links; i++) {
137     bandwidth = sg_link_bandwidth(links[i]);
138     if (bandwidth < min_bandwidth || min_bandwidth == -1.0)
139       min_bandwidth = bandwidth;
140   }
141
142   return min_bandwidth;
143 }
144
145 /**
146  * \brief Returns an approximative estimated time for the given
147  * communication amount between two workstations
148  *
149  * \param src the first workstation
150  * \param dst the second workstation
151  * \param bytes_amount the communication amount you want to evaluate (in bytes)
152  * \return an approximative estimated communication time for the given bytes amount
153  * between the workstations (in seconds)
154  */
155 double SD_route_get_communication_time(sg_host_t src,
156                                        sg_host_t dst,
157                                        double bytes_amount)
158 {
159
160
161   /* total time = latency + transmission time of the slowest link
162      transmission time of a link = communication amount / link bandwidth */
163
164   const SD_link_t *links;
165   xbt_dynar_t route = NULL;
166   int nb_links;
167   double bandwidth, min_bandwidth;
168   double latency = 0;
169   int i;
170
171   xbt_assert(bytes_amount >= 0, "bytes_amount must be greater than or equal to zero");
172
173
174   if (bytes_amount == 0.0)
175     return 0.0;
176
177   routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard,
178                                     &route, &latency);
179
180   links = SD_route_get_list(src, dst);
181   nb_links = SD_route_get_size(src, dst);
182   min_bandwidth = -1.0;
183
184   for (i = 0; i < nb_links; i++) {
185     bandwidth = sg_link_bandwidth(links[i]);
186     if (bandwidth < min_bandwidth || min_bandwidth == -1.0)
187       min_bandwidth = bandwidth;
188   }
189
190   return latency + (bytes_amount / min_bandwidth);
191 }
192
193 /**
194  * \brief Return the list of mounted storages on a workstation.
195  *
196  * \param workstation a workstation
197  * \return a dynar containing all mounted storages on the workstation
198  */
199 /**
200  * \brief Return the list of mounted storages on a workstation.
201  *
202  * \param workstation a workstation
203  * \return a dynar containing all mounted storages on the workstation
204  */
205 /**
206  * \brief Returns the host name the storage is attached to
207  *
208  * This functions checks whether a storage is a valid pointer or not and return its name.
209  */
210 const char *SD_storage_get_host(msg_storage_t storage) {
211   xbt_assert((storage != NULL), "Invalid parameters");
212   SD_storage_priv_t priv = SD_storage_priv(storage);
213   return priv->host;
214 }