A
lgorithmique
N
umérique
D
istribuée
Public GIT Repository
projects
/
simgrid.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Exposing a pointer to internals is not considered as good OOP practices
[simgrid.git]
/
src
/
surf
/
surf_routing_dijkstra.cpp
diff --git
a/src/surf/surf_routing_dijkstra.cpp
b/src/surf/surf_routing_dijkstra.cpp
index
ec006a6
..
c5a59fa
100644
(file)
--- a/
src/surf/surf_routing_dijkstra.cpp
+++ b/
src/surf/surf_routing_dijkstra.cpp
@@
-201,33
+201,22
@@
void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c
/* set utils vars */
srcDstCheck(src, dst);
/* set utils vars */
srcDstCheck(src, dst);
- int *src_id = src->getIdPtr();
- int *dst_id = dst->getIdPtr();
-
- if (!src_id || !dst_id)
- THROWF(arg_error,0,"No route from '%s' to '%s'",src->getName(),dst->getName());
+ int src_id = src->id();
+ int dst_id = dst->id();
int *pred_arr = NULL;
int *pred_arr = NULL;
- int src_node_id = 0;
- int dst_node_id = 0;
- int *nodeid = NULL;
- int v;
sg_platf_route_cbarg_t e_route;
int size = 0;
unsigned int cpt;
void *link;
sg_platf_route_cbarg_t e_route;
int size = 0;
unsigned int cpt;
void *link;
- xbt_dynar_t links = NULL;
- route_cache_element_t elm = NULL;
xbt_dynar_t nodes = xbt_graph_get_nodes(p_routeGraph);
/* Use the graph_node id mapping set to quickly find the nodes */
xbt_dynar_t nodes = xbt_graph_get_nodes(p_routeGraph);
/* Use the graph_node id mapping set to quickly find the nodes */
- graph_node_map_element_t src_elm = nodeMapSearch(
*
src_id);
- graph_node_map_element_t dst_elm = nodeMapSearch(
*
dst_id);
+ graph_node_map_element_t src_elm = nodeMapSearch(src_id);
+ graph_node_map_element_t dst_elm = nodeMapSearch(dst_id);
- src_node_id = ((graph_node_data_t)
- xbt_graph_node_get_data(src_elm->node))->graph_id;
- dst_node_id = ((graph_node_data_t)
- xbt_graph_node_get_data(dst_elm->node))->graph_id;
+ int src_node_id = ((graph_node_data_t) xbt_graph_node_get_data(src_elm->node))->graph_id;
+ int dst_node_id = ((graph_node_data_t) xbt_graph_node_get_data(dst_elm->node))->graph_id;
/* if the src and dst are the same */
if (src_node_id == dst_node_id) {
/* if the src and dst are the same */
if (src_node_id == dst_node_id) {
@@
-237,12
+226,11
@@
void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c
xbt_edge_t edge = xbt_graph_get_edge(p_routeGraph, node_s_v, node_e_v);
if (edge == NULL)
xbt_edge_t edge = xbt_graph_get_edge(p_routeGraph, node_s_v, node_e_v);
if (edge == NULL)
- THROWF(arg_error, 0, "No route from '%s' to '%s'", src->
getName(), dst->getN
ame());
+ THROWF(arg_error, 0, "No route from '%s' to '%s'", src->
name(), dst->n
ame());
e_route = (sg_platf_route_cbarg_t) xbt_graph_edge_get_data(edge);
e_route = (sg_platf_route_cbarg_t) xbt_graph_edge_get_data(edge);
- links = e_route->link_list;
- xbt_dynar_foreach(links, cpt, link) {
+ xbt_dynar_foreach(e_route->link_list, cpt, link) {
xbt_dynar_unshift(route->link_list, &link);
if (lat)
*lat += static_cast<Link*>(link)->getLatency();
xbt_dynar_unshift(route->link_list, &link);
if (lat)
*lat += static_cast<Link*>(link)->getLatency();
@@
-250,29
+238,25
@@
void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c
}
}
- if (m_cached) {
-
/*check if there is a cached predecessor list avail
*/
+ route_cache_element_t elm = NULL;
+
if (m_cached) { /* cache mode
*/
elm = (route_cache_element_t)
elm = (route_cache_element_t)
- xbt_dict_get_or_null_ext(p_routeCache, (char *) (&src_id),
- sizeof(int));
+ xbt_dict_get_or_null_ext(p_routeCache, (char *) (&src_id), sizeof(int));
}
if (elm) { /* cached mode and cache hit */
pred_arr = elm->pred_arr;
}
if (elm) { /* cached mode and cache hit */
pred_arr = elm->pred_arr;
- } else { /* not cached mode or cache miss */
- double *cost_arr = NULL;
- xbt_heap_t pqueue = NULL;
- int i = 0;
+ } else { /* not cached mode, or cache miss */
int nr_nodes = xbt_dynar_length(nodes);
int nr_nodes = xbt_dynar_length(nodes);
- cost_arr = xbt_new0(double, nr_nodes); /* link cost from src to other hosts */
+
double *
cost_arr = xbt_new0(double, nr_nodes); /* link cost from src to other hosts */
pred_arr = xbt_new0(int, nr_nodes); /* predecessors in path from src */
pred_arr = xbt_new0(int, nr_nodes); /* predecessors in path from src */
- pqueue = xbt_heap_new(nr_nodes, xbt_free_f);
+
xbt_heap_t
pqueue = xbt_heap_new(nr_nodes, xbt_free_f);
/* initialize */
cost_arr[src_node_id] = 0.0;
/* initialize */
cost_arr[src_node_id] = 0.0;
- for (i = 0; i < nr_nodes; i++) {
+ for (i
nt i
= 0; i < nr_nodes; i++) {
if (i != src_node_id) {
cost_arr[i] = DBL_MAX;
}
if (i != src_node_id) {
cost_arr[i] = DBL_MAX;
}
@@
-280,7
+264,7
@@
void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c
pred_arr[i] = 0;
/* initialize priority queue */
pred_arr[i] = 0;
/* initialize priority queue */
- nodeid = xbt_new0(int, 1);
+
int *
nodeid = xbt_new0(int, 1);
*nodeid = i;
xbt_heap_push(pqueue, nodeid, cost_arr[i]);
*nodeid = i;
xbt_heap_push(pqueue, nodeid, cost_arr[i]);
@@
-290,11
+274,10
@@
void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c
while (xbt_heap_size(pqueue) > 0) {
int *v_id = (int *) xbt_heap_pop(pqueue);
xbt_node_t v_node = xbt_dynar_get_as(nodes, *v_id, xbt_node_t);
while (xbt_heap_size(pqueue) > 0) {
int *v_id = (int *) xbt_heap_pop(pqueue);
xbt_node_t v_node = xbt_dynar_get_as(nodes, *v_id, xbt_node_t);
- xbt_dynar_t out_edges = xbt_graph_node_get_outedges(v_node);
xbt_edge_t edge = NULL;
unsigned int cursor;
xbt_edge_t edge = NULL;
unsigned int cursor;
- xbt_dynar_foreach(
out_edges
, cursor, edge) {
+ xbt_dynar_foreach(
xbt_graph_node_get_outedges(v_node)
, cursor, edge) {
xbt_node_t u_node = xbt_graph_edge_get_target(edge);
graph_node_data_t data = (graph_node_data_t) xbt_graph_node_get_data(u_node);
int u_id = data->graph_id;
xbt_node_t u_node = xbt_graph_edge_get_target(edge);
graph_node_data_t data = (graph_node_data_t) xbt_graph_node_get_data(u_node);
int u_id = data->graph_id;
@@
-304,7
+287,7
@@
void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c
if (cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) {
pred_arr[u_id] = *v_id;
cost_arr[u_id] = cost_v_u + cost_arr[*v_id];
if (cost_v_u + cost_arr[*v_id] < cost_arr[u_id]) {
pred_arr[u_id] = *v_id;
cost_arr[u_id] = cost_v_u + cost_arr[*v_id];
- nodeid = xbt_new0(int, 1);
+
int *
nodeid = xbt_new0(int, 1);
*nodeid = u_id;
xbt_heap_push(pqueue, nodeid, cost_arr[u_id]);
}
*nodeid = u_id;
xbt_heap_push(pqueue, nodeid, cost_arr[u_id]);
}
@@
-322,15
+305,13
@@
void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c
NetCard *gw_src = NULL, *gw_dst, *prev_gw_src, *first_gw = NULL;
NetCard *gw_dst_net_elm = NULL, *prev_gw_src_net_elm = NULL;
NetCard *gw_src = NULL, *gw_dst, *prev_gw_src, *first_gw = NULL;
NetCard *gw_dst_net_elm = NULL, *prev_gw_src_net_elm = NULL;
- for (v = dst_node_id; v != src_node_id; v = pred_arr[v]) {
- xbt_node_t node_pred_v =
- xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t);
+ for (int v = dst_node_id; v != src_node_id; v = pred_arr[v]) {
+ xbt_node_t node_pred_v = xbt_dynar_get_as(nodes, pred_arr[v], xbt_node_t);
xbt_node_t node_v = xbt_dynar_get_as(nodes, v, xbt_node_t);
xbt_node_t node_v = xbt_dynar_get_as(nodes, v, xbt_node_t);
- xbt_edge_t edge =
- xbt_graph_get_edge(p_routeGraph, node_pred_v, node_v);
+ xbt_edge_t edge = xbt_graph_get_edge(p_routeGraph, node_pred_v, node_v);
if (edge == NULL)
if (edge == NULL)
- THROWF(arg_error, 0, "No route from '%s' to '%s'", src->
getName(), dst->getN
ame());
+ THROWF(arg_error, 0, "No route from '%s' to '%s'", src->
name(), dst->n
ame());
prev_gw_src = gw_src;
prev_gw_src = gw_src;
@@
-342,15
+323,14
@@
void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c
first_gw = gw_dst;
if (hierarchy_ == SURF_ROUTING_RECURSIVE && v != dst_node_id
first_gw = gw_dst;
if (hierarchy_ == SURF_ROUTING_RECURSIVE && v != dst_node_id
- && strcmp(gw_dst->
getName(), prev_gw_src->getN
ame())) {
+ && strcmp(gw_dst->
name(), prev_gw_src->n
ame())) {
xbt_dynar_t e_route_as_to_as=NULL;
routing_platf->getRouteAndLatency(gw_dst_net_elm, prev_gw_src_net_elm, &e_route_as_to_as, NULL);
if (edge == NULL)
xbt_dynar_t e_route_as_to_as=NULL;
routing_platf->getRouteAndLatency(gw_dst_net_elm, prev_gw_src_net_elm, &e_route_as_to_as, NULL);
if (edge == NULL)
- THROWF(arg_error,0,"No route from '%s' to '%s'", src->getName(), dst->getName());
- links = e_route_as_to_as;
+ THROWF(arg_error,0,"No route from '%s' to '%s'", src->name(), dst->name());
int pos = 0;
int pos = 0;
- xbt_dynar_foreach(
link
s, cpt, link) {
+ xbt_dynar_foreach(
e_route_as_to_a
s, cpt, link) {
xbt_dynar_insert_at(route->link_list, pos, &link);
if (lat)
*lat += static_cast<Link*>(link)->getLatency();
xbt_dynar_insert_at(route->link_list, pos, &link);
if (lat)
*lat += static_cast<Link*>(link)->getLatency();
@@
-358,8
+338,7
@@
void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c
}
}
}
}
- links = e_route->link_list;
- xbt_dynar_foreach(links, cpt, link) {
+ xbt_dynar_foreach(e_route->link_list, cpt, link) {
xbt_dynar_unshift(route->link_list, &link);
if (lat)
*lat += static_cast<Link*>(link)->getLatency();
xbt_dynar_unshift(route->link_list, &link);
if (lat)
*lat += static_cast<Link*>(link)->getLatency();
@@
-377,8
+356,7
@@
void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c
elm = xbt_new0(struct route_cache_element, 1);
elm->pred_arr = pred_arr;
elm->size = size;
elm = xbt_new0(struct route_cache_element, 1);
elm->pred_arr = pred_arr;
elm->size = size;
- xbt_dict_set_ext(p_routeCache, (char *) (&src_id), sizeof(int),
- (xbt_dictelm_t) elm, NULL);
+ xbt_dict_set_ext(p_routeCache, (char *) (&src_id), sizeof(int), (xbt_dictelm_t) elm, NULL);
}
if (!m_cached)
}
if (!m_cached)
@@
-387,11
+365,9
@@
void AsDijkstra::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_c
AsDijkstra::~AsDijkstra()
{
AsDijkstra::~AsDijkstra()
{
- xbt_graph_free_graph(p_routeGraph, &xbt_free_f,
- &graph_edge_data_free, &xbt_free_f);
+ xbt_graph_free_graph(p_routeGraph, &xbt_free_f, &graph_edge_data_free, &xbt_free_f);
xbt_dict_free(&p_graphNodeMap);
xbt_dict_free(&p_graphNodeMap);
- if (m_cached)
- xbt_dict_free(&p_routeCache);
+ xbt_dict_free(&p_routeCache);
}
/* Creation routing model functions */
}
/* Creation routing model functions */
@@
-444,12
+420,12
@@
void AsDijkstra::parseRoute(sg_platf_route_cbarg_t route)
XBT_DEBUG("Load Route from \"%s\" to \"%s\"", src, dst);
else{
XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
XBT_DEBUG("Load Route from \"%s\" to \"%s\"", src, dst);
else{
XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", src,
- route->gw_src->
getName(), dst, route->gw_dst->getN
ame());
+ route->gw_src->
name(), dst, route->gw_dst->n
ame());
as_route = 1;
if(route->gw_dst->getRcType() == SURF_NETWORK_ELEMENT_NULL)
as_route = 1;
if(route->gw_dst->getRcType() == SURF_NETWORK_ELEMENT_NULL)
- surf_parse_error("The gw_dst '%s' does not exist!",route->gw_dst->
getN
ame());
+ surf_parse_error("The gw_dst '%s' does not exist!",route->gw_dst->
n
ame());
if(route->gw_src->getRcType() == SURF_NETWORK_ELEMENT_NULL)
if(route->gw_src->getRcType() == SURF_NETWORK_ELEMENT_NULL)
- surf_parse_error("The gw_src '%s' does not exist!",route->gw_src->
getN
ame());
+ surf_parse_error("The gw_src '%s' does not exist!",route->gw_src->
n
ame());
}
NetCard *src_net_elm, *dst_net_elm;
}
NetCard *src_net_elm, *dst_net_elm;
@@
-470,7
+446,7
@@
void AsDijkstra::parseRoute(sg_platf_route_cbarg_t route)
p_routeCache = xbt_dict_new_homogeneous(&route_cache_elem_free);
sg_platf_route_cbarg_t e_route = newExtendedRoute(hierarchy_, route, 1);
p_routeCache = xbt_dict_new_homogeneous(&route_cache_elem_free);
sg_platf_route_cbarg_t e_route = newExtendedRoute(hierarchy_, route, 1);
- newRoute(src_net_elm->
getId(), dst_net_elm->getI
d(), e_route);
+ newRoute(src_net_elm->
id(), dst_net_elm->i
d(), e_route);
// Symmetrical YES
if ( (route->symmetrical == TRUE && as_route == 0)
// Symmetrical YES
if ( (route->symmetrical == TRUE && as_route == 0)
@@
-481,11
+457,11
@@
void AsDijkstra::parseRoute(sg_platf_route_cbarg_t route)
XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dst, src);
else
XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
XBT_DEBUG("Load Route from \"%s\" to \"%s\"", dst, src);
else
XBT_DEBUG("Load ASroute from \"%s(%s)\" to \"%s(%s)\"", dst,
- route->gw_dst->
getName(), src, route->gw_src->getN
ame());
+ route->gw_dst->
name(), src, route->gw_src->n
ame());
xbt_dynar_t nodes = xbt_graph_get_nodes(p_routeGraph);
xbt_dynar_t nodes = xbt_graph_get_nodes(p_routeGraph);
- xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_net_elm->
getI
d(), xbt_node_t);
- xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_net_elm->
getI
d(), xbt_node_t);
+ xbt_node_t node_s_v = xbt_dynar_get_as(nodes, src_net_elm->
i
d(), xbt_node_t);
+ xbt_node_t node_e_v = xbt_dynar_get_as(nodes, dst_net_elm->
i
d(), xbt_node_t);
xbt_edge_t edge =
xbt_graph_get_edge(p_routeGraph, node_e_v, node_s_v);
xbt_edge_t edge =
xbt_graph_get_edge(p_routeGraph, node_e_v, node_s_v);
@@
-499,7
+475,7
@@
void AsDijkstra::parseRoute(sg_platf_route_cbarg_t route)
route->gw_dst = gw_tmp;
}
sg_platf_route_cbarg_t link_route_back = newExtendedRoute(hierarchy_, route, 0);
route->gw_dst = gw_tmp;
}
sg_platf_route_cbarg_t link_route_back = newExtendedRoute(hierarchy_, route, 0);
- newRoute(dst_net_elm->
getId(), src_net_elm->getI
d(), link_route_back);
+ newRoute(dst_net_elm->
id(), src_net_elm->i
d(), link_route_back);
}
xbt_dynar_free(&route->link_list);
}
}
xbt_dynar_free(&route->link_list);
}