1 /* Copyright (c) 2006-2016. The SimGrid Team.
2 * All rights reserved. */
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. */
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>
14 #include "xbt/sysdep.h"
15 #include "surf/surf.h"
17 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(sd_workstation, sd,
18 "Logging specific to SimDag (workstation)");
20 /* Creates a storage and registers it in SD.
22 SD_storage_t __SD_storage_create(void *surf_storage, void *data)
25 SD_storage_priv_t storage;
28 storage = xbt_new(s_SD_storage_priv_t, 1);
29 storage->data = data; /* user data */
30 name = surf_resource_name((surf_cpp_resource_t)surf_storage);
31 storage->host = (const char*)surf_storage_get_host( (surf_resource_t )surf_storage_resource_by_name(name));
32 xbt_lib_set(storage_lib,name, SD_STORAGE_LEVEL, storage);
33 return xbt_lib_get_elm_or_null(storage_lib, name);
36 /* Destroys a storage.
38 void __SD_storage_destroy(void *storage)
42 s = (SD_storage_priv_t) storage;
47 * \brief Returns the workstation list
49 * Use sg_host_count() to know the array size.
51 * \return an array of \ref sg_host_t containing all workstations
52 * \remark The workstation order in the returned array is generally different from the workstation creation/declaration order in the XML platform (we use a hash table internally).
53 * \see sg_host_count()
55 const sg_host_t *sg_host_list(void) {
56 xbt_assert(sg_host_count() > 0, "There is no workstation!");
58 if (sd_global->host_list == NULL) /* this is the first time the function is called */
59 sd_global->host_list = (sg_host_t*)xbt_dynar_to_array(sg_hosts_as_dynar());
61 return sd_global->host_list;
64 /** @brief Displays debugging informations about a workstation */
65 void sg_host_dump(sg_host_t ws)
68 xbt_dict_cursor_t cursor=NULL;
71 XBT_INFO("Displaying workstation %s", sg_host_get_name(ws));
72 XBT_INFO(" - speed: %.0f", ws->speed());
73 XBT_INFO(" - available speed: %.2f", sg_host_get_available_speed(ws));
74 props = sg_host_get_properties(ws);
76 if (!xbt_dict_is_empty(props)){
77 XBT_INFO(" - properties:");
79 xbt_dict_foreach(props,cursor,key,data) {
80 XBT_INFO(" %s->%s",key,data);
86 * \brief Returns the route between two workstations
88 * Use SD_route_get_size() to know the array size.
90 * \param src a workstation
91 * \param dst another workstation
92 * \return a new array of \ref SD_link_t representing the route between these two workstations
93 * \see SD_route_get_size(), SD_link_t
95 double sg_host_speed(sg_host_t workstation)
97 return workstation->speed();
99 int sg_host_core_count(sg_host_t workstation) {
100 return workstation->core_count();
104 double sg_host_computation_time(sg_host_t workstation,
107 xbt_assert(flops_amount >= 0,
108 "flops_amount must be greater than or equal to zero");
109 return flops_amount / workstation->speed();
112 xbt_dict_t sg_host_get_mounted_storage_list(sg_host_t workstation){
113 return workstation->extension<simgrid::surf::Host>()->getMountedStorageList();
116 xbt_dynar_t sg_host_get_attached_storage_list(sg_host_t workstation){
117 return surf_host_get_attached_storage_list(workstation);
120 const SD_link_t *SD_route_get_list(sg_host_t src,
123 xbt_dynar_t surf_route;
127 if (sd_global->recyclable_route == NULL) {
129 sd_global->recyclable_route = xbt_new(SD_link_t, sg_link_count());
132 surf_route = surf_host_model_get_route((surf_host_model_t)surf_host_model, src, dst);
134 xbt_dynar_foreach(surf_route, cpt, surf_link) {
135 sd_global->recyclable_route[cpt] = (SD_link_t)surf_link;
137 return sd_global->recyclable_route;
141 * \brief Returns the number of links on the route between two workstations
143 * \param src a workstation
144 * \param dst another workstation
145 * \return the number of links on the route between these two workstations
146 * \see SD_route_get_list()
148 int SD_route_get_size(sg_host_t src, sg_host_t dst)
150 return xbt_dynar_length(surf_host_model_get_route(
151 (surf_host_model_t)surf_host_model, src, dst));
155 * \brief Returns the total speed of a workstation
157 * \param workstation a workstation
158 * \return the total speed of this workstation
159 * \see sg_host_get_available_speed()
162 * \brief Returns the amount of cores of a workstation
164 * \param workstation a workstation
165 * \return the amount of cores of this workstation
168 * \brief Returns an approximative estimated time for the given computation amount on a workstation
170 * \param workstation a workstation
171 * \param flops_amount the computation amount you want to evaluate (in flops)
172 * \return an approximative estimated computation time for the given computation amount on this workstation (in seconds)
175 * \brief Returns the latency of the route between two workstations.
177 * \param src the first workstation
178 * \param dst the second workstation
179 * \return the latency of the route between the two workstations (in seconds)
180 * \see SD_route_get_bandwidth()
182 double SD_route_get_latency(sg_host_t src, sg_host_t dst)
184 xbt_dynar_t route = NULL;
187 routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard,
194 * \brief Returns the bandwidth of the route between two workstations,
195 * i.e. the minimum link bandwidth of all between the workstations.
197 * \param src the first workstation
198 * \param dst the second workstation
199 * \return the bandwidth of the route between the two workstations
201 * \see SD_route_get_latency()
203 double SD_route_get_bandwidth(sg_host_t src, sg_host_t dst)
206 const SD_link_t *links;
209 double min_bandwidth;
212 links = SD_route_get_list(src, dst);
213 nb_links = SD_route_get_size(src, dst);
214 min_bandwidth = -1.0;
216 for (i = 0; i < nb_links; i++) {
217 bandwidth = sg_link_bandwidth(links[i]);
218 if (bandwidth < min_bandwidth || min_bandwidth == -1.0)
219 min_bandwidth = bandwidth;
222 return min_bandwidth;
226 * \brief Returns an approximative estimated time for the given
227 * communication amount between two workstations
229 * \param src the first workstation
230 * \param dst the second workstation
231 * \param bytes_amount the communication amount you want to evaluate (in bytes)
232 * \return an approximative estimated communication time for the given bytes amount
233 * between the workstations (in seconds)
235 double SD_route_get_communication_time(sg_host_t src,
241 /* total time = latency + transmission time of the slowest link
242 transmission time of a link = communication amount / link bandwidth */
244 const SD_link_t *links;
245 xbt_dynar_t route = NULL;
247 double bandwidth, min_bandwidth;
251 xbt_assert(bytes_amount >= 0, "bytes_amount must be greater than or equal to zero");
254 if (bytes_amount == 0.0)
257 routing_platf->getRouteAndLatency(src->pimpl_netcard, dst->pimpl_netcard,
260 links = SD_route_get_list(src, dst);
261 nb_links = SD_route_get_size(src, dst);
262 min_bandwidth = -1.0;
264 for (i = 0; i < nb_links; i++) {
265 bandwidth = sg_link_bandwidth(links[i]);
266 if (bandwidth < min_bandwidth || min_bandwidth == -1.0)
267 min_bandwidth = bandwidth;
270 return latency + (bytes_amount / min_bandwidth);
274 * \brief Return the list of mounted storages on a workstation.
276 * \param workstation a workstation
277 * \return a dynar containing all mounted storages on the workstation
280 * \brief Return the list of mounted storages on a workstation.
282 * \param workstation a workstation
283 * \return a dynar containing all mounted storages on the workstation
286 * \brief Returns the host name the storage is attached to
288 * This functions checks whether a storage is a valid pointer or not and return its name.
290 const char *SD_storage_get_host(msg_storage_t storage) {
291 xbt_assert((storage != NULL), "Invalid parameters");
292 SD_storage_priv_t priv = SD_storage_priv(storage);