int src_id = src->id();
int dst_id = dst->id();
- int* pred_arr = nullptr;
- int size = 0;
xbt_dynar_t nodes = xbt_graph_get_nodes(routeGraph_);
/* Use the graph_node id mapping set to quickly find the nodes */
}
}
- route_cache_element_t elm = nullptr;
- if (not routeCache_.empty()) { /* cache mode */
- auto it = routeCache_.find(src_id);
- elm = (it == routeCache_.end()) ? nullptr : it->second;
- }
-
- if (elm) { /* cached mode and cache hit */
- pred_arr = elm->pred_arr;
- } else { /* not cached mode, or cache miss */
+ auto elm = routeCache_.emplace(src_id, std::vector<int>());
+ std::vector<int>& pred_arr = elm.first->second;
+ if (elm.second) { /* new element was inserted (not cached mode, or cache miss) */
int nr_nodes = xbt_dynar_length(nodes);
- double* cost_arr = new double[nr_nodes]; /* link cost from src to other hosts */
- pred_arr = new int[nr_nodes]; /* predecessors in path from src */
+ std::vector<double> cost_arr(nr_nodes); /* link cost from src to other hosts */
+ pred_arr.resize(nr_nodes); /* predecessors in path from src */
xbt_heap_t pqueue = xbt_heap_new(nr_nodes, nullptr);
/* initialize */
/* free item popped from pqueue */
delete v_id;
}
-
- delete[] cost_arr;
xbt_heap_free(pqueue);
}
if (lat)
*lat += static_cast<surf::LinkImpl*>(link)->latency();
}
- size++;
}
if (hierarchy_ == RoutingMode::recursive) {
route->gw_dst = first_gw;
}
- if (not routeCache_.empty() && elm == nullptr) {
- /* add to predecessor list of the current src-host to cache */
- elm = new s_route_cache_element_t;
- elm->pred_arr = pred_arr;
- elm->size = size;
- routeCache_.insert({src_id, elm});
- }
-
- if (routeCache_.empty())
- delete[] pred_arr;
+ if (not cached_)
+ routeCache_.clear();
}
DijkstraZone::~DijkstraZone()
/* Creation routing model functions */
-DijkstraZone::DijkstraZone(NetZone* father, std::string name, bool cached) : RoutedZone(father, name)
+DijkstraZone::DijkstraZone(NetZone* father, std::string name, bool cached) : RoutedZone(father, name), cached_(cached)
{
}
};
typedef s_graph_node_data_t* graph_node_data_t;
-struct s_route_cache_element_t {
- int* pred_arr;
- int size;
-};
-typedef s_route_cache_element_t* route_cache_element_t;
-
namespace simgrid {
namespace kernel {
namespace routing {
void addRoute(sg_platf_route_cbarg_t route) override;
xbt_graph_t routeGraph_ = nullptr; /* xbt_graph */
- std::map<int, xbt_node_t> graphNodeMap_; /* map */
- std::map<int, route_cache_element_t> routeCache_; /* use in cache mode */
+ std::map<int, xbt_node_t> graphNodeMap_; /* map */
+ bool cached_; /* cache mode */
+ std::map<int, std::vector<int>> routeCache_; /* use in cache mode */
};
}
}
new_zone = new simgrid::kernel::routing::FatTreeZone(current_routing, zone->id);
break;
case A_surfxml_AS_routing_Dijkstra:
- new_zone = new simgrid::kernel::routing::DijkstraZone(current_routing, zone->id, 0);
+ new_zone = new simgrid::kernel::routing::DijkstraZone(current_routing, zone->id, false);
break;
case A_surfxml_AS_routing_DijkstraCache:
- new_zone = new simgrid::kernel::routing::DijkstraZone(current_routing, zone->id, 1);
+ new_zone = new simgrid::kernel::routing::DijkstraZone(current_routing, zone->id, true);
break;
case A_surfxml_AS_routing_Floyd:
new_zone = new simgrid::kernel::routing::FloydZone(current_routing, zone->id);