Skip to content

Commit

Permalink
refactor: rename scalable_vector to ScalableVector
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielSeemaier committed Apr 29, 2024
1 parent 0f47460 commit 333af93
Show file tree
Hide file tree
Showing 22 changed files with 52 additions and 55 deletions.
2 changes: 1 addition & 1 deletion kaminpar-common/datastructures/binary_heap.h
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ template <typename Key, template <typename> typename Comparator> class SharedBin
}

ID _capacity;
scalable_vector<HeapElement> _heap;
ScalableVector<HeapElement> _heap;
std::size_t *_id_pos;
Comparator<Key> _comparator{};
};
Expand Down
6 changes: 3 additions & 3 deletions kaminpar-common/datastructures/fast_reset_array.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ template <typename Value, typename Size = std::size_t> class FastResetArray {
return _data[pos] != Value();
}

[[nodiscard]] scalable_vector<size_type> &used_entry_ids() {
[[nodiscard]] ScalableVector<size_type> &used_entry_ids() {
return _used_entries;
}

Expand Down Expand Up @@ -116,8 +116,8 @@ template <typename Value, typename Size = std::size_t> class FastResetArray {
}

private:
scalable_vector<value_type> _data;
scalable_vector<size_type> _used_entries{};
ScalableVector<value_type> _data;
ScalableVector<size_type> _used_entries{};

IF_HEAP_PROFILING(heap_profiler::DataStructure *_struct);
};
Expand Down
8 changes: 2 additions & 6 deletions kaminpar-common/datastructures/scalable_vector.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,8 @@

namespace kaminpar {
#ifdef KAMINPAR_ENABLE_HEAP_PROFILING
// @deprecated
template <typename T> using scalable_vector = std::vector<T>;
template <typename T> using ScalableVector = std::vector<T>;
#else
// @deprecated
template <typename T> using scalable_vector = std::vector<T, tbb::scalable_allocator<T>>;
template <typename T> using ScalableVector = std::vector<T, tbb::scalable_allocator<T>>;
#endif

template <typename T> using ScalableVector = scalable_vector<T>;
} // namespace kaminpar
2 changes: 1 addition & 1 deletion kaminpar-dist/coarsening/coarsener.cc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ const DistributedGraph *Coarsener::coarsen_once_local(const GlobalNodeWeight max
return graph;
}

scalable_vector<parallel::Atomic<NodeID>> legacy_clustering(clustering.begin(), clustering.end());
ScalableVector<parallel::Atomic<NodeID>> legacy_clustering(clustering.begin(), clustering.end());
auto [c_graph, mapping, m_ctx] = contract_local_clustering(*graph, legacy_clustering);
KASSERT(debug::validate_graph(c_graph), "", assert::heavy);
DBG << "Reduced number of nodes from " << graph->global_n() << " to " << c_graph.global_n();
Expand Down
2 changes: 1 addition & 1 deletion kaminpar-dist/coarsening/coarsener.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Coarsener {
std::vector<DistributedGraph> _graph_hierarchy;
std::vector<GlobalMapping> _global_mapping_hierarchy; //< produced by global clustering algorithm
std::vector<MigratedNodes> _node_migration_history;
std::vector<scalable_vector<NodeID>>
std::vector<ScalableVector<NodeID>>
_local_mapping_hierarchy; //< produced by local clustering_algorithm

bool _local_clustering_converged = false;
Expand Down
9 changes: 4 additions & 5 deletions kaminpar-dist/coarsening/contraction/cluster_contraction.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1044,7 +1044,7 @@ ContractionResult contract_clustering(
);

// @bug not all entries are used, why?
std::vector<scalable_vector<GlobalNodeID>> my_mapping_requests(size);
std::vector<ScalableVector<GlobalNodeID>> my_mapping_requests(size);
tbb::parallel_for<PEID>(0, size, [&](const PEID pe) {
my_mapping_requests[pe].resize(next_index_for_pe[pe].value, kInvalidGlobalNodeID);
});
Expand All @@ -1067,7 +1067,7 @@ ContractionResult contract_clustering(
auto their_mapping_requests =
mpi::sparse_alltoall_get<GlobalNodeID>(my_mapping_requests, graph.communicator());

std::vector<scalable_vector<GlobalNodeID>> my_mapping_responses(size);
std::vector<ScalableVector<GlobalNodeID>> my_mapping_responses(size);
tbb::parallel_for<PEID>(0, size, [&](const PEID pe) {
my_mapping_responses[pe].resize(their_mapping_requests[pe].size());

Expand Down Expand Up @@ -1185,7 +1185,7 @@ ContractionResult contract_clustering(
EdgeWeight weight;
};

NavigableLinkedList<NodeID, LocalEdge, scalable_vector> edge_buffer_ets;
NavigableLinkedList<NodeID, LocalEdge, ScalableVector> edge_buffer_ets;

START_TIMER("Construct edges");
tbb::parallel_for(tbb::blocked_range<NodeID>(0, c_n), [&](const auto &r) {
Expand Down Expand Up @@ -1320,8 +1320,7 @@ ContractionResult contract_clustering(
// Finally, build coarse graph
START_TIMER("Construct coarse graph");
auto all_buffered_nodes =
ts_navigable_list::combine<NodeID, LocalEdge, scalable_vector, scalable_vector>(
edge_buffer_ets
ts_navigable_list::combine<NodeID, LocalEdge, ScalableVector, ScalableVector>(edge_buffer_ets
);

tbb::parallel_for<NodeID>(0, c_n, [&](const NodeID i) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ SET_DEBUG(false);

Result contract_local_clustering(
const DistributedGraph &graph,
const scalable_vector<parallel::Atomic<NodeID>> &clustering,
const ScalableVector<parallel::Atomic<NodeID>> &clustering,
MemoryContext m_ctx
) {
KASSERT(clustering.size() >= graph.n());
Expand All @@ -40,7 +40,7 @@ Result contract_local_clustering(
auto &leader_mapping = m_ctx.leader_mapping;
auto &all_buffered_nodes = m_ctx.all_buffered_nodes;

scalable_vector<NodeID> mapping(graph.total_n());
ScalableVector<NodeID> mapping(graph.total_n());
if (leader_mapping.size() < graph.n()) {
leader_mapping.resize(graph.n());
}
Expand Down Expand Up @@ -170,7 +170,7 @@ Result contract_local_clustering(
tbb::enumerable_thread_specific<Map> collector_ets{[&] {
return Map(ghost_mapper.next_ghost_node());
}};
NavigableLinkedList<NodeID, Edge, scalable_vector> edge_buffer_ets;
NavigableLinkedList<NodeID, Edge, ScalableVector> edge_buffer_ets;

tbb::parallel_for(tbb::blocked_range<NodeID>(0, c_n), [&](const auto &r) {
auto &local_collector = collector_ets.local();
Expand Down Expand Up @@ -228,7 +228,7 @@ Result contract_local_clustering(
//
// Construct rest of the coarse graph: edges, edge weights
//
all_buffered_nodes = ts_navigable_list::combine<NodeID, Edge, scalable_vector>(
all_buffered_nodes = ts_navigable_list::combine<NodeID, Edge, ScalableVector>(
edge_buffer_ets, std::move(all_buffered_nodes)
);

Expand Down
12 changes: 6 additions & 6 deletions kaminpar-dist/coarsening/contraction/local_cluster_contraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,22 @@ struct Edge {
};

struct MemoryContext {
scalable_vector<NodeID> buckets;
scalable_vector<parallel::Atomic<NodeID>> buckets_index;
scalable_vector<parallel::Atomic<NodeID>> leader_mapping;
StaticArray<NavigationMarker<NodeID, Edge, scalable_vector>> all_buffered_nodes;
ScalableVector<NodeID> buckets;
ScalableVector<parallel::Atomic<NodeID>> buckets_index;
ScalableVector<parallel::Atomic<NodeID>> leader_mapping;
StaticArray<NavigationMarker<NodeID, Edge, ScalableVector>> all_buffered_nodes;
};

struct Result {
DistributedGraph graph;
scalable_vector<NodeID> mapping;
ScalableVector<NodeID> mapping;
MemoryContext m_ctx;
};
} // namespace contraction

contraction::Result contract_local_clustering(
const DistributedGraph &graph,
const scalable_vector<parallel::Atomic<NodeID>> &clustering,
const ScalableVector<parallel::Atomic<NodeID>> &clustering,
contraction::MemoryContext m_ctx = {}
);
} // namespace kaminpar::dist
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ void DistributedPartitionedGraph::init_block_weights() {
});
auto local_block_weights = local_block_weights_ets.combine(std::plus{});

scalable_vector<BlockWeight> global_block_weights_nonatomic(k());
ScalableVector<BlockWeight> global_block_weights_nonatomic(k());
mpi::allreduce(
local_block_weights.data(),
global_block_weights_nonatomic.data(),
Expand Down
8 changes: 4 additions & 4 deletions kaminpar-dist/distributed_label_propagation.h
Original file line number Diff line number Diff line change
Expand Up @@ -830,12 +830,12 @@ template <typename Derived, typename Config> class LabelPropagation {
//! Flags nodes with at least one node in its neighborhood that changed
//! clusters during the last iteration. Nodes without this flag set must not
//! be considered in the next iteration.
scalable_vector<parallel::Atomic<uint8_t>> _active;
ScalableVector<parallel::Atomic<uint8_t>> _active;

//! If a node cannot join any cluster during an iteration, this vector stores
//! the node's highest rated cluster independent of the maximum cluster
//! weight. This information is used during 2-hop clustering.
scalable_vector<parallel::Atomic<ClusterID>> _favored_clusters;
ScalableVector<parallel::Atomic<ClusterID>> _favored_clusters;

//! If statistics are enabled, this is the sum of the gain of all moves that
//! were performed. If executed single-thread, this should be equal to the
Expand Down Expand Up @@ -1269,7 +1269,7 @@ template <typename NodeID, typename ClusterID> class OwnedClusterVector {
}

private:
scalable_vector<parallel::Atomic<ClusterID>> _clusters;
ScalableVector<parallel::Atomic<ClusterID>> _clusters;
};

template <typename ClusterID, typename ClusterWeight> class OwnedRelaxedClusterWeightVector {
Expand Down Expand Up @@ -1304,6 +1304,6 @@ template <typename ClusterID, typename ClusterWeight> class OwnedRelaxedClusterW
}

private:
scalable_vector<parallel::Atomic<ClusterWeight>> _cluster_weights;
ScalableVector<parallel::Atomic<ClusterWeight>> _cluster_weights;
};
} // namespace kaminpar::dist
6 changes: 3 additions & 3 deletions kaminpar-dist/refinement/lp/lp_refiner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -502,9 +502,9 @@ class LPRefinerImpl final : public ChunkRandomdLabelPropagation<LPRefinerImpl, L
DistributedPartitionedGraph *_p_graph = nullptr;
const PartitionContext *_p_ctx = nullptr;

scalable_vector<BlockID> _next_partition;
scalable_vector<EdgeWeight> _gains;
scalable_vector<parallel::Atomic<BlockWeight>> _block_weights;
ScalableVector<BlockID> _next_partition;
ScalableVector<EdgeWeight> _gains;
ScalableVector<parallel::Atomic<BlockWeight>> _block_weights;

Statistics _statistics;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ std::unique_ptr<CoarseGraph> contract_clustering_buffered(
tbb::enumerable_thread_specific<RatingMap<EdgeWeight, NodeID>> collector{[&] {
return RatingMap<EdgeWeight, NodeID>(c_n);
}};
NavigableLinkedList<NodeID, Edge, scalable_vector> edge_buffer_ets;
NavigableLinkedList<NodeID, Edge, ScalableVector> edge_buffer_ets;

for (const auto [cluster_start, cluster_end] : cluster_chunks) {
tbb::parallel_for(tbb::blocked_range<NodeID>(cluster_start, cluster_end), [&](const auto &r) {
Expand Down
2 changes: 1 addition & 1 deletion kaminpar-shm/coarsening/contraction/cluster_contraction.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct MemoryContext {
StaticArray<NodeID> buckets;
StaticArray<NodeID> buckets_index;
StaticArray<NodeID> leader_mapping;
StaticArray<NavigationMarker<NodeID, Edge, scalable_vector>> all_buffered_nodes;
StaticArray<NavigationMarker<NodeID, Edge, ScalableVector>> all_buffered_nodes;
};
} // namespace contraction

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ std::unique_ptr<CoarseGraph> contract_clustering_buffered_legacy(
// node degrees (3) We copy coarse edges and coarse edge weights from the
// auxiliary arrays to c_edges and c_edge_weights
//
NavigableLinkedList<NodeID, Edge, scalable_vector> edge_buffer_ets;
NavigableLinkedList<NodeID, Edge, ScalableVector> edge_buffer_ets;

START_TIMER("Construct coarse edges");
tbb::parallel_for(tbb::blocked_range<NodeID>(0, c_n), [&](const auto &r) {
Expand Down Expand Up @@ -125,7 +125,7 @@ std::unique_ptr<CoarseGraph> contract_clustering_buffered_legacy(
// Construct rest of the coarse graph: edges, edge weights
//

all_buffered_nodes = ts_navigable_list::combine<NodeID, Edge, scalable_vector>(
all_buffered_nodes = ts_navigable_list::combine<NodeID, Edge, ScalableVector>(
edge_buffer_ets, std::move(all_buffered_nodes)
);

Expand Down
4 changes: 2 additions & 2 deletions kaminpar-shm/datastructures/delta_partitioned_graph.h
Original file line number Diff line number Diff line change
Expand Up @@ -152,15 +152,15 @@ class GenericDeltaPartitionedGraph : public GraphDelegate<Graph> {
std::conditional_t<
compact_block_weight_delta,
DynamicFlatMap<BlockID, BlockWeight>,
scalable_vector<BlockWeight>>
ScalableVector<BlockWeight>>
_block_weights_delta;

// If we need random access to the partition delta, use a hash map. Otherwise,
// we can just store the moves in a vector.
std::conditional_t<
allow_read_after_move,
DynamicFlatMap<NodeID, BlockID>,
scalable_vector<DeltaEntry>>
ScalableVector<DeltaEntry>>
_partition_delta;
};
} // namespace kaminpar::shm
12 changes: 6 additions & 6 deletions kaminpar-shm/graphutils/subgraph_extractor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -194,16 +194,16 @@ SubgraphExtractionResult extract_subgraphs_generic_graph(
StaticArray<NodeID> mapping(p_graph.n());
StaticArray<SubgraphMemoryStartPosition> start_positions(p_graph.k() + 1);
StaticArray<NodeID> bucket_index(p_graph.k());
scalable_vector<shm::Graph> subgraphs(p_graph.k());
ScalableVector<shm::Graph> subgraphs(p_graph.k());
STOP_TIMER();

// count number of nodes and edges in each block
START_TIMER("Count block size");
tbb::enumerable_thread_specific<scalable_vector<NodeID>> tl_num_nodes_in_block{[&] {
return scalable_vector<NodeID>(p_graph.k());
tbb::enumerable_thread_specific<ScalableVector<NodeID>> tl_num_nodes_in_block{[&] {
return ScalableVector<NodeID>(p_graph.k());
}};
tbb::enumerable_thread_specific<scalable_vector<EdgeID>> tl_num_edges_in_block{[&] {
return scalable_vector<EdgeID>(p_graph.k());
tbb::enumerable_thread_specific<ScalableVector<EdgeID>> tl_num_edges_in_block{[&] {
return ScalableVector<EdgeID>(p_graph.k());
}};

tbb::parallel_for(tbb::blocked_range<NodeID>(0, graph.n()), [&](auto &r) {
Expand Down Expand Up @@ -339,7 +339,7 @@ SubgraphExtractionResult extract_subgraphs(

PartitionedGraph copy_subgraph_partitions(
PartitionedGraph p_graph,
const scalable_vector<StaticArray<BlockID>> &p_subgraph_partitions,
const ScalableVector<StaticArray<BlockID>> &p_subgraph_partitions,
const BlockID k_prime,
const BlockID input_k,
const StaticArray<NodeID> &mapping
Expand Down
4 changes: 2 additions & 2 deletions kaminpar-shm/graphutils/subgraph_extractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ struct SubgraphMemory {
};

struct SubgraphExtractionResult {
scalable_vector<Graph> subgraphs;
ScalableVector<Graph> subgraphs;
StaticArray<NodeID> node_mapping;
StaticArray<SubgraphMemoryStartPosition> positions;
};
Expand Down Expand Up @@ -171,7 +171,7 @@ SequentialSubgraphExtractionResult extract_subgraphs_sequential(

PartitionedGraph copy_subgraph_partitions(
PartitionedGraph p_graph,
const scalable_vector<StaticArray<BlockID>> &p_subgraph_partitions,
const ScalableVector<StaticArray<BlockID>> &p_subgraph_partitions,
BlockID k_prime,
BlockID input_k,
const StaticArray<NodeID> &mapping
Expand Down
4 changes: 2 additions & 2 deletions kaminpar-shm/partitioning/deep/async_initial_partitioning.cc
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ PartitionedGraph AsyncInitialPartitioner::split_and_join(

// parallel recursion
tbb::task_group tg;
scalable_vector<PartitionedGraph> p_graphs(num_copies);
scalable_vector<PartitionContext> p_ctx_copies(num_copies, p_ctx);
ScalableVector<PartitionedGraph> p_graphs(num_copies);
ScalableVector<PartitionContext> p_ctx_copies(num_copies, p_ctx);

for (std::size_t copy = 0; copy < num_copies; ++copy) {
tg.run([this,
Expand Down
4 changes: 2 additions & 2 deletions kaminpar-shm/partitioning/helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ void extend_partition(

START_HEAP_PROFILER("Allocation");
START_TIMER("Allocation");
scalable_vector<StaticArray<BlockID>> subgraph_partitions;
ScalableVector<StaticArray<BlockID>> subgraph_partitions;
for (const auto &subgraph : subgraphs) {
subgraph_partitions.emplace_back(subgraph.n());
}
Expand Down Expand Up @@ -328,7 +328,7 @@ std::size_t compute_num_copies(
}

std::size_t
select_best(const scalable_vector<PartitionedGraph> &p_graphs, const PartitionContext &p_ctx) {
select_best(const ScalableVector<PartitionedGraph> &p_graphs, const PartitionContext &p_ctx) {
return select_best(p_graphs.begin(), p_graphs.end(), p_ctx);
}

Expand Down
2 changes: 1 addition & 1 deletion kaminpar-shm/partitioning/helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ std::size_t
compute_num_copies(const Context &input_ctx, NodeID n, bool converged, std::size_t num_threads);

std::size_t
select_best(const scalable_vector<PartitionedGraph> &p_graphs, const PartitionContext &p_ctx);
select_best(const ScalableVector<PartitionedGraph> &p_graphs, const PartitionContext &p_ctx);

template <typename Iterator>
std::size_t select_best(
Expand Down
2 changes: 1 addition & 1 deletion kaminpar-shm/partitioning/rb/rb_multilevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class RBMultilevelPartitioner : public Partitioner {
[&] { p_graph1 = partition_recursive(subgraphs[0], k / 2); },
[&] { p_graph2 = partition_recursive(subgraphs[1], k / 2); }
);
scalable_vector<StaticArray<BlockID>> subgraph_partitions(2);
ScalableVector<StaticArray<BlockID>> subgraph_partitions(2);
subgraph_partitions[0] = p_graph1.take_raw_partition();
subgraph_partitions[1] = p_graph2.take_raw_partition();

Expand Down
2 changes: 2 additions & 0 deletions kaminpar-shm/presets.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include <string>
#include <unordered_set>

#include "kaminpar-shm/context.h"

namespace kaminpar::shm {
Context create_context_by_preset_name(const std::string &name) {
if (name == "default") {
Expand Down

0 comments on commit 333af93

Please sign in to comment.