Reference documentation for deal.II version 9.3.3
\(\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\}}\)
partitioner.h
Go to the documentation of this file.
1// ---------------------------------------------------------------------
2//
3// Copyright (C) 2011 - 2021 by the deal.II authors
4//
5// This file is part of the deal.II library.
6//
7// The deal.II library is free software; you can use it, redistribute
8// it, and/or modify it under the terms of the GNU Lesser General
9// Public License as published by the Free Software Foundation; either
10// version 2.1 of the License, or (at your option) any later version.
11// The full text of the license can be found in the file LICENSE.md at
12// the top level directory of deal.II.
13//
14// ---------------------------------------------------------------------
15
16#ifndef dealii_partitioner_h
17#define dealii_partitioner_h
18
19#include <deal.II/base/config.h>
20
26#include <deal.II/base/mpi.h>
27#include <deal.II/base/types.h>
29
30#include <deal.II/lac/vector.h>
32
33#include <limits>
34
35
37
38namespace Utilities
39{
40 namespace MPI
41 {
195 {
196 public:
201
206 Partitioner(const unsigned int size);
207
223 const types::global_dof_index ghost_size,
224 const MPI_Comm & communicator);
225
233 Partitioner(const IndexSet &locally_owned_indices,
234 const IndexSet &ghost_indices_in,
235 const MPI_Comm &communicator_in);
236
244 Partitioner(const IndexSet &locally_owned_indices,
245 const MPI_Comm &communicator_in);
246
254 virtual void
255 reinit(const IndexSet &vector_space_vector_index_set,
256 const IndexSet &read_write_vector_index_set,
257 const MPI_Comm &communicator) override;
258
262 void
263 set_owned_indices(const IndexSet &locally_owned_indices);
264
275 void
277 const IndexSet &larger_ghost_index_set = IndexSet());
278
283 size() const;
284
295 unsigned int
296 local_size() const;
297
304 unsigned int
306
313 const IndexSet &
315
321 std::pair<types::global_dof_index, types::global_dof_index>
322 local_range() const;
323
328 bool
330
341 unsigned int
343
353 local_to_global(const unsigned int local_index) const;
354
360 bool
362
366 const IndexSet &
368
373 unsigned int
375
386 const std::vector<std::pair<unsigned int, unsigned int>> &
388
394 const std::vector<std::pair<unsigned int, unsigned int>> &
396
405 const std::vector<std::pair<unsigned int, unsigned int>> &
407
412 unsigned int
414
424 const std::vector<std::pair<unsigned int, unsigned int>> &
426
437 bool
438 is_compatible(const Partitioner &part) const;
439
456 bool
458
463 unsigned int
465
470 unsigned int
472
476 virtual const MPI_Comm &
477 get_mpi_communicator() const override;
478
484 bool
486
487#ifdef DEAL_II_WITH_MPI
523 template <typename Number, typename MemorySpaceType = MemorySpace::Host>
524 void
526 const unsigned int communication_channel,
527 const ArrayView<const Number, MemorySpaceType> &locally_owned_array,
528 const ArrayView<Number, MemorySpaceType> & temporary_storage,
529 const ArrayView<Number, MemorySpaceType> & ghost_array,
530 std::vector<MPI_Request> & requests) const;
531
549 template <typename Number, typename MemorySpaceType = MemorySpace::Host>
550 void
552 const ArrayView<Number, MemorySpaceType> &ghost_array,
553 std::vector<MPI_Request> & requests) const;
554
592 template <typename Number, typename MemorySpaceType = MemorySpace::Host>
593 void
595 const VectorOperation::values vector_operation,
596 const unsigned int communication_channel,
597 const ArrayView<Number, MemorySpaceType> &ghost_array,
598 const ArrayView<Number, MemorySpaceType> &temporary_storage,
599 std::vector<MPI_Request> & requests) const;
600
635 template <typename Number, typename MemorySpaceType = MemorySpace::Host>
636 void
638 const VectorOperation::values vector_operation,
639 const ArrayView<const Number, MemorySpaceType> &temporary_storage,
640 const ArrayView<Number, MemorySpaceType> & locally_owned_storage,
641 const ArrayView<Number, MemorySpaceType> & ghost_array,
642 std::vector<MPI_Request> & requests) const;
643#endif
644
648 std::size_t
650
656 unsigned int,
657 << "Global index " << arg1
658 << " neither owned nor ghost on proc " << arg2 << ".");
659
664 unsigned int,
665 unsigned int,
666 unsigned int,
667 << "The size of the ghost index array (" << arg1
668 << ") must either equal the number of ghost in the "
669 << "partitioner (" << arg2
670 << ") or be equal in size to a more comprehensive index"
671 << "set which contains " << arg3
672 << " elements for this partitioner.");
673
674 private:
679 void
681
686
691
696 std::pair<types::global_dof_index, types::global_dof_index>
698
704
710
715 std::vector<std::pair<unsigned int, unsigned int>> ghost_targets_data;
716
723 std::vector<std::pair<unsigned int, unsigned int>> import_indices_data;
724
731 // The variable is mutable to enable lazy initialization in
732 // export_to_ghosted_array_start(). This way partitioner does not have to
733 // be templated on the MemorySpaceType.
734 mutable std::vector<
735 std::pair<std::unique_ptr<unsigned int[], void (*)(unsigned int *)>,
736 unsigned int>>
738
744
749 std::vector<std::pair<unsigned int, unsigned int>> import_targets_data;
750
755 std::vector<unsigned int> import_indices_chunks_by_rank_data;
756
762
768
774 std::vector<std::pair<unsigned int, unsigned int>>
776
780 unsigned int my_pid;
781
785 unsigned int n_procs;
786
791
796 };
797
798
799
800 /*--------------------- Inline functions --------------------------------*/
801
802#ifndef DOXYGEN
803
805 Partitioner::size() const
806 {
807 return global_size;
808 }
809
810
811
812 inline const IndexSet &
814 {
816 }
817
818
819
820 inline std::pair<types::global_dof_index, types::global_dof_index>
822 {
823 return local_range_data;
824 }
825
826
827
828 inline unsigned int
830 {
831 return locally_owned_size();
832 }
833
834
835
836 inline unsigned int
838 {
840 local_range_data.second - local_range_data.first;
843 return static_cast<unsigned int>(size);
844 }
845
846
847
848 inline bool
851 {
852 return (local_range_data.first <= global_index &&
854 }
855
856
857
858 inline bool
861 {
862 // if the index is in the global range, it is trivially not a ghost
863 if (in_local_range(global_index) == true)
864 return false;
865 else
867 }
868
869
870
871 inline unsigned int
874 {
878 return static_cast<unsigned int>(global_index - local_range_data.first);
880 return (locally_owned_size() +
881 static_cast<unsigned int>(
883 else
884 // should only end up here in optimized mode, when we use this large
885 // number to trigger a segfault when using this method for array
886 // access
888 }
889
890
891
893 Partitioner::local_to_global(const unsigned int local_index) const
894 {
895 AssertIndexRange(local_index,
897 if (local_index < locally_owned_size())
898 return local_range_data.first + types::global_dof_index(local_index);
899 else
900 return ghost_indices_data.nth_index_in_set(local_index -
902 }
903
904
905
906 inline const IndexSet &
908 {
909 return ghost_indices_data;
910 }
911
912
913
914 inline unsigned int
916 {
918 }
919
920
921
922 inline const std::vector<std::pair<unsigned int, unsigned int>> &
924 {
926 }
927
928
929
930 inline const std::vector<std::pair<unsigned int, unsigned int>> &
932 {
933 return ghost_targets_data;
934 }
935
936
937 inline const std::vector<std::pair<unsigned int, unsigned int>> &
939 {
940 return import_indices_data;
941 }
942
943
944
945 inline unsigned int
947 {
949 }
950
951
952
953 inline const std::vector<std::pair<unsigned int, unsigned int>> &
955 {
956 return import_targets_data;
957 }
958
959
960
961 inline unsigned int
963 {
964 // return the id from the variable stored in this class instead of
965 // Utilities::MPI::this_mpi_process() in order to make this query also
966 // work when MPI is not initialized.
967 return my_pid;
968 }
969
970
971
972 inline unsigned int
974 {
975 // return the number of MPI processes from the variable stored in this
976 // class instead of Utilities::MPI::n_mpi_processes() in order to make
977 // this query also work when MPI is not initialized.
978 return n_procs;
979 }
980
981
982
983 inline const MPI_Comm &
985 {
986 return communicator;
987 }
988
989
990
991 inline bool
993 {
994 return have_ghost_indices;
995 }
996
997#endif // ifndef DOXYGEN
998
999 } // end of namespace MPI
1000
1001} // end of namespace Utilities
1002
1003
1005
1006#endif
size_type index_within_set(const size_type global_index) const
Definition: index_set.h:1921
bool is_element(const size_type index) const
Definition: index_set.h:1765
size_type nth_index_in_set(const size_type local_index) const
Definition: index_set.h:1880
unsigned int n_ghost_indices_data
Definition: partitioner.h:709
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< std::pair< unsigned int, unsigned int > > import_indices_data
Definition: partitioner.h:723
bool is_globally_compatible(const Partitioner &part) const
Partitioner(const IndexSet &locally_owned_indices, const IndexSet &ghost_indices_in, const MPI_Comm &communicator_in)
void set_owned_indices(const IndexSet &locally_owned_indices)
Partitioner(const types::global_dof_index local_size, const types::global_dof_index ghost_size, const MPI_Comm &communicator)
const IndexSet & locally_owned_range() const
unsigned int n_ghost_indices_in_larger_set
Definition: partitioner.h:761
unsigned int n_ghost_indices() const
std::vector< std::pair< unsigned int, unsigned int > > ghost_targets_data
Definition: partitioner.h:715
unsigned int local_size() const
virtual void reinit(const IndexSet &vector_space_vector_index_set, const IndexSet &read_write_vector_index_set, const MPI_Comm &communicator) override
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
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
Partitioner(const IndexSet &locally_owned_indices, const MPI_Comm &communicator_in)
const std::vector< std::pair< unsigned int, unsigned int > > & import_targets() const
std::vector< std::pair< std::unique_ptr< unsigned int[], void(*)(unsigned int *)>, unsigned int > > import_indices_plain_dev
Definition: partitioner.h:737
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
Definition: partitioner.h:685
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
Definition: partitioner.h:697
std::vector< unsigned int > import_indices_chunks_by_rank_data
Definition: partitioner.h:755
unsigned int n_import_indices_data
Definition: partitioner.h:743
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
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
Definition: partitioner.h:767
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
virtual const MPI_Comm & get_mpi_communicator() const override
std::vector< std::pair< unsigned int, unsigned int > > import_targets_data
Definition: partitioner.h:749
types::global_dof_index size() const
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
Definition: partitioner.h:775
bool ghost_indices_initialized() const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:402
#define DEAL_II_DEPRECATED_EARLY
Definition: config.h:170
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:403
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
Definition: exceptions.h:1465
static ::ExceptionBase & ExcIndexNotPresent(types::global_dof_index arg1, unsigned int arg2)
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:538
static ::ExceptionBase & ExcGhostIndexArrayHasWrongSize(unsigned int arg1, unsigned int arg2, unsigned int arg3)
#define AssertIndexRange(index, range)
Definition: exceptions.h:1690
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:561
TrilinosWrappers::types::int_type global_index(const Epetra_BlockMap &map, const ::types::global_dof_index i)
static const unsigned int invalid_unsigned_int
Definition: types.h:196
unsigned int global_dof_index
Definition: types.h:76