Skip to content

Commit ef4a3bd

Browse files
committed
revise constructComputationalDag
1 parent ce25be1 commit ef4a3bd

7 files changed

Lines changed: 28 additions & 22 deletions

File tree

include/osp/bsp/model/BspInstance.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class BspInstance {
106106
explicit BspInstance(const BspInstance<Graph_t_other> &other)
107107
: architecture(other.getArchitecture()),
108108
nodeProcessorCompatibility(other.getNodeProcessorCompatibilityMatrix()) {
109-
construct_computational_dag(other.getComputationalDag(), cdag);
109+
constructComputationalDag(other.getComputationalDag(), cdag);
110110
}
111111

112112
BspInstance(const BspInstance<Graph_t> &other) = default;

include/osp/coarser/StepByStep/StepByStepCoarser.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ std::vector<vertex_idx_t<Graph_t>> StepByStepCoarser<Graph_t>::generate_vertex_c
156156
G_coarse.remove_vertex(node);
157157
}
158158

159-
construct_computational_dag(G_full, G_coarse);
159+
constructComputationalDag(G_full, G_coarse);
160160

161161
contractionHistory.clear();
162162

include/osp/graph_algorithms/computational_dag_construction_util.hpp

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -18,46 +18,52 @@ limitations under the License.
1818

1919
#pragma once
2020

21-
#include <numeric>
22-
2321
#include "osp/concepts/computational_dag_concept.hpp"
2422
#include "osp/concepts/constructable_computational_dag_concept.hpp"
25-
#include "directed_graph_top_sort.hpp"
2623

2724
namespace osp {
2825

26+
/**
27+
* @brief Constructs a computational DAG from another graph.
28+
*
29+
* This function copies the structure and properties of a source graph into a target graph structure.
30+
* Assumes that the vertices of the source graph are indexed from 0 to N-1. If the target graph is empty, indices are sequentially assigned starting from 0.
31+
* If the target graph is not empty, new vertices will be added to the target graph and their indices will be sequentially assigned starting from the index N.
32+
*
33+
* @tparam Graph_from The type of the source graph. Must satisfy `is_computational_dag`.
34+
* @tparam Graph_to The type of the target graph. Must satisfy `is_constructable_cdag_vertex`.
35+
* @param from The source graph.
36+
* @param to The target graph.
37+
*/
2938
template<typename Graph_from, typename Graph_to>
30-
bool construct_computational_dag(const Graph_from &from, Graph_to &to) {
31-
39+
void constructComputationalDag(const Graph_from &from, Graph_to &to) {
3240
static_assert(is_computational_dag_v<Graph_from>, "Graph_from must satisfy the computational_dag concept");
3341
static_assert(is_constructable_cdag_vertex_v<Graph_to>, "Graph_to must satisfy the constructable_cdag_vertex concept");
3442

35-
for (const auto &v_idx : from.vertices()) {
43+
std::vector<vertex_idx_t<Graph_to>> vertex_map;
44+
vertex_map.reserve(from.num_vertices());
3645

46+
for (const auto &v_idx : from.vertices()) {
3747
if constexpr (has_typed_vertices_v<Graph_from> and has_typed_vertices_v<Graph_to>) {
38-
to.add_vertex(from.vertex_work_weight(v_idx), from.vertex_comm_weight(v_idx),
39-
from.vertex_mem_weight(v_idx), from.vertex_type(v_idx));
48+
vertex_map.push_back(to.add_vertex(from.vertex_work_weight(v_idx), from.vertex_comm_weight(v_idx),
49+
from.vertex_mem_weight(v_idx), from.vertex_type(v_idx)));
4050
} else {
41-
to.add_vertex(from.vertex_work_weight(v_idx), from.vertex_comm_weight(v_idx),
42-
from.vertex_mem_weight(v_idx));
51+
vertex_map.push_back(to.add_vertex(from.vertex_work_weight(v_idx), from.vertex_comm_weight(v_idx),
52+
from.vertex_mem_weight(v_idx)));
4353
}
4454
}
4555

4656
if constexpr (has_edge_weights_v<Graph_from> and has_edge_weights_v<Graph_to>) {
47-
4857
for (const auto &e : edges(from)) {
49-
to.add_edge(source(e, from), target(e, from), from.edge_comm_weight(e));
58+
to.add_edge(vertex_map.at(source(e, from)), vertex_map.at(target(e, from)), from.edge_comm_weight(e));
5059
}
51-
5260
} else {
5361
for (const auto &v : from.vertices()) {
5462
for (const auto &child : from.children(v)) {
55-
to.add_edge(v, child);
63+
to.add_edge(vertex_map.at(v), vertex_map.at(child));
5664
}
5765
}
5866
}
59-
60-
return true;
6167
}
6268

6369
} // namespace osp

include/osp/graph_implementations/adj_list_impl/computational_dag_edge_idx_vector_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ class computational_dag_edge_idx_vector_impl {
124124

125125
static_assert(is_computational_dag_v<Graph_t>, "Graph_t must satisfy the is_computation_dag concept");
126126

127-
construct_computational_dag(other, *this);
127+
constructComputationalDag(other, *this);
128128
}
129129

130130
computational_dag_edge_idx_vector_impl &operator=(const computational_dag_edge_idx_vector_impl &other) = default;

include/osp/graph_implementations/adj_list_impl/computational_dag_vector_impl.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ class computational_dag_vector_impl {
101101

102102
static_assert(is_computational_dag_v<Graph_t>, "Graph_t must satisfy the is_computation_dag concept");
103103

104-
construct_computational_dag(other, *this);
104+
constructComputationalDag(other, *this);
105105
}
106106

107107
computational_dag_vector_impl(computational_dag_vector_impl &&other) noexcept

include/osp/graph_implementations/adj_list_impl/vector_cast_view.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class vector_cast_view {
141141
* @param i The index of the element to access.
142142
* @return The element at index i, cast to to_t.
143143
*/
144-
[[nodiscard]] auto operator[](std::size_t i) const { return static_cast<to_t>(vec[i]); }
144+
[[nodiscard]] auto operator[](std::size_t i) const { return static_cast<to_t>(vec.at(i)); }
145145
};
146146

147147
} // namespace osp

include/osp/graph_implementations/boost_graphs/boost_graph.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class boost_graph {
208208

209209
graph.m_vertices.reserve(other.num_vertices());
210210

211-
osp::construct_computational_dag(other, *this);
211+
osp::constructComputationalDag(other, *this);
212212
}
213213

214214
inline const boost_graph_impl_t &get_boost_graph() const { return graph; }

0 commit comments

Comments
 (0)