Skip to content

Commit 82c972f

Browse files
authored
Revision graph impl (#55)
* split dag_vector_adapter and cast_view move constructor, operator added cdag_vertex_impl.hpp dag vector const const, at at * revise constructComputationalDag
1 parent 7d97b8c commit 82c972f

File tree

11 files changed

+523
-204
lines changed

11 files changed

+523
-204
lines changed

include/osp/auxiliary/io/DotFileWriter.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ class DotFileWriter {
463463
}
464464

465465
write_graph_structure(
466-
os, g2, VertexWriterDuplicateRecompSchedule_DOT<Graph_t>(g2, names, node_to_proc, node_to_superstep));
466+
os, g2, VertexWriterDuplicateRecompSchedule_DOT<graph_t>(g2, names, node_to_proc, node_to_superstep));
467467
}
468468

469469
template<typename Graph_t>

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: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,47 +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");
33-
static_assert(is_constructable_cdag_vertex_v<Graph_to>,
34-
"Graph_to must satisfy the constructable_cdag_vertex concept");
41+
static_assert(is_constructable_cdag_vertex_v<Graph_to>, "Graph_to must satisfy the constructable_cdag_vertex concept");
3542

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

46+
for (const auto &v_idx : from.vertices()) {
3847
if constexpr (has_typed_vertices_v<Graph_from> and has_typed_vertices_v<Graph_to>) {
39-
to.add_vertex(from.vertex_work_weight(v_idx), from.vertex_comm_weight(v_idx),
40-
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)));
4150
} else {
42-
to.add_vertex(from.vertex_work_weight(v_idx), from.vertex_comm_weight(v_idx),
43-
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)));
4453
}
4554
}
4655

4756
if constexpr (has_edge_weights_v<Graph_from> and has_edge_weights_v<Graph_to>) {
48-
4957
for (const auto &e : edges(from)) {
50-
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));
5159
}
52-
5360
} else {
5461
for (const auto &v : from.vertices()) {
5562
for (const auto &child : from.children(v)) {
56-
to.add_edge(v, child);
63+
to.add_edge(vertex_map.at(v), vertex_map.at(child));
5764
}
5865
}
5966
}
60-
61-
return true;
6267
}
6368

6469
} // namespace osp
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
Copyright 2024 Huawei Technologies Co., Ltd.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
16+
@author Toni Boehnlein, Benjamin Lozes, Pal Andras Papp, Raphael S. Steiner
17+
*/
18+
#pragma once
19+
20+
namespace osp {
21+
22+
/**
23+
* @brief Implementation of a computational DAG vertex.
24+
*
25+
* This struct holds the properties of a vertex in a computational DAG, including its ID,
26+
* weights (work, communication, memory), and type.
27+
*
28+
* @tparam vertex_idx_t Type for vertex indices.
29+
* @tparam workw_t Type for work weights.
30+
* @tparam commw_t Type for communication weights.
31+
* @tparam memw_t Type for memory weights.
32+
* @tparam vertex_type_t Type for vertex types.
33+
*/
34+
template<typename vertex_idx_t, typename workw_t, typename commw_t, typename memw_t, typename vertex_type_t>
35+
struct cdag_vertex_impl {
36+
37+
using vertex_idx_type = vertex_idx_t;
38+
using work_weight_type = workw_t;
39+
using comm_weight_type = commw_t;
40+
using mem_weight_type = memw_t;
41+
using cdag_vertex_type_type = vertex_type_t;
42+
43+
cdag_vertex_impl() = default;
44+
45+
cdag_vertex_impl(const cdag_vertex_impl &other) = default;
46+
cdag_vertex_impl(cdag_vertex_impl &&other) noexcept = default;
47+
cdag_vertex_impl &operator=(const cdag_vertex_impl &other) = default;
48+
cdag_vertex_impl &operator=(cdag_vertex_impl &&other) noexcept = default;
49+
50+
/**
51+
* @brief Constructs a vertex with specified properties.
52+
*
53+
* @param vertex_idx_ The unique identifier for the vertex.
54+
* @param work_w The computational work weight.
55+
* @param comm_w The communication weight.
56+
* @param mem_w The memory weight.
57+
* @param vertex_t The type of the vertex.
58+
*/
59+
cdag_vertex_impl(vertex_idx_t vertex_idx_, workw_t work_w, commw_t comm_w, memw_t mem_w,
60+
vertex_type_t vertex_t)
61+
: id(vertex_idx_), work_weight(work_w), comm_weight(comm_w), mem_weight(mem_w),
62+
vertex_type(vertex_t) {}
63+
64+
vertex_idx_t id = 0;
65+
66+
workw_t work_weight = 0;
67+
commw_t comm_weight = 0;
68+
memw_t mem_weight = 0;
69+
70+
vertex_type_t vertex_type = 0;
71+
};
72+
73+
/**
74+
* @brief A vertex implementation with integer weights. Indexed by size_t. Node types are unsigned.
75+
*
76+
* This struct implements a vertex with integer weights for work, communication, and memory.
77+
*/
78+
using cdag_vertex_impl_int = cdag_vertex_impl<size_t, int, int, int, unsigned>;
79+
80+
/**
81+
* @brief A vertex implementation with unsigned weights. Indexed by size_t. Node types are unsigned.
82+
*
83+
* This struct implements a vertex with unsigned weights for work, communication, and memory.
84+
*/
85+
using cdag_vertex_impl_unsigned = cdag_vertex_impl<size_t, unsigned, unsigned, unsigned, unsigned>;
86+
87+
} // namespace osp

include/osp/graph_implementations/adj_list_impl/computational_dag_edge_idx_vector_impl.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ limitations under the License.
1818
#pragma once
1919

2020
#include "osp/auxiliary/hash_util.hpp"
21-
#include "computational_dag_vector_impl.hpp"
21+
#include "cdag_vertex_impl.hpp"
2222
#include "edge_iterator.hpp"
23+
#include "osp/graph_implementations/integral_range.hpp"
2324
#include "osp/graph_algorithms/computational_dag_construction_util.hpp"
2425
#include <vector>
2526

@@ -123,7 +124,7 @@ class computational_dag_edge_idx_vector_impl {
123124

124125
static_assert(is_computational_dag_v<Graph_t>, "Graph_t must satisfy the is_computation_dag concept");
125126

126-
construct_computational_dag(other, *this);
127+
constructComputationalDag(other, *this);
127128
}
128129

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

0 commit comments

Comments
 (0)