Note: this is documentation for an old release. View the latest documentation at docs.fenicsproject.org/dolfinx/v0.9.0/cpp/doxygen/d7/d74/IndexMap_8h_source.html
DOLFINx 0.8.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 <cstdint>
11#include <dolfinx/common/MPI.h>
12#include <memory>
13#include <span>
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
37std::vector<int32_t>
38compute_owned_indices(std::span<const std::int32_t> indices,
39 const IndexMap& map);
40
58std::tuple<std::int64_t, std::vector<std::int32_t>,
59 std::vector<std::vector<std::int64_t>>,
60 std::vector<std::vector<int>>>
62 const std::vector<std::pair<std::reference_wrapper<const IndexMap>, int>>&
63 maps);
64
83std::pair<IndexMap, std::vector<std::int32_t>> create_sub_index_map(
84 const IndexMap& imap, std::span<const std::int32_t> indices,
85 IndexMapOrder order = IndexMapOrder::any, bool allow_owner_change = false);
86
94{
95public:
104 IndexMap(MPI_Comm comm, std::int32_t local_size);
105
122 IndexMap(MPI_Comm comm, std::int32_t local_size,
123 std::span<const std::int64_t> ghosts, std::span<const int> owners);
124
144 IndexMap(MPI_Comm comm, std::int32_t local_size,
145 const std::array<std::vector<int>, 2>& src_dest,
146 std::span<const std::int64_t> ghosts, std::span<const int> owners);
147
148 // Copy constructor
149 IndexMap(const IndexMap& map) = delete;
150
152 IndexMap(IndexMap&& map) = default;
153
155 ~IndexMap() = default;
156
158 IndexMap& operator=(IndexMap&& map) = default;
159
160 // Copy assignment
161 IndexMap& operator=(const IndexMap& map) = delete;
162
164 std::array<std::int64_t, 2> local_range() const noexcept;
165
167 std::int32_t num_ghosts() const noexcept;
168
170 std::int32_t size_local() const noexcept;
171
173 std::int64_t size_global() const noexcept;
174
177 std::span<const std::int64_t> ghosts() const noexcept;
178
181 MPI_Comm comm() const;
182
186 void local_to_global(std::span<const std::int32_t> local,
187 std::span<std::int64_t> global) const;
188
194 void global_to_local(std::span<const std::int64_t> global,
195 std::span<std::int32_t> local) const;
196
200 std::vector<std::int64_t> global_indices() const;
201
205 std::span<const int> owners() const { return _owners; }
206
213
218 std::vector<std::int32_t> shared_indices() const;
219
226 std::span<const int> src() const noexcept;
227
235 std::span<const int> dest() const noexcept;
236
252 std::array<double, 2> imbalance() const;
253
254private:
255 // Range of indices (global) owned by this process
256 std::array<std::int64_t, 2> _local_range;
257
258 // Number indices across communicator
259 std::int64_t _size_global;
260
261 // MPI communicator that map is defined on
262 dolfinx::MPI::Comm _comm;
263
264 // Local-to-global map for ghost indices
265 std::vector<std::int64_t> _ghosts;
266
267 // Owning rank on _comm for the ith ghost index
268 std::vector<int> _owners;
269
270 // Set of ranks that own ghosts
271 std::vector<int> _src;
272
273 // Set of ranks ghost owned indices
274 std::vector<int> _dest;
275};
276} // namespace dolfinx::common
Definition IndexMap.h:94
~IndexMap()=default
Destructor.
std::span< const int > owners() const
The ranks that own each ghost index.
Definition IndexMap.h:205
std::int32_t num_ghosts() const noexcept
Number of ghost indices on this process.
Definition IndexMap.cpp:866
std::span< const int > dest() const noexcept
Ordered set of MPI ranks that ghost indices owned by caller.
Definition IndexMap.cpp:1239
std::array< std::int64_t, 2 > local_range() const noexcept
Range of indices (global) owned by this process.
Definition IndexMap.cpp:861
std::int32_t size_local() const noexcept
Number of indices owned by this process.
Definition IndexMap.cpp:868
std::int64_t size_global() const noexcept
Number indices across communicator.
Definition IndexMap.cpp:873
IndexMap(IndexMap &&map)=default
Move constructor.
IndexMap & operator=(IndexMap &&map)=default
Move assignment.
graph::AdjacencyList< int > index_to_dest_ranks() const
Compute map from each local (owned) index to the set of ranks that have the index as a ghost.
Definition IndexMap.cpp:942
std::array< double, 2 > imbalance() const
Returns the imbalance of the current IndexMap.
Definition IndexMap.cpp:1241
std::span< const int > src() const noexcept
Ordered set of MPI ranks that own caller's ghost indices.
Definition IndexMap.cpp:1237
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:880
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:899
IndexMap(MPI_Comm comm, std::int32_t local_size)
Create an non-overlapping index map.
Definition IndexMap.cpp:792
std::span< const std::int64_t > ghosts() const noexcept
Definition IndexMap.cpp:875
std::vector< std::int32_t > shared_indices() const
Build a list of owned indices that are ghosted by another rank.
Definition IndexMap.cpp:1166
MPI_Comm comm() const
Return the MPI communicator that the map is defined on.
Definition IndexMap.cpp:940
std::vector< std::int64_t > global_indices() const
Build list of indices with global indexing.
Definition IndexMap.cpp:927
Definition AdjacencyList.h:28
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:751
std::vector< int32_t > compute_owned_indices(std::span< const std::int32_t > indices, const IndexMap &map)
Given a sorted vector of indices (local numbering, owned or ghost) and an index map,...
Definition IndexMap.cpp:473
IndexMapOrder
Definition IndexMap.h:25
@ any
Allow arbitrary ordering of ghost indices in sub-maps.
@ preserve
Preserve the ordering of ghost indices.
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:583
Top-level namespace.
Definition defines.h:12