Reference documentation for deal.II version GIT d77e5ebb0a 2023-01-27 22:35:02+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\}}\)
partitioner.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2011 - 2022 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 
23 #include <deal.II/base/index_set.h>
25 #include <deal.II/base/mpi_stub.h>
26 #include <deal.II/base/types.h>
27 
29 
30 #include <limits>
31 #include <memory>
32 
34 
35 namespace Utilities
36 {
37  namespace MPI
38  {
192  {
193  public:
198 
203  Partitioner(const unsigned int size);
204 
220  const types::global_dof_index ghost_size,
221  const MPI_Comm & communicator);
222 
230  Partitioner(const IndexSet &locally_owned_indices,
231  const IndexSet &ghost_indices_in,
232  const MPI_Comm &communicator_in);
233 
241  Partitioner(const IndexSet &locally_owned_indices,
242  const MPI_Comm &communicator_in);
243 
251  virtual void
252  reinit(const IndexSet &vector_space_vector_index_set,
253  const IndexSet &read_write_vector_index_set,
254  const MPI_Comm &communicator) override;
255 
259  void
260  set_owned_indices(const IndexSet &locally_owned_indices);
261 
272  void
274  const IndexSet &larger_ghost_index_set = IndexSet());
275 
280  size() const;
281 
292  unsigned int
293  local_size() const;
294 
301  unsigned int
303 
310  const IndexSet &
312 
318  std::pair<types::global_dof_index, types::global_dof_index>
319  local_range() const;
320 
325  bool
327 
338  unsigned int
340 
350  local_to_global(const unsigned int local_index) const;
351 
357  bool
359 
363  const IndexSet &
364  ghost_indices() const;
365 
370  unsigned int
372 
383  const std::vector<std::pair<unsigned int, unsigned int>> &
385 
391  const std::vector<std::pair<unsigned int, unsigned int>> &
392  ghost_targets() const;
393 
402  const std::vector<std::pair<unsigned int, unsigned int>> &
403  import_indices() const;
404 
409  unsigned int
411 
421  const std::vector<std::pair<unsigned int, unsigned int>> &
422  import_targets() const;
423 
434  bool
435  is_compatible(const Partitioner &part) const;
436 
453  bool
455 
460  unsigned int
462 
467  unsigned int
469 
473  virtual const MPI_Comm &
474  get_mpi_communicator() const override;
475 
481  bool
483 
484 #ifdef DEAL_II_WITH_MPI
520  template <typename Number, typename MemorySpaceType = MemorySpace::Host>
521  void
523  const unsigned int communication_channel,
524  const ArrayView<const Number, MemorySpaceType> &locally_owned_array,
525  const ArrayView<Number, MemorySpaceType> & temporary_storage,
526  const ArrayView<Number, MemorySpaceType> & ghost_array,
527  std::vector<MPI_Request> & requests) const;
528 
546  template <typename Number, typename MemorySpaceType = MemorySpace::Host>
547  void
549  const ArrayView<Number, MemorySpaceType> &ghost_array,
550  std::vector<MPI_Request> & requests) const;
551 
589  template <typename Number, typename MemorySpaceType = MemorySpace::Host>
590  void
592  const VectorOperation::values vector_operation,
593  const unsigned int communication_channel,
594  const ArrayView<Number, MemorySpaceType> &ghost_array,
595  const ArrayView<Number, MemorySpaceType> &temporary_storage,
596  std::vector<MPI_Request> & requests) const;
597 
632  template <typename Number, typename MemorySpaceType = MemorySpace::Host>
633  void
635  const VectorOperation::values vector_operation,
636  const ArrayView<const Number, MemorySpaceType> &temporary_storage,
637  const ArrayView<Number, MemorySpaceType> & locally_owned_storage,
638  const ArrayView<Number, MemorySpaceType> & ghost_array,
639  std::vector<MPI_Request> & requests) const;
640 #endif
641 
645  std::size_t
647 
653  unsigned int,
654  << "Global index " << arg1
655  << " neither owned nor ghost on proc " << arg2 << '.');
656 
661  unsigned int,
662  unsigned int,
663  unsigned int,
664  << "The size of the ghost index array (" << arg1
665  << ") must either equal the number of ghost in the "
666  << "partitioner (" << arg2
667  << ") or be equal in size to a more comprehensive index"
668  << "set which contains " << arg3
669  << " elements for this partitioner.");
670 
671  private:
676  void
678 
683 
688 
693  std::pair<types::global_dof_index, types::global_dof_index>
695 
701 
706  unsigned int n_ghost_indices_data;
707 
712  std::vector<std::pair<unsigned int, unsigned int>> ghost_targets_data;
713 
720  std::vector<std::pair<unsigned int, unsigned int>> import_indices_data;
721 
728  // The variable is mutable to enable lazy initialization in
729  // export_to_ghosted_array_start().
730  mutable std::vector<
731  Kokkos::View<unsigned int *, MemorySpace::Default::kokkos_space>>
733 
738  unsigned int n_import_indices_data;
739 
744  std::vector<std::pair<unsigned int, unsigned int>> import_targets_data;
745 
750  std::vector<unsigned int> import_indices_chunks_by_rank_data;
751 
757 
762  std::vector<unsigned int> ghost_indices_subset_chunks_by_rank_data;
763 
769  std::vector<std::pair<unsigned int, unsigned int>>
771 
775  unsigned int my_pid;
776 
780  unsigned int n_procs;
781 
785  MPI_Comm communicator;
786 
791  };
792 
793 
794 
795  /*--------------------- Inline functions --------------------------------*/
796 
797 #ifndef DOXYGEN
798 
800  Partitioner::size() const
801  {
802  return global_size;
803  }
804 
805 
806 
807  inline const IndexSet &
809  {
811  }
812 
813 
814 
815  inline std::pair<types::global_dof_index, types::global_dof_index>
817  {
818  return local_range_data;
819  }
820 
821 
822 
823  inline unsigned int
825  {
826  return locally_owned_size();
827  }
828 
829 
830 
831  inline unsigned int
833  {
835  local_range_data.second - local_range_data.first;
838  return static_cast<unsigned int>(size);
839  }
840 
841 
842 
843  inline bool
846  {
847  return (local_range_data.first <= global_index &&
848  global_index < local_range_data.second);
849  }
850 
851 
852 
853  inline bool
856  {
857  // if the index is in the global range, it is trivially not a ghost
858  if (in_local_range(global_index) == true)
859  return false;
860  else
862  }
863 
864 
865 
866  inline unsigned int
869  {
873  return static_cast<unsigned int>(global_index - local_range_data.first);
874  else
875  {
876  // avoid checking the ghost index set via a binary search twice by
877  // querying the index within set, which returns invalid_dof_index
878  // for non-existent entries
879  const types::global_dof_index index_within_ghosts =
881  if (index_within_ghosts == numbers::invalid_dof_index)
883  else
884  return locally_owned_size() +
885  static_cast<unsigned int>(index_within_ghosts);
886  }
887  }
888 
889 
890 
892  Partitioner::local_to_global(const unsigned int local_index) const
893  {
894  AssertIndexRange(local_index,
896  if (local_index < locally_owned_size())
897  return local_range_data.first + types::global_dof_index(local_index);
898  else
899  return ghost_indices_data.nth_index_in_set(local_index -
901  }
902 
903 
904 
905  inline const IndexSet &
907  {
908  return ghost_indices_data;
909  }
910 
911 
912 
913  inline unsigned int
915  {
916  return n_ghost_indices_data;
917  }
918 
919 
920 
921  inline const std::vector<std::pair<unsigned int, unsigned int>> &
923  {
925  }
926 
927 
928 
929  inline const std::vector<std::pair<unsigned int, unsigned int>> &
931  {
932  return ghost_targets_data;
933  }
934 
935 
936  inline const std::vector<std::pair<unsigned int, unsigned int>> &
938  {
939  return import_indices_data;
940  }
941 
942 
943 
944  inline unsigned int
946  {
947  return n_import_indices_data;
948  }
949 
950 
951 
952  inline const std::vector<std::pair<unsigned int, unsigned int>> &
954  {
955  return import_targets_data;
956  }
957 
958 
959 
960  inline unsigned int
962  {
963  // return the id from the variable stored in this class instead of
964  // Utilities::MPI::this_mpi_process() in order to make this query also
965  // work when MPI is not initialized.
966  return my_pid;
967  }
968 
969 
970 
971  inline unsigned int
973  {
974  // return the number of MPI processes from the variable stored in this
975  // class instead of Utilities::MPI::n_mpi_processes() in order to make
976  // this query also work when MPI is not initialized.
977  return n_procs;
978  }
979 
980 
981 
982  inline const MPI_Comm &
984  {
985  return communicator;
986  }
987 
988 
989 
990  inline bool
992  {
993  return have_ghost_indices;
994  }
995 
996 #endif // ifndef DOXYGEN
997 
998  } // end of namespace MPI
999 
1000 } // end of namespace Utilities
1001 
1002 
1004 
1005 #endif
size_type index_within_set(const size_type global_index) const
Definition: index_set.h:1856
bool is_element(const size_type index) const
Definition: index_set.h:1749
size_type nth_index_in_set(const size_type local_index) const
Definition: index_set.h:1837
const std::vector< std::pair< unsigned int, unsigned int > > & ghost_targets() const
unsigned int n_ghost_indices_data
Definition: partitioner.h:706
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
Definition: partitioner.h:732
std::vector< std::pair< unsigned int, unsigned int > > import_indices_data
Definition: partitioner.h:720
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 std::vector< std::pair< unsigned int, unsigned int > > & import_indices() const
unsigned int n_ghost_indices_in_larger_set
Definition: partitioner.h:756
unsigned int n_ghost_indices() const
std::vector< std::pair< unsigned int, unsigned int > > ghost_targets_data
Definition: partitioner.h:712
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
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)
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:682
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:694
std::vector< unsigned int > import_indices_chunks_by_rank_data
Definition: partitioner.h:750
unsigned int n_import_indices_data
Definition: partitioner.h:738
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
unsigned int n_import_indices() const
std::vector< unsigned int > ghost_indices_subset_chunks_by_rank_data
Definition: partitioner.h:762
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:744
types::global_dof_index size() const
const IndexSet & locally_owned_range() 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:770
bool ghost_indices_initialized() const
std::pair< types::global_dof_index, types::global_dof_index > local_range() const
const std::vector< std::pair< unsigned int, unsigned int > > & import_targets() const
const IndexSet & ghost_indices() const
#define DEAL_II_DEPRECATED
Definition: config.h:162
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:461
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:462
static ::ExceptionBase & ExcGhostIndexArrayHasWrongSize(unsigned int arg1, unsigned int arg2, unsigned int arg3)
#define Assert(cond, exc)
Definition: exceptions.h:1509
static ::ExceptionBase & ExcNotImplemented()
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:532
#define AssertIndexRange(index, range)
Definition: exceptions.h:1768
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:555
static ::ExceptionBase & ExcIndexNotPresent(types::global_dof_index arg1, unsigned int arg2)
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:206
const types::global_dof_index invalid_dof_index
Definition: types.h:226
unsigned int global_dof_index
Definition: types.h:81