Skip to content

Commit

Permalink
refactor: use more StaticArray
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSeemaier committed Jun 5, 2024
1 parent 25f2c83 commit 03316ca
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 29 deletions.
16 changes: 6 additions & 10 deletions kaminpar-shm/initial_partitioning/initial_coarsener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ InitialCoarsener::ContractionResult InitialCoarsener::contract_current_clusterin
timer::LocalTimer timer;
timer.reset();

ScalableVector<NodeID> node_mapping = _hierarchy.alloc_mapping_memory();
StaticArray<NodeID> node_mapping = _hierarchy.alloc_mapping_memory();
if (node_mapping.size() < _current_graph->n()) {
node_mapping.resize(_current_graph->n());
node_mapping.resize(_current_graph->n(), static_array::seq);
}

CSRGraphMemory c_memory = _hierarchy.alloc_graph_memory();
Expand All @@ -194,10 +194,10 @@ InitialCoarsener::ContractionResult InitialCoarsener::contract_current_clusterin
StaticArray<EdgeWeight> c_edge_weights = std::move(c_memory.edge_weights);

if (c_nodes.size() < c_n + 1) {
c_nodes.resize(c_n + 1, static_array::small, static_array::seq);
c_nodes.resize(c_n + 1, static_array::seq);
}
if (c_node_weights.size() < c_n) {
c_node_weights.resize(c_n, static_array::small, static_array::seq);
c_node_weights.resize(c_n, static_array::seq);
}

// CSRGraph determines the number of nodes based on the size of the c_nodes array:
Expand All @@ -206,14 +206,10 @@ InitialCoarsener::ContractionResult InitialCoarsener::contract_current_clusterin
c_node_weights.restrict(c_n);

if (c_edges.size() < _current_graph->m()) {
c_edges.resize(
_current_graph->m(), static_array::small, static_array::seq, static_array::noinit
);
c_edges.resize(_current_graph->m(), static_array::seq, static_array::noinit);
}
if (c_edge_weights.size() < _current_graph->m()) {
c_edge_weights.resize(
_current_graph->m(), static_array::small, static_array::seq, static_array::noinit
);
c_edge_weights.resize(_current_graph->m(), static_array::seq, static_array::noinit);
}

// Similarly to the c_nodes array, we must restrict the size of the c_edges array: this is
Expand Down
2 changes: 1 addition & 1 deletion kaminpar-shm/initial_partitioning/initial_coarsener.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class InitialCoarsener {
static constexpr std::size_t kChunkSize = 256;
static constexpr std::size_t kNumberOfNodePermutations = 16;

using ContractionResult = std::pair<CSRGraph, ScalableVector<NodeID>>;
using ContractionResult = std::pair<CSRGraph, StaticArray<NodeID>>;

public:
struct Cluster {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,10 @@ void InitialPoolBipartitioner::init(const CSRGraph &graph, const PartitionContex
}

if (_current_partition.size() < _graph->n()) {
_current_partition.resize(_graph->n(), static_array::small, static_array::seq);
_current_partition.resize(_graph->n(), static_array::seq);
}
if (_best_partition.size() < _graph->n()) {
_best_partition.resize(_graph->n(), static_array::small, static_array::seq);
_best_partition.resize(_graph->n(), static_array::seq);
}

reset();
Expand Down
18 changes: 9 additions & 9 deletions kaminpar-shm/initial_partitioning/sequential_graph_hierarchy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void SequentialGraphHierarchy::init(const CSRGraph &graph) {
_coarse_graphs.clear();
}

void SequentialGraphHierarchy::push(CSRGraph &&c_graph, ScalableVector<NodeID> &&c_mapping) {
void SequentialGraphHierarchy::push(CSRGraph &&c_graph, StaticArray<NodeID> &&c_mapping) {
KASSERT(current().n() == c_mapping.size());

_coarse_mappings.push_back(std::move(c_mapping));
Expand All @@ -37,7 +37,7 @@ PartitionedCSRGraph SequentialGraphHierarchy::pop(PartitionedCSRGraph &&coarse_p
KASSERT(&_coarse_graphs.back() == &coarse_p_graph.graph());

// Goal: project partition of p_graph == c_graph onto new_c_graph
ScalableVector<NodeID> c_mapping = std::move(_coarse_mappings.back());
StaticArray<NodeID> c_mapping = std::move(_coarse_mappings.back());
_coarse_mappings.pop_back();

const CSRGraph &graph = get_second_coarsest_graph();
Expand Down Expand Up @@ -79,7 +79,7 @@ void SequentialGraphHierarchy::recover_partition_memory(StaticArray<BlockID> par
_partition_memory_cache.push_back(std::move(partition));
}

void SequentialGraphHierarchy::recover_mapping_memory(ScalableVector<NodeID> mapping) {
void SequentialGraphHierarchy::recover_mapping_memory(StaticArray<NodeID> mapping) {
_mapping_memory_cache.push_back(std::move(mapping));
}

Expand Down Expand Up @@ -107,9 +107,9 @@ StaticArray<BlockID> SequentialGraphHierarchy::alloc_partition_memory() {
return memory;
}

ScalableVector<NodeID> SequentialGraphHierarchy::alloc_mapping_memory() {
StaticArray<NodeID> SequentialGraphHierarchy::alloc_mapping_memory() {
if (_mapping_memory_cache.empty()) {
_mapping_memory_cache.emplace_back();
_mapping_memory_cache.emplace_back(0, static_array::seq);
}

auto memory = std::move(_mapping_memory_cache.back());
Expand All @@ -120,10 +120,10 @@ ScalableVector<NodeID> SequentialGraphHierarchy::alloc_mapping_memory() {
CSRGraphMemory SequentialGraphHierarchy::alloc_graph_memory() {
if (_graph_memory_cache.empty()) {
_graph_memory_cache.push_back(CSRGraphMemory{
StaticArray<EdgeID>{0, static_array::small, static_array::seq},
StaticArray<NodeID>{0, static_array::small, static_array::seq},
StaticArray<NodeWeight>{0, static_array::small, static_array::seq},
StaticArray<EdgeWeight>{0, static_array::small, static_array::seq},
StaticArray<EdgeID>{0, static_array::seq},
StaticArray<NodeID>{0, static_array::seq},
StaticArray<NodeWeight>{0, static_array::seq},
StaticArray<EdgeWeight>{0, static_array::seq},
});
}

Expand Down
10 changes: 5 additions & 5 deletions kaminpar-shm/initial_partitioning/sequential_graph_hierarchy.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class SequentialGraphHierarchy {

void init(const CSRGraph &graph);

void push(CSRGraph &&c_graph, ScalableVector<NodeID> &&c_mapping);
void push(CSRGraph &&c_graph, StaticArray<NodeID> &&c_mapping);

[[nodiscard]] const CSRGraph &current() const;

Expand All @@ -43,23 +43,23 @@ class SequentialGraphHierarchy {
}

StaticArray<BlockID> alloc_partition_memory();
ScalableVector<NodeID> alloc_mapping_memory();
StaticArray<NodeID> alloc_mapping_memory();
CSRGraphMemory alloc_graph_memory();

private:
[[nodiscard]] const CSRGraph &get_second_coarsest_graph() const;

void recover_partition_memory(StaticArray<BlockID> partition);
void recover_mapping_memory(ScalableVector<NodeID> mapping);
void recover_mapping_memory(StaticArray<NodeID> mapping);
void recover_graph_memory(CSRGraph graph);

const CSRGraph *_finest_graph;

ScalableVector<ScalableVector<NodeID>> _coarse_mappings;
ScalableVector<StaticArray<NodeID>> _coarse_mappings;
ScalableVector<CSRGraph> _coarse_graphs;

ScalableVector<CSRGraphMemory> _graph_memory_cache;
ScalableVector<ScalableVector<NodeID>> _mapping_memory_cache;
ScalableVector<StaticArray<NodeID>> _mapping_memory_cache;
ScalableVector<StaticArray<BlockID>> _partition_memory_cache;
};
} // namespace kaminpar::shm
3 changes: 1 addition & 2 deletions kaminpar-shm/partitioning/helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -296,8 +296,7 @@ void extend_partition(
return a += b;
});

constexpr bool kShowTimings = false;
if constexpr (kShowTimings) {
if (true) {
LOG << "bipartitioner_init_ms: "
<< static_cast<std::uint64_t>(timings.bipartitioner_init_ms / 1e6);
LOG << "bipartitioner_ms: " << static_cast<std::uint64_t>(timings.bipartitioner_ms / 1e6);
Expand Down

0 comments on commit 03316ca

Please sign in to comment.