DOLFINx 0.12.0.0
DOLFINx C++
Loading...
Searching...
No Matches
IndexMap.h
1// Copyright (C) 2015-2024 Chris Richardson, Garth N. Wells and Igor Baratta
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 "MPI.h"
10#include <cstdint>
11#include <memory>
12#include <span>
13#include <tuple>
14#include <utility>
15#include <vector>
16
17namespace dolfinx::common
18{
19// Forward declaration
20class IndexMap;
21
24enum class IndexMapOrder : bool
25{
26 preserve = true,
27 any = false
28};
29
38std::vector<int32_t>
39compute_owned_indices(std::span<const std::int32_t> indices,
40 const IndexMap& map);
41
59std::tuple<std::int64_t, std::vector<std::int32_t>,
60 std::vector<std::vector<std::int64_t>>,
61 std::vector<std::vector<int>>>
63 const std::vector<std::pair<std::reference_wrapper<const IndexMap>, int>>&
64 maps);
65
84std::pair<IndexMap, std::vector<std::int32_t>> create_sub_index_map(
85 const IndexMap& imap, std::span<const std::int32_t> indices,
86 IndexMapOrder order = IndexMapOrder::any, bool allow_owner_change = false);
87
95{
96public:
105 IndexMap(MPI_Comm comm, std::int32_t local_size);
106
135 IndexMap(MPI_Comm comm, std::int32_t local_size,
136 std::span<const std::int64_t> ghosts, std::span<const int> owners,
137 int tag = static_cast<int>(dolfinx::MPI::tag::consensus_nbx));
138
158 IndexMap(MPI_Comm comm, std::int32_t local_size,
159 const std::array<std::vector<int>, 2>& src_dest,
160 std::span<const std::int64_t> ghosts, std::span<const int> owners);
161
162 // Copy constructor
163 IndexMap(const IndexMap& map) = delete;
164
166 IndexMap(IndexMap&& map) = default;
167
169 ~IndexMap() = default;
170
172 IndexMap& operator=(IndexMap&& map) = default;
173
174 // Copy assignment
175 IndexMap& operator=(const IndexMap& map) = delete;
176
178 std::array<std::int64_t, 2> local_range() const noexcept;
179
181 std::int32_t num_ghosts() const noexcept;
182
184 std::int32_t size_local() const noexcept;
185
187 std::int64_t size_global() const noexcept;
188
191 std::span<const std::int64_t> ghosts() const noexcept;
192
195 MPI_Comm comm() const;
196
200 void local_to_global(std::span<const std::int32_t> local,
201 std::span<std::int64_t> global) const;
202
208 void global_to_local(std::span<const std::int64_t> global,
209 std::span<std::int32_t> local) const;
210
214 std::vector<std::int64_t> global_indices() const;
215
219 std::span<const int> owners() const { return _owners; }
220
233 std::pair<std::vector<int>, std::vector<std::int32_t>> index_to_dest_ranks(
234 int tag = static_cast<int>(dolfinx::MPI::tag::consensus_nbx)) const;
235
240 std::vector<std::int32_t> shared_indices() const;
241
248 std::span<const int> src() const noexcept;
249
257 std::span<const int> dest() const noexcept;
258
272 std::vector<std::int32_t> weights_src() const;
273
287 std::vector<std::int32_t> weights_dest() const;
288
308 std::array<std::vector<int>, 2> rank_type(int split_type) const;
309
310private:
311 // Range of indices (global) owned by this process
312 std::array<std::int64_t, 2> _local_range;
313
314 // Number indices across communicator
315 std::int64_t _size_global;
316
317 // MPI communicator that map is defined on
318 dolfinx::MPI::Comm _comm;
319
320 // Local-to-global map for ghost indices
321 std::vector<std::int64_t> _ghosts;
322
323 // Owning rank on _comm for the ith ghost index
324 std::vector<int> _owners;
325
326 // Set of ranks that own ghosts
327 std::vector<int> _src;
328
329 // Set of ranks ghost owned indices
330 std::vector<int> _dest;
331};
332
333} // namespace dolfinx::common
Definition IndexMap.h:95
std::vector< std::int32_t > weights_dest() const
Compute the number of ghost indices owned by each rank in IndexMap::dest.
Definition IndexMap.cpp:1356
~IndexMap()=default
Destructor.
std::span< const int > owners() const
The ranks that own each ghost index.
Definition IndexMap.h:219
std::int32_t num_ghosts() const noexcept
Number of ghost indices on this process.
Definition IndexMap.cpp:940
std::span< const int > dest() const noexcept
Ordered set of MPI ranks that ghost indices owned by caller.
Definition IndexMap.cpp:1339
std::vector< std::int32_t > weights_src() const
Compute the number of ghost indices owned by each rank in IndexMap::src.
Definition IndexMap.cpp:1341
std::pair< std::vector< int >, std::vector< std::int32_t > > index_to_dest_ranks(int tag=static_cast< int >(dolfinx::MPI::tag::consensus_nbx)) const
For each local (owned) index compute the set of ranks that have the index as a ghost.
Definition IndexMap.cpp:1023
std::array< std::int64_t, 2 > local_range() const noexcept
Range of indices (global) owned by this process.
Definition IndexMap.cpp:935
std::int32_t size_local() const noexcept
Number of indices owned by this process.
Definition IndexMap.cpp:945
std::int64_t size_global() const noexcept
Number indices across communicator.
Definition IndexMap.cpp:950
IndexMap(IndexMap &&map)=default
Move constructor.
IndexMap & operator=(IndexMap &&map)=default
Move assignment.
std::span< const int > src() const noexcept
Ordered set of MPI ranks that own caller's ghost indices.
Definition IndexMap.cpp:1337
void local_to_global(std::span< const std::int32_t > local, std::span< std::int64_t > global) const
Compute global indices for array of local indices.
Definition IndexMap.cpp:957
void global_to_local(std::span< const std::int64_t > global, std::span< std::int32_t > local) const
Compute local indices for array of global indices.
Definition IndexMap.cpp:976
IndexMap(MPI_Comm comm, std::int32_t local_size)
Create an non-overlapping index map.
Definition IndexMap.cpp:865
std::span< const std::int64_t > ghosts() const noexcept
Definition IndexMap.cpp:952
std::vector< std::int32_t > shared_indices() const
Build a list of owned indices that are ghosted by another rank.
Definition IndexMap.cpp:1254
MPI_Comm comm() const
Return the MPI communicator that the map is defined on.
Definition IndexMap.cpp:1020
std::vector< std::int64_t > global_indices() const
Build list of indices with global indexing.
Definition IndexMap.cpp:1008
std::array< std::vector< int >, 2 > rank_type(int split_type) const
Destination and source ranks by type, e.g, ranks that are destination/source ranks for the caller and...
Definition IndexMap.cpp:1380
MPI support functionality.
Definition MPI.h:34
Miscellaneous classes, functions and types.
Definition dolfinx_common.h:8
std::pair< IndexMap, std::vector< std::int32_t > > create_sub_index_map(const IndexMap &imap, std::span< const std::int32_t > indices, IndexMapOrder order=IndexMapOrder::any, bool allow_owner_change=false)
Create a new index map from a subset of indices in an existing index map.
Definition IndexMap.cpp:825
std::vector< int32_t > compute_owned_indices(std::span< const std::int32_t > indices, const IndexMap &map)
Given a sorted list of indices (local indexing, owned or ghost) and an index map, this function retur...
Definition IndexMap.cpp:541
IndexMapOrder
Definition IndexMap.h:25
@ any
Allow arbitrary ordering of ghost indices in sub-maps.
Definition IndexMap.h:27
@ preserve
Preserve the ordering of ghost indices.
Definition IndexMap.h:26
std::tuple< std::int64_t, std::vector< std::int32_t >, std::vector< std::vector< std::int64_t > >, std::vector< std::vector< int > > > stack_index_maps(const std::vector< std::pair< std::reference_wrapper< const IndexMap >, int > > &maps)
Compute layout data and ghost indices for a stacked (concatenated) index map, i.e....
Definition IndexMap.cpp:659
Top-level namespace.
Definition defines.h:12