Loading...
Searching...
No Matches
IndexMap.h
// Copyright (C) 2015-2024 Chris Richardson, Garth N. Wells and Igor Baratta
//
// This file is part of DOLFINx (https://www.fenicsproject.org)
//
// SPDX-License-Identifier: LGPL-3.0-or-later
#pragma once
#include "IndexMap.h"
#include "MPI.h"
#include <cstdint>
#include <dolfinx/graph/AdjacencyList.h>
#include <memory>
#include <span>
#include <tuple>
#include <utility>
#include <vector>
namespace dolfinx::common
{
// Forward declaration
class IndexMap;
enum class IndexMapOrder : bool
{
preserve = true,
any = false
};
std::vector<int32_t>
compute_owned_indices(std::span<const std::int32_t> indices,
const IndexMap& map);
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);
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);
class IndexMap
{
public:
IndexMap(MPI_Comm comm, std::int32_t local_size);
IndexMap(MPI_Comm comm, std::int32_t local_size,
std::span<const std::int64_t> ghosts, std::span<const int> owners,
int tag = static_cast<int>(dolfinx::MPI::tag::consensus_nbx));
IndexMap(MPI_Comm comm, std::int32_t local_size,
const std::array<std::vector<int>, 2>& src_dest,
std::span<const std::int64_t> ghosts, std::span<const int> owners);
// Copy constructor
IndexMap(const IndexMap& map) = delete;
IndexMap(IndexMap&& map) = default;
~IndexMap() = default;
IndexMap& operator=(IndexMap&& map) = default;
// Copy assignment
IndexMap& operator=(const IndexMap& map) = delete;
std::array<std::int64_t, 2> local_range() const noexcept;
std::int32_t num_ghosts() const noexcept;
std::int32_t size_local() const noexcept;
std::int64_t size_global() const noexcept;
std::span<const std::int64_t> ghosts() const noexcept;
MPI_Comm comm() const;
void local_to_global(std::span<const std::int32_t> local,
std::span<std::int64_t> global) const;
void global_to_local(std::span<const std::int64_t> global,
std::span<std::int32_t> local) const;
std::vector<std::int64_t> global_indices() const;
std::span<const int> owners() const { return _owners; }
graph::AdjacencyList<int> index_to_dest_ranks(
int tag = static_cast<int>(dolfinx::MPI::tag::consensus_nbx)) const;
std::vector<std::int32_t> shared_indices() const;
std::span<const int> src() const noexcept;
std::span<const int> dest() const noexcept;
std::vector<std::int32_t> weights_src() const;
std::vector<std::int32_t> weights_dest() const;
std::array<std::vector<int>, 2> rank_type(int split_type) const;
private:
// Range of indices (global) owned by this process
std::array<std::int64_t, 2> _local_range;
// Number indices across communicator
std::int64_t _size_global;
// MPI communicator that map is defined on
dolfinx::MPI::Comm _comm;
// Local-to-global map for ghost indices
std::vector<std::int64_t> _ghosts;
// Owning rank on _comm for the ith ghost index
std::vector<int> _owners;
// Set of ranks that own ghosts
std::vector<int> _src;
// Set of ranks ghost owned indices
std::vector<int> _dest;
};
} // namespace dolfinx::common
dolfinx::common::IndexMap
Definition IndexMap.h:97
dolfinx::common::IndexMap::weights_dest
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
dolfinx::common::IndexMap::~IndexMap
~IndexMap()=default
Destructor.
dolfinx::common::IndexMap::owners
std::span< const int > owners() const
The ranks that own each ghost index.
Definition IndexMap.h:221
dolfinx::common::IndexMap::num_ghosts
std::int32_t num_ghosts() const noexcept
Number of ghost indices on this process.
Definition IndexMap.cpp:931
dolfinx::common::IndexMap::dest
std::span< const int > dest() const noexcept
Ordered set of MPI ranks that ghost indices owned by caller.
Definition IndexMap.cpp:1302
dolfinx::common::IndexMap::weights_src
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
dolfinx::common::IndexMap::local_range
std::array< std::int64_t, 2 > local_range() const noexcept
Range of indices (global) owned by this process.
Definition IndexMap.cpp:926
dolfinx::common::IndexMap::size_local
std::int32_t size_local() const noexcept
Number of indices owned by this process.
Definition IndexMap.cpp:933
dolfinx::common::IndexMap::size_global
std::int64_t size_global() const noexcept
Number indices across communicator.
Definition IndexMap.cpp:938
dolfinx::common::IndexMap::IndexMap
IndexMap(IndexMap &&map)=default
Move constructor.
dolfinx::common::IndexMap::operator=
IndexMap & operator=(IndexMap &&map)=default
Move assignment.
dolfinx::common::IndexMap::src
std::span< const int > src() const noexcept
Ordered set of MPI ranks that own caller's ghost indices.
Definition IndexMap.cpp:1300
dolfinx::common::IndexMap::local_to_global
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
dolfinx::common::IndexMap::global_to_local
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
dolfinx::common::IndexMap::IndexMap
IndexMap(MPI_Comm comm, std::int32_t local_size)
Create an non-overlapping index map.
Definition IndexMap.cpp:856
dolfinx::common::IndexMap::ghosts
std::span< const std::int64_t > ghosts() const noexcept
Definition IndexMap.cpp:940
dolfinx::common::IndexMap::index_to_dest_ranks
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
dolfinx::common::IndexMap::shared_indices
std::vector< std::int32_t > shared_indices() const
Build a list of owned indices that are ghosted by another rank.
Definition IndexMap.cpp:1229
dolfinx::common::IndexMap::comm
MPI_Comm comm() const
Return the MPI communicator that the map is defined on.
Definition IndexMap.cpp:1005
dolfinx::common::IndexMap::global_indices
std::vector< std::int64_t > global_indices() const
Build list of indices with global indexing.
Definition IndexMap.cpp:993
dolfinx::common::IndexMap::rank_type
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
dolfinx::graph::AdjacencyList
This class provides a static adjacency list data structure.
Definition AdjacencyList.h:38
dolfinx::MPI
MPI support functionality.
Definition MPI.h:30
dolfinx::common
Miscellaneous classes, functions and types.
Definition dolfinx_common.h:8
dolfinx::common::create_sub_index_map
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
dolfinx::common::compute_owned_indices
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
dolfinx::common::IndexMapOrder
IndexMapOrder
Definition IndexMap.h:27
dolfinx::common::IndexMapOrder::any
@ any
Allow arbitrary ordering of ghost indices in sub-maps.
Definition IndexMap.h:29
dolfinx::common::IndexMapOrder::preserve
@ preserve
Preserve the ordering of ghost indices.
Definition IndexMap.h:28
dolfinx::common::stack_index_maps
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
dolfinx
Top-level namespace.
Definition defines.h:12