DOLFINx 0.12.0.0
DOLFINx C++
Loading...
Searching...
No Matches
partition.h
1// Copyright (C) 2020-2026 Garth N. Wells
2//
3// This file is part of DOLFINx (https://www.fenicsproject.org)
4//
5// SPDX-License-Identifier: LGPL-3.0-or-later
6
7#pragma once
8
9#include "AdjacencyList.h"
10#include <array>
11#include <cstdint>
12#include <functional>
13#include <mpi.h>
14#include <optional>
15#include <span>
16#include <tuple>
17#include <variant>
18#include <vector>
19
20namespace dolfinx::graph
21{
38using partition_fn = std::function<graph::AdjacencyList<std::int32_t>(
39 MPI_Comm, int, const AdjacencyList<std::int64_t>&,
40 std::optional<std::span<const std::int32_t>>,
41 std::optional<std::span<const std::int32_t>>, bool)>;
42
69using geom_partition_fn = std::function<std::vector<int>(
70 MPI_Comm, int, std::span<const double>, int,
71 std::optional<std::span<const std::int32_t>>)>;
72
102using hybrid_partition_fn = std::function<graph::AdjacencyList<std::int32_t>(
103 MPI_Comm, int, const AdjacencyList<std::int64_t>&, std::span<const double>,
104 std::optional<std::span<const std::int32_t>>,
105 std::optional<std::span<const std::int32_t>>, bool)>;
106
119 = std::variant<partition_fn, geom_partition_fn, hybrid_partition_fn>;
120
126bool has_partitioner(const AnyPartitionFunction& partitioner);
127
145 MPI_Comm comm, int nparts, const AdjacencyList<std::int64_t>& local_graph,
146 std::optional<std::span<const std::int32_t>> node_weights,
147 std::optional<std::span<const std::int32_t>> edge_weights, bool ghosting);
148
155/// for.
156struct Partitioner
157{
161
164 std::optional<std::span<const std::int32_t>> node_weights = std::nullopt;
165};
166
169/// @todo Add a function that sends data to the 'owner'
170namespace build
171{
201std::tuple<graph::AdjacencyList<std::int64_t>, std::vector<int>,
202 std::vector<std::int64_t>, std::vector<int>>
203distribute(MPI_Comm comm, const graph::AdjacencyList<std::int64_t>& list,
204 const graph::AdjacencyList<std::int32_t>& destinations);
205
238std::tuple<std::vector<std::int64_t>, std::vector<int>,
239 std::vector<std::int64_t>, std::vector<int>>
240distribute(MPI_Comm comm, std::span<const std::int64_t> list,
241 std::array<std::size_t, 2> shape,
242 const graph::AdjacencyList<std::int32_t>& destinations);
243
268std::vector<std::int64_t>
269compute_ghost_indices(MPI_Comm comm,
270 std::span<const std::int64_t> owned_indices,
271 std::span<const std::int64_t> ghost_indices,
272 std::span<const int> ghost_owners, int num_threads);
273
284std::vector<std::int64_t>
285compute_local_to_global(std::span<const std::int64_t> global,
286 std::span<const std::int32_t> local);
287
296std::vector<std::int32_t>
297compute_local_to_local(std::span<const std::int64_t> local0_to_global,
298 std::span<const std::int64_t> local1_to_global);
299} // namespace build
300
301} // namespace dolfinx::graph
This class provides a static adjacency list data structure.
Definition AdjacencyList.h:41
Definition partition.h:170
std::vector< std::int64_t > compute_ghost_indices(MPI_Comm comm, std::span< const std::int64_t > owned_indices, std::span< const std::int64_t > ghost_indices, std::span< const int > ghost_owners, int num_threads)
Take a set of distributed input global indices, including ghosts, and determine the new global indice...
Definition partition.cpp:400
std::vector< std::int64_t > compute_local_to_global(std::span< const std::int64_t > global, std::span< const std::int32_t > local)
Definition partition.cpp:573
std::tuple< graph::AdjacencyList< std::int64_t >, std::vector< int >, std::vector< std::int64_t >, std::vector< int > > distribute(MPI_Comm comm, const graph::AdjacencyList< std::int64_t > &list, const graph::AdjacencyList< std::int32_t > &destinations)
Distribute adjacency list nodes to destination ranks.
Definition partition.cpp:157
std::vector< std::int32_t > compute_local_to_local(std::span< const std::int64_t > local0_to_global, std::span< const std::int64_t > local1_to_global)
Compute a local0-to-local1 map from two local-to-global maps with common global indices.
Definition partition.cpp:595
Graph data structures and algorithms.
Definition AdjacencyList.h:23
std::function< std::vector< int >( MPI_Comm, int, std::span< const double >, int, std::optional< std::span< const std::int32_t > >)> geom_partition_fn
Signature of functions for computing the parallel partitioning of a distributed graph from the positi...
Definition partition.h:69
bool has_partitioner(const AnyPartitionFunction &partitioner)
Whether an AnyPartitionFunction holds a callable partitioner.
Definition partition.cpp:130
std::function< graph::AdjacencyList< std::int32_t >( MPI_Comm, int, const AdjacencyList< std::int64_t > &, std::span< const double >, std::optional< std::span< const std::int32_t > >, std::optional< std::span< const std::int32_t > >, bool)> hybrid_partition_fn
Signature of functions for computing the parallel partitioning of a distributed graph using both its ...
Definition partition.h:102
AdjacencyList< std::int32_t > partition_graph(MPI_Comm comm, int nparts, const AdjacencyList< std::int64_t > &local_graph, std::optional< std::span< const std::int32_t > > node_weights, std::optional< std::span< const std::int32_t > > edge_weights, bool ghosting)
Partition graph across processes using the default graph partitioner.
Definition partition.cpp:136
std::function< graph::AdjacencyList< std::int32_t >( MPI_Comm, int, const AdjacencyList< std::int64_t > &, std::optional< std::span< const std::int32_t > >, std::optional< std::span< const std::int32_t > >, bool)> partition_fn
Signature of functions for computing the parallel partitioning of a distributed graph,...
Definition partition.h:38
std::variant< partition_fn, geom_partition_fn, hybrid_partition_fn > AnyPartitionFunction
Any of the three partitioning function shapes that mesh::create_mesh accepts: partition_fn,...
Definition partition.h:118
An AnyPartitionFunction together with the node weights it should be called with, if any.
Definition partition.h:156
std::optional< std::span< const std::int32_t > > node_weights
Definition partition.h:163
AnyPartitionFunction fn
Definition partition.h:159