deal.II version GIT relicensing-6834-g5b78e6bcdf 2026-10-01 11:20:01+00:00
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
Loading...
Searching...
No Matches
partitioner.h
Go to the documentation of this file.
1// -----------------------------------------------------------------------------
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
4// Copyright (C) 2012 - 2026 by the deal.II authors
5//
6// This file is part of the deal.II library.
7//
8// Detailed license information governing the source code and contributions
9// can be found in LICENSE.md and CONTRIBUTING.md at the top level directory.
10//
11// -----------------------------------------------------------------------------
12
13#ifndef dealii_partitioner_h
14#define dealii_partitioner_h
15
16#include <deal.II/base/config.h>
17
24#include <deal.II/base/types.h>
25
27
28#include <Kokkos_Core.hpp>
29
30#include <limits>
31#include <memory>
32#include <vector>
33
34
36
37namespace Utilities
38{
39 namespace MPI
40 {
200 {
201 public:
206
211 Partitioner(const unsigned int size);
212
228 const types::global_dof_index ghost_size,
229 const MPI_Comm communicator);
230
238 Partitioner(const IndexSet &locally_owned_indices,
239 const IndexSet &ghost_indices_in,
240 const MPI_Comm communicator_in);
241
249 Partitioner(const IndexSet &locally_owned_indices,
250 const MPI_Comm communicator_in);
251
265 virtual void
266 reinit(const IndexSet &locally_owned_indices,
267 const IndexSet &ghost_indices,
268 const MPI_Comm communicator) override;
269
273 void
274 set_owned_indices(const IndexSet &locally_owned_indices);
275
286 void
288 const IndexSet &larger_ghost_index_set = IndexSet());
289
294 size() const;
295
302 unsigned int
304
311 const IndexSet &
313
319 std::pair<types::global_dof_index, types::global_dof_index>
320 local_range() const;
321
326 bool
327 in_local_range(const types::global_dof_index global_index) const;
328
339 unsigned int
340 global_to_local(const types::global_dof_index global_index) const;
341
351 local_to_global(const unsigned int local_index) const;
352
358 bool
359 is_ghost_entry(const types::global_dof_index global_index) const;
360
364 const IndexSet &
366
371 unsigned int
373
384 const std::vector<std::pair<unsigned int, unsigned int>> &
386
392 const std::vector<std::pair<unsigned int, unsigned int>> &
394
403 const std::vector<std::pair<unsigned int, unsigned int>> &
405
410 unsigned int
412
422 const std::vector<std::pair<unsigned int, unsigned int>> &
424
435 bool
436 is_compatible(const Partitioner &part) const;
437
454 bool
456
461 unsigned int
463
468 unsigned int
470
474 virtual MPI_Comm
475 get_mpi_communicator() const override;
476
482 bool
484
485#ifdef DEAL_II_WITH_MPI
521 template <typename Number, typename MemorySpaceType = MemorySpace::Host>
522 void
524 const unsigned int communication_channel,
525 const ArrayView<const Number, MemorySpaceType> &locally_owned_array,
526 const ArrayView<Number, MemorySpaceType> &temporary_storage,
527 const ArrayView<Number, MemorySpaceType> &ghost_array,
528 std::vector<MPI_Request> &requests) const;
529
547 template <typename Number, typename MemorySpaceType = MemorySpace::Host>
548 void
550 const ArrayView<Number, MemorySpaceType> &ghost_array,
551 std::vector<MPI_Request> &requests) const;
552
590 template <typename Number, typename MemorySpaceType = MemorySpace::Host>
591 void
593 const VectorOperation::values vector_operation,
594 const unsigned int communication_channel,
595 const ArrayView<Number, MemorySpaceType> &ghost_array,
596 const ArrayView<Number, MemorySpaceType> &temporary_storage,
597 std::vector<MPI_Request> &requests) const;
598
633 template <typename Number, typename MemorySpaceType = MemorySpace::Host>
634 void
636 const VectorOperation::values vector_operation,
637 const ArrayView<const Number, MemorySpaceType> &temporary_storage,
638 const ArrayView<Number, MemorySpaceType> &locally_owned_storage,
639 const ArrayView<Number, MemorySpaceType> &ghost_array,
640 std::vector<MPI_Request> &requests) const;
641#endif
642
646 std::size_t
648
654 unsigned int,
655 << "Global index " << arg1
656 << " neither owned nor ghost on proc " << arg2 << '.');
657
662 unsigned int,
663 unsigned int,
664 unsigned int,
665 << "The size of the ghost index array (" << arg1
666 << ") must either equal the number of ghost in the "
667 << "partitioner (" << arg2
668 << ") or be equal in size to a more comprehensive index"
669 << "set which contains " << arg3
670 << " elements for this partitioner.");
671
672 private:
677 void
679
684
689
694 std::pair<types::global_dof_index, types::global_dof_index>
696
702
708
713 std::vector<std::pair<unsigned int, unsigned int>> ghost_targets_data;
714
721 std::vector<std::pair<unsigned int, unsigned int>> import_indices_data;
722
729 // The variable is mutable to enable lazy initialization in
730 // export_to_ghosted_array_start().
731 mutable std::vector<
732 Kokkos::View<unsigned int *, MemorySpace::Default::kokkos_space>>
734
740
745 std::vector<std::pair<unsigned int, unsigned int>> import_targets_data;
746
751 std::vector<unsigned int> import_indices_chunks_by_rank_data;
752
758
764
770 std::vector<std::pair<unsigned int, unsigned int>>
772
776 unsigned int my_pid;
777
781 unsigned int n_procs;
782
787
792 };
793
794
795
796 /*--------------------- Inline functions --------------------------------*/
797
798#ifndef DOXYGEN
799
801 Partitioner::size() const
802 {
803 return global_size;
804 }
805
806
807
808 inline const IndexSet &
810 {
812 }
813
814
815
816 inline std::pair<types::global_dof_index, types::global_dof_index>
818 {
819 return local_range_data;
820 }
821
822
823
824 inline unsigned int
826 {
828 local_range_data.second - local_range_data.first;
829 Assert(size <= std::numeric_limits<unsigned int>::max(),
831 return static_cast<unsigned int>(size);
832 }
833
834
835
836 inline bool
838 const types::global_dof_index global_index) const
839 {
840 return (local_range_data.first <= global_index &&
841 global_index < local_range_data.second);
842 }
843
844
845
846 inline bool
848 const types::global_dof_index global_index) const
849 {
850 // if the index is in the global range, it is trivially not a ghost
851 if (in_local_range(global_index) == true)
852 return false;
853 else
854 return ghost_indices().is_element(global_index);
855 }
856
857
858
859 inline unsigned int
861 const types::global_dof_index global_index) const
862 {
863 Assert(in_local_range(global_index) || is_ghost_entry(global_index),
864 ExcIndexNotPresent(global_index, my_pid));
865 if (in_local_range(global_index))
866 return static_cast<unsigned int>(global_index - local_range_data.first);
867 else
868 {
869 // avoid checking the ghost index set via a binary search twice by
870 // querying the index within set, which returns invalid_dof_index
871 // for non-existent entries
872 const types::global_dof_index index_within_ghosts =
874 if (index_within_ghosts == numbers::invalid_dof_index)
876 else
877 return locally_owned_size() +
878 static_cast<unsigned int>(index_within_ghosts);
879 }
880 }
881
882
883
885 Partitioner::local_to_global(const unsigned int local_index) const
886 {
887 AssertIndexRange(local_index,
889 if (local_index < locally_owned_size())
890 return local_range_data.first + types::global_dof_index(local_index);
891 else
892 return ghost_indices_data.nth_index_in_set(local_index -
894 }
895
896
897
898 inline const IndexSet &
900 {
901 return ghost_indices_data;
902 }
903
904
905
906 inline unsigned int
908 {
910 }
911
912
913
914 inline const std::vector<std::pair<unsigned int, unsigned int>> &
916 {
918 }
919
920
921
922 inline const std::vector<std::pair<unsigned int, unsigned int>> &
924 {
925 return ghost_targets_data;
926 }
927
928
929 inline const std::vector<std::pair<unsigned int, unsigned int>> &
931 {
932 return import_indices_data;
933 }
934
935
936
937 inline unsigned int
939 {
941 }
942
943
944
945 inline const std::vector<std::pair<unsigned int, unsigned int>> &
947 {
948 return import_targets_data;
949 }
950
951
952
953 inline unsigned int
955 {
956 // return the id from the variable stored in this class instead of
957 // Utilities::MPI::this_mpi_process() in order to make this query also
958 // work when MPI is not initialized.
959 return my_pid;
960 }
961
962
963
964 inline unsigned int
966 {
967 // return the number of MPI processes from the variable stored in this
968 // class instead of Utilities::MPI::n_mpi_processes() in order to make
969 // this query also work when MPI is not initialized.
970 return n_procs;
971 }
972
973
974
975 inline MPI_Comm
977 {
978 return communicator;
979 }
980
981
982
983 inline bool
985 {
986 return have_ghost_indices;
987 }
988
989#endif // ifndef DOXYGEN
990
991 } // end of namespace MPI
992
993} // end of namespace Utilities
994
995
997
998#endif
size_type index_within_set(const size_type global_index) const
Definition index_set.h:1977
bool is_element(const size_type index) const
Definition index_set.h:1877
size_type nth_index_in_set(const size_type local_index) const
Definition index_set.h:1958
unsigned int n_ghost_indices_data
Partitioner(const IndexSet &locally_owned_indices, const IndexSet &ghost_indices_in, const MPI_Comm communicator_in)
std::size_t memory_consumption() const
unsigned int global_to_local(const types::global_dof_index global_index) const
bool in_local_range(const types::global_dof_index global_index) const
std::vector< Kokkos::View< unsigned int *, MemorySpace::Default::kokkos_space > > import_indices_plain_dev
std::vector< std::pair< unsigned int, unsigned int > > import_indices_data
bool is_globally_compatible(const Partitioner &part) const
void set_owned_indices(const IndexSet &locally_owned_indices)
const IndexSet & locally_owned_range() const
unsigned int n_ghost_indices_in_larger_set
unsigned int n_ghost_indices() const
std::vector< std::pair< unsigned int, unsigned int > > ghost_targets_data
const std::vector< std::pair< unsigned int, unsigned int > > & ghost_indices_within_larger_ghost_set() const
const IndexSet & ghost_indices() const
const std::vector< std::pair< unsigned int, unsigned int > > & ghost_targets() const
Partitioner(const IndexSet &locally_owned_indices, const MPI_Comm communicator_in)
void export_to_ghosted_array_start(const unsigned int communication_channel, const ArrayView< const Number, MemorySpaceType > &locally_owned_array, const ArrayView< Number, MemorySpaceType > &temporary_storage, const ArrayView< Number, MemorySpaceType > &ghost_array, std::vector< MPI_Request > &requests) const
unsigned int this_mpi_process() const
const std::vector< std::pair< unsigned int, unsigned int > > & import_targets() const
void import_from_ghosted_array_finish(const VectorOperation::values vector_operation, const ArrayView< const Number, MemorySpaceType > &temporary_storage, const ArrayView< Number, MemorySpaceType > &locally_owned_storage, const ArrayView< Number, MemorySpaceType > &ghost_array, std::vector< MPI_Request > &requests) const
unsigned int n_mpi_processes() const
void initialize_import_indices_plain_dev() const
Partitioner(const unsigned int size)
types::global_dof_index global_size
unsigned int locally_owned_size() const
types::global_dof_index local_to_global(const unsigned int local_index) const
std::pair< types::global_dof_index, types::global_dof_index > local_range_data
std::vector< unsigned int > import_indices_chunks_by_rank_data
virtual MPI_Comm get_mpi_communicator() const override
unsigned int n_import_indices_data
void set_ghost_indices(const IndexSet &ghost_indices, const IndexSet &larger_ghost_index_set=IndexSet())
void export_to_ghosted_array_finish(const ArrayView< Number, MemorySpaceType > &ghost_array, std::vector< MPI_Request > &requests) const
Partitioner(const types::global_dof_index local_size, const types::global_dof_index ghost_size, const MPI_Comm communicator)
std::pair< types::global_dof_index, types::global_dof_index > local_range() const
unsigned int n_import_indices() const
const std::vector< std::pair< unsigned int, unsigned int > > & import_indices() const
std::vector< unsigned int > ghost_indices_subset_chunks_by_rank_data
void import_from_ghosted_array_start(const VectorOperation::values vector_operation, const unsigned int communication_channel, const ArrayView< Number, MemorySpaceType > &ghost_array, const ArrayView< Number, MemorySpaceType > &temporary_storage, std::vector< MPI_Request > &requests) const
std::vector< std::pair< unsigned int, unsigned int > > import_targets_data
types::global_dof_index size() const
virtual void reinit(const IndexSet &locally_owned_indices, const IndexSet &ghost_indices, const MPI_Comm communicator) override
bool is_ghost_entry(const types::global_dof_index global_index) const
bool is_compatible(const Partitioner &part) const
std::vector< std::pair< unsigned int, unsigned int > > ghost_indices_subset_data
bool ghost_indices_initialized() const
#define DEAL_II_NAMESPACE_OPEN
Definition config.h:38
#define DEAL_II_NAMESPACE_CLOSE
Definition config.h:39
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
static ::ExceptionBase & ExcIndexNotPresent(types::global_dof_index arg1, unsigned int arg2)
#define DeclException2(Exception2, type1, type2, outsequence)
static ::ExceptionBase & ExcGhostIndexArrayHasWrongSize(unsigned int arg1, unsigned int arg2, unsigned int arg3)
#define AssertIndexRange(index, range)
#define DeclException3(Exception3, type1, type2, type3, outsequence)
TrilinosWrappers::types::int_type global_index(const Epetra_BlockMap &map, const ::types::global_dof_index i)
constexpr types::global_dof_index invalid_dof_index
Definition types.h:259
constexpr unsigned int invalid_unsigned_int
Definition types.h:228
unsigned int global_dof_index
Definition types.h:92