Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
move the vanilla def of executeParallelTask in HostModel
[simgrid.git] / src / surf / surf_routing_cluster.cpp
1 /* Copyright (c) 2009-2011, 2013-2015. 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 "surf_routing_cluster.hpp"
8 #include "surf_routing_private.hpp"
9
10 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(surf_route_cluster, surf, "Routing part of surf");
11
12 /* This routing is specifically setup to represent clusters, aka homogeneous sets of machines
13  * Note that a router is created, easing the interconnexion with the rest of the world.
14  */
15
16 AS_t model_cluster_create(void)
17 {
18   return new simgrid::surf::AsCluster();
19 }
20
21 namespace simgrid {
22 namespace surf {
23
24 /* Business methods */
25 void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cbarg_t route, double *lat)
26 {
27   s_surf_parsing_link_up_down_t info;
28   XBT_VERB("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
29             src->getName(), src->getId(), dst->getName(), dst->getId());
30
31   if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
32
33     if((src->getId() == dst->getId()) && p_has_loopback  ){
34       info = xbt_dynar_get_as(p_linkUpDownList, src->getId() * p_nb_links_per_node, s_surf_parsing_link_up_down_t);
35       xbt_dynar_push_as(route->link_list, void *, info.link_up);
36       if (lat)
37         *lat += static_cast<Link*>(info.link_up)->getLatency();
38       return;
39     }
40
41
42     if (p_has_limiter){          // limiter for sender
43       info = xbt_dynar_get_as(p_linkUpDownList, src->getId() * p_nb_links_per_node + p_has_loopback, s_surf_parsing_link_up_down_t);
44       xbt_dynar_push_as(route->link_list, void *, info.link_up);
45     }
46
47     info = xbt_dynar_get_as(p_linkUpDownList, src->getId() * p_nb_links_per_node + p_has_loopback + p_has_limiter, s_surf_parsing_link_up_down_t);
48     if (info.link_up) {         // link up
49       xbt_dynar_push_as(route->link_list, void *, info.link_up);
50       if (lat)
51         *lat += static_cast<Link*>(info.link_up)->getLatency();
52     }
53
54   }
55
56   if (p_backbone) {
57     xbt_dynar_push_as(route->link_list, void *,
58       static_cast<simgrid::surf::Resource*>(p_backbone));
59     if (lat)
60       *lat += p_backbone->getLatency();
61   }
62
63   if (dst->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) {    // No specific link for router
64     info = xbt_dynar_get_as(p_linkUpDownList, dst->getId() * p_nb_links_per_node + p_has_loopback + p_has_limiter, s_surf_parsing_link_up_down_t);
65
66     if (info.link_down) {       // link down
67       xbt_dynar_push_as(route->link_list, void *, info.link_down);
68       if (lat)
69         *lat += static_cast<Link*>(info.link_down)->getLatency();
70     }
71     if (p_has_limiter){          // limiter for receiver
72         info = xbt_dynar_get_as(p_linkUpDownList, dst->getId() * p_nb_links_per_node + p_has_loopback, s_surf_parsing_link_up_down_t);
73         xbt_dynar_push_as(route->link_list, void *, info.link_up);
74     }
75   }
76 }
77
78 void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
79 {
80   int isrc;
81   int table_size = xbt_dynar_length(p_indexNetworkElm);
82
83   NetCard *src;
84   xbt_node_t current, previous, backboneNode = NULL, routerNode;
85   s_surf_parsing_link_up_down_t info;
86
87   xbt_assert(p_router,"Malformed cluster. This may be because your platform file is a hypergraph while it must be a graph.");
88
89   /* create the router */
90   char *link_name = p_router->getName();
91   routerNode = new_xbt_graph_node(graph, link_name, nodes);
92
93   if(p_backbone) {
94     const char *link_nameR = p_backbone->getName();
95     backboneNode = new_xbt_graph_node(graph, link_nameR, nodes);
96
97     new_xbt_graph_edge(graph, routerNode, backboneNode, edges);
98   }
99
100   for (isrc = 0; isrc < table_size; isrc++) {
101     src = xbt_dynar_get_as(p_indexNetworkElm, isrc, NetCard*);
102
103     if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) {
104       previous = new_xbt_graph_node(graph, src->getName(), nodes);
105
106       info = xbt_dynar_get_as(p_linkUpDownList, src->getId(), s_surf_parsing_link_up_down_t);
107
108       if (info.link_up) {     // link up
109
110         const char *link_name = static_cast<simgrid::surf::Resource*>(
111           info.link_up)->getName();
112         current = new_xbt_graph_node(graph, link_name, nodes);
113         new_xbt_graph_edge(graph, previous, current, edges);
114
115         if (p_backbone) {
116           new_xbt_graph_edge(graph, current, backboneNode, edges);
117         } else {
118           new_xbt_graph_edge(graph, current, routerNode, edges);
119         }
120
121       }
122
123       if (info.link_down) {    // link down
124         const char *link_name = static_cast<simgrid::surf::Resource*>(
125           info.link_down)->getName();
126         current = new_xbt_graph_node(graph, link_name, nodes);
127         new_xbt_graph_edge(graph, previous, current, edges);
128
129         if (p_backbone) {
130           new_xbt_graph_edge(graph, current, backboneNode, edges);
131         } else {
132           new_xbt_graph_edge(graph, current, routerNode, edges);
133         }
134       }
135     }
136
137   }
138 }
139
140 void AsCluster::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id, int , int position){
141   s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER;
142   s_surf_parsing_link_up_down_t info;
143   char* link_id = bprintf("%s_link_%d", cluster->id, id);
144
145   memset(&link, 0, sizeof(link));
146   link.id = link_id;
147   link.bandwidth = cluster->bw;
148   link.latency = cluster->lat;
149   link.initiallyOn = 1;
150   link.policy = cluster->sharing_policy;
151   sg_platf_new_link(&link);
152
153   if (link.policy == SURF_LINK_FULLDUPLEX) {
154     char *tmp_link = bprintf("%s_UP", link_id);
155     info.link_up = sg_link_by_name(tmp_link);
156     xbt_free(tmp_link);
157     tmp_link = bprintf("%s_DOWN", link_id);
158     info.link_down = sg_link_by_name(tmp_link);
159     xbt_free(tmp_link);
160   } else {
161     info.link_up = sg_link_by_name(link_id);
162     info.link_down = info.link_up;
163   }
164   xbt_dynar_set(p_linkUpDownList, position, &info);
165   xbt_free(link_id);
166 }
167
168 int AsCluster::parsePU(NetCard *elm) {
169   XBT_DEBUG("Load process unit \"%s\"", elm->getName());
170   xbt_dynar_push_as(p_indexNetworkElm, NetCard*, elm);
171   return xbt_dynar_length(p_indexNetworkElm)-1;
172 }
173
174 int AsCluster::parseAS(NetCard *elm) {
175   XBT_DEBUG("Load Autonomous system \"%s\"", elm->getName());
176   xbt_dynar_push_as(p_indexNetworkElm, NetCard*, elm);
177   return xbt_dynar_length(p_indexNetworkElm)-1;
178 }
179
180 }
181 }