DOLFINx 0.10.0.0
DOLFINx C++ interface
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 "IndexMap.h"
10#include "MPI.h"
11#include <cstdint>
12#include <dolfinx/graph/AdjacencyList.h>
13#include <memory>
14#include <span>
15#include <tuple>
16#include <utility>
17#include <vector>
18
19namespace dolfinx::common
20{
21// Forward declaration
22class IndexMap;
23
26enum class IndexMapOrder : bool
27{
28 preserve = true,
29 any = false
30};
31
40std::vector<int32_t>
41compute_owned_indices(std::span<const std::int32_t> indices,
42 const IndexMap& map);
43
61std::tuple<std::int64_t, std::vector<std::int32_t>,
62 std::vector<std::vector<std::int64_t>>,
63 std::vector<std::vector<int>>>
65 const std::vector<std::pair<std::reference_wrapper<const IndexMap>, int>>&
66 maps);
67
86std::pair<IndexMap, std::vector<std::int32_t>> create_sub_index_map(
87 const IndexMap& imap, std::span<const std::int32_t> indices,
88 IndexMapOrder order = IndexMapOrder::any, bool allow_owner_change = false);
89
97{
98public:
107 IndexMap(MPI_Comm comm, std::int32_t local_size);
108
137 IndexMap(MPI_Comm comm, std::int32_t local_size,
138 std::span<const std::int64_t> ghosts, std::span<const int> owners,
139 int tag = static_cast<int>(dolfinx::MPI::tag::consensus_nbx));
140
160 IndexMap(MPI_Comm comm, std::int32_t local_size,
161 const std::array<std::vector<int>, 2>& src_dest,
162 std::span<const std::int64_t> ghosts, std::span<const int> owners);
163
164 // Copy constructor
165 IndexMap(const IndexMap& map) = delete;
166
168 IndexMap(IndexMap&& map) = default;
169
171 ~IndexMap() = default;
172
174 IndexMap& operator=(IndexMap&& map) = default;
175
176 // Copy assignment
177 IndexMap& operator=(const IndexMap& map) = delete;
178
180 std::array<std::int64_t, 2> local_range() const noexcept;
181
183 std::int32_t num_ghosts() const noexcept;
184
186 std::int32_t size_local() const noexcept;
187
189 std::int64_t size_global() const noexcept;
190
193 std::span<const std::int64_t> ghosts() const noexcept;
194
197 MPI_Comm comm() const;
198
202 void local_to_global(std::span<const std::int32_t> local,
203 std::span<std::int64_t> global) const;
204
210 void global_to_local(std::span<const std::int64_t> global,
211 std::span<std::int32_t> local) const;
212
216 std::vector<std::int64_t> global_indices() const;
217
221 std::span<const int> owners() const { return _owners; }
222
236 int tag = static_cast<int>(dolfinx::MPI::tag::consensus_nbx)) const;
237
242 std::vector<std::int32_t> shared_indices() const;
243
250 std::span<const int> src() const noexcept;
251
259 std::span<const int> dest() const noexcept;
260
274 std::vector<std::int32_t> weights_src() const;
275
289 std::vector<std::int32_t> weights_dest() const;
290
310 std::array<std::vector<int>, 2> rank_type(int split_type) const;
311
312private:
313 // Range of indices (global) owned by this process
314 std::array<std::int64_t, 2> _local_range;
315
316 // Number indices across communicator
317 std::int64_t _size_global;
318
319 // MPI communicator that map is defined on
320 dolfinx::MPI::Comm _comm;
321
322 // Local-to-global map for ghost indices
323 std::vector<std::int64_t> _ghosts;
324
325 // Owning rank on _comm for the ith ghost index
326 std::vector<int> _owners;
327
328 // Set of ranks that own ghosts
329 std::vector<int> _src;
330
331 // Set of ranks ghost owned indices
332 std::vector<int> _dest;
333};
334
335} // namespace dolfinx::common
Definition IndexMap.h:97
std::vector< std::int32_t > weights_dest() const
Compute the number of ghost indices owned by each rank in IndexMap::dest.
Definition IndexMap.cpp:1319
~IndexMap()=default
Destructor.
std::span< const int > owners() const
The ranks that own each ghost index.
Definition IndexMap.h:221
std::int32_t num_ghosts() const noexcept
Number of ghost indices on this process.
Definition IndexMap.cpp:931
std::span< const int > dest() const noexcept
Ordered set of MPI ranks that ghost indices owned by caller.
Definition IndexMap.cpp:1302
std::vector< std::int32_t > weights_src() const
Compute the number of ghost indices owned by each rank in IndexMap::src.
Definition IndexMap.cpp:1304
std::array< std::int64_t, 2 > local_range() const noexcept
Range of indices (global) owned by this process.
Definition IndexMap.cpp:926
std::int32_t size_local() const noexcept
Number of indices owned by this process.
Definition IndexMap.cpp:933
std::int64_t size_global() const noexcept
Number indices across communicator.
Definition IndexMap.cpp:938
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:1300
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:945
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:964
IndexMap(MPI_Comm comm, std::int32_t local_size)
Create an non-overlapping index map.
Definition IndexMap.cpp:856
std::span< const std::int64_t > ghosts() const noexcept
Definition IndexMap.cpp:940
graph::AdjacencyList< int > index_to_dest_ranks(int tag=static_cast< int >(dolfinx::MPI::tag::consensus_nbx)) const
Compute map from each local (owned) index to the set of ranks that have the index as a ghost.
Definition IndexMap.cpp:1007
std::vector< std::int32_t > shared_indices() const
Build a list of owned indices that are ghosted by another rank.
Definition IndexMap.cpp:1229
MPI_Comm comm() const
Return the MPI communicator that the map is defined on.
Definition IndexMap.cpp:1005
std::vector< std::int64_t > global_indices() const
Build list of indices with global indexing.
Definition IndexMap.cpp:993
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:1347
This class provides a static adjacency list data structure.
Definition AdjacencyList.h:38
MPI support functionality.
Definition MPI.h:30
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:816
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:538
IndexMapOrder
Definition IndexMap.h:27
@ any
Allow arbitrary ordering of ghost indices in sub-maps.
Definition IndexMap.h:29
@ preserve
Preserve the ordering of ghost indices.
Definition IndexMap.h:28
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:650
Top-level namespace.
Definition defines.h:12