DOLFINx
DOLFINx C++ interface
IndexMap.h
1// Copyright (C) 2015-2022 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
29std::vector<int32_t>
30compute_owned_indices(const std::span<const std::int32_t>& indices,
31 const IndexMap& map);
32
50std::tuple<std::int64_t, std::vector<std::int32_t>,
51 std::vector<std::vector<std::int64_t>>,
52 std::vector<std::vector<int>>>
54 const std::vector<
55 std::pair<std::reference_wrapper<const common::IndexMap>, int>>& maps);
56
64{
65public:
73 IndexMap(MPI_Comm comm, std::int32_t local_size);
74
91 IndexMap(MPI_Comm comm, std::int32_t local_size,
92 const std::span<const std::int64_t>& ghosts,
93 const std::span<const int>& owners);
94
114 IndexMap(MPI_Comm comm, std::int32_t local_size,
115 const std::array<std::vector<int>, 2>& src_dest,
116 const std::span<const std::int64_t>& ghosts,
117 const std::span<const int>& owners);
118
119 // Copy constructor
120 IndexMap(const IndexMap& map) = delete;
121
123 IndexMap(IndexMap&& map) = default;
124
126 ~IndexMap() = default;
127
129 IndexMap& operator=(IndexMap&& map) = default;
130
131 // Copy assignment
132 IndexMap& operator=(const IndexMap& map) = delete;
133
135 std::array<std::int64_t, 2> local_range() const noexcept;
136
138 std::int32_t num_ghosts() const noexcept;
139
141 std::int32_t size_local() const noexcept;
142
144 std::int64_t size_global() const noexcept;
145
148 const std::vector<std::int64_t>& ghosts() const noexcept;
149
152 MPI_Comm comm() const;
153
157 void local_to_global(const std::span<const std::int32_t>& local,
158 const std::span<std::int64_t>& global) const;
159
165 void global_to_local(const std::span<const std::int64_t>& global,
166 const std::span<std::int32_t>& local) const;
167
171 std::vector<std::int64_t> global_indices() const;
172
176 const std::vector<int>& owners() const { return _owners; }
177
191 std::pair<IndexMap, std::vector<std::int32_t>>
192 create_submap(const std::span<const std::int32_t>& indices) const;
193
200
205 std::vector<std::int32_t> shared_indices() const;
206
213 const std::vector<int>& src() const noexcept;
214
222 const std::vector<int>& dest() const noexcept;
223
231 bool overlapped() const noexcept;
232
233private:
234 // Range of indices (global) owned by this process
235 std::array<std::int64_t, 2> _local_range;
236
237 // Number indices across communicator
238 std::int64_t _size_global;
239
240 // MPI communicator that map is defined on
241 dolfinx::MPI::Comm _comm;
242
243 // Local-to-global map for ghost indices
244 std::vector<std::int64_t> _ghosts;
245
246 // Local-to-global map for ghost indices
247 std::vector<int> _owners;
248
249 // Set of ranks that own ghosts
250 std::vector<int> _src;
251
252 // Set of ranks ghost owned indices
253 std::vector<int> _dest;
254
255 // True if map has overlaps (ghosts)
256 bool _overlapping;
257};
258} // namespace dolfinx::common
This class represents the distribution index arrays across processes. An index array is a contiguous ...
Definition: IndexMap.h:64
bool overlapped() const noexcept
Check if index map has overlaps (ghosts on any rank).
Definition: IndexMap.cpp:907
~IndexMap()=default
Destructor.
void local_to_global(const std::span< const std::int32_t > &local, const std::span< std::int64_t > &global) const
Compute global indices for array of local indices.
Definition: IndexMap.cpp:379
std::int32_t num_ghosts() const noexcept
Number of ghost indices on this process.
Definition: IndexMap.cpp:365
const std::vector< int > & src() const noexcept
Ordered set of MPI ranks that own caller's ghost indices.
Definition: IndexMap.cpp:903
const std::vector< int > & owners() const
The ranks that own each ghost index.
Definition: IndexMap.h:176
std::array< std::int64_t, 2 > local_range() const noexcept
Range of indices (global) owned by this process.
Definition: IndexMap.cpp:360
std::int32_t size_local() const noexcept
Number of indices owned by on this process.
Definition: IndexMap.cpp:367
std::int64_t size_global() const noexcept
Number indices across communicator.
Definition: IndexMap.cpp:372
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:605
const std::vector< std::int64_t > & ghosts() const noexcept
Local-to-global map for ghosts (local indexing beyond end of local range)
Definition: IndexMap.cpp:374
std::pair< IndexMap, std::vector< std::int32_t > > create_submap(const std::span< const std::int32_t > &indices) const
Create new index map from a subset of indices in this index map.
Definition: IndexMap.cpp:440
void global_to_local(const std::span< const std::int64_t > &global, const std::span< std::int32_t > &local) const
Compute local indices for array of global indices.
Definition: IndexMap.cpp:398
IndexMap(MPI_Comm comm, std::int32_t local_size)
Create an non-overlapping index map.
Definition: IndexMap.cpp:298
const std::vector< int > & dest() const noexcept
Ordered set of MPI ranks that ghost indices owned by caller.
Definition: IndexMap.cpp:905
std::vector< std::int32_t > shared_indices() const
Build a list of owned indices that are ghosted by another rank.
Definition: IndexMap.cpp:822
MPI_Comm comm() const
Return the MPI communicator that the map is defined on.
Definition: IndexMap.cpp:437
std::vector< std::int64_t > global_indices() const
Build list of indices with global indexing.
Definition: IndexMap.cpp:424
This class provides a static adjacency list data structure. It is commonly used to store directed gra...
Definition: AdjacencyList.h:26
Miscellaneous classes, functions and types.
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 common::IndexMap >, int > > &maps)
Compute layout data and ghost indices for a stacked (concatenated) index map, i.e....
Definition: IndexMap.cpp:136
std::vector< int32_t > compute_owned_indices(const std::span< const std::int32_t > &indices, const IndexMap &map)
Given a vector of indices (local numbering, owned or ghost) and an index map, this function returns t...
Definition: IndexMap.cpp:35