Reference documentation for deal.II version 9.2.0
\(\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 - 2020 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 
22 #include <deal.II/base/index_set.h>
25 #include <deal.II/base/mpi.h>
26 #include <deal.II/base/types.h>
27 #include <deal.II/base/utilities.h>
28 
30 #include <deal.II/lac/vector.h>
32 
33 #include <limits>
34 
35 
37 
38 namespace Utilities
39 {
40  namespace MPI
41  {
196  {
197  public:
201  Partitioner();
202 
207  Partitioner(const unsigned int size);
208 
216  Partitioner(const IndexSet &locally_owned_indices,
217  const IndexSet &ghost_indices_in,
218  const MPI_Comm communicator_in);
219 
227  Partitioner(const IndexSet &locally_owned_indices,
228  const MPI_Comm communicator_in);
229 
237  virtual void
238  reinit(const IndexSet &vector_space_vector_index_set,
239  const IndexSet &read_write_vector_index_set,
240  const MPI_Comm &communicator) override;
241 
245  void
246  set_owned_indices(const IndexSet &locally_owned_indices);
247 
258  void
260  const IndexSet &larger_ghost_index_set = IndexSet());
261 
266  size() const;
267 
272  unsigned int
273  local_size() const;
274 
281  const IndexSet &
282  locally_owned_range() const;
283 
289  std::pair<types::global_dof_index, types::global_dof_index>
290  local_range() const;
291 
296  bool
298 
309  unsigned int
311 
320  local_to_global(const unsigned int local_index) const;
321 
327  bool
329 
333  const IndexSet &
334  ghost_indices() const;
335 
340  unsigned int
341  n_ghost_indices() const;
342 
353  const std::vector<std::pair<unsigned int, unsigned int>> &
355 
361  const std::vector<std::pair<unsigned int, unsigned int>> &
362  ghost_targets() const;
363 
372  const std::vector<std::pair<unsigned int, unsigned int>> &
373  import_indices() const;
374 
379  unsigned int
380  n_import_indices() const;
381 
391  const std::vector<std::pair<unsigned int, unsigned int>> &
392  import_targets() const;
393 
404  bool
405  is_compatible(const Partitioner &part) const;
406 
423  bool
424  is_globally_compatible(const Partitioner &part) const;
425 
430  unsigned int
431  this_mpi_process() const;
432 
437  unsigned int
438  n_mpi_processes() const;
439 
443  virtual const MPI_Comm &
444  get_mpi_communicator() const override;
445 
451  bool
453 
454 #ifdef DEAL_II_WITH_MPI
455 
490  template <typename Number, typename MemorySpaceType = MemorySpace::Host>
491  void
493  const unsigned int communication_channel,
494  const ArrayView<const Number, MemorySpaceType> &locally_owned_array,
495  const ArrayView<Number, MemorySpaceType> & temporary_storage,
496  const ArrayView<Number, MemorySpaceType> & ghost_array,
497  std::vector<MPI_Request> & requests) const;
498 
516  template <typename Number, typename MemorySpaceType = MemorySpace::Host>
517  void
519  const ArrayView<Number, MemorySpaceType> &ghost_array,
520  std::vector<MPI_Request> & requests) const;
521 
559  template <typename Number, typename MemorySpaceType = MemorySpace::Host>
560  void
562  const VectorOperation::values vector_operation,
563  const unsigned int communication_channel,
564  const ArrayView<Number, MemorySpaceType> &ghost_array,
565  const ArrayView<Number, MemorySpaceType> &temporary_storage,
566  std::vector<MPI_Request> & requests) const;
567 
602  template <typename Number, typename MemorySpaceType = MemorySpace::Host>
603  void
605  const VectorOperation::values vector_operation,
606  const ArrayView<const Number, MemorySpaceType> &temporary_storage,
607  const ArrayView<Number, MemorySpaceType> & locally_owned_storage,
608  const ArrayView<Number, MemorySpaceType> & ghost_array,
609  std::vector<MPI_Request> & requests) const;
610 #endif
611 
615  std::size_t
616  memory_consumption() const;
617 
623  unsigned int,
624  << "Global index " << arg1
625  << " neither owned nor ghost on proc " << arg2 << ".");
626 
631  unsigned int,
632  unsigned int,
633  unsigned int,
634  << "The size of the ghost index array (" << arg1
635  << ") must either equal the number of ghost in the "
636  << "partitioner (" << arg2
637  << ") or be equal in size to a more comprehensive index"
638  << "set which contains " << arg3
639  << " elements for this partitioner.");
640 
641  private:
646  void
648 
653 
658 
663  std::pair<types::global_dof_index, types::global_dof_index>
665 
671 
676  unsigned int n_ghost_indices_data;
677 
682  std::vector<std::pair<unsigned int, unsigned int>> ghost_targets_data;
683 
690  std::vector<std::pair<unsigned int, unsigned int>> import_indices_data;
691 
698  // The variable is mutable to enable lazy initialization in
699  // export_to_ghosted_array_start(). This way partitioner does not have to
700  // be templated on the MemorySpaceType.
701  mutable std::vector<
702  std::pair<std::unique_ptr<unsigned int[], void (*)(unsigned int *)>,
703  unsigned int>>
705 
710  unsigned int n_import_indices_data;
711 
716  std::vector<std::pair<unsigned int, unsigned int>> import_targets_data;
717 
722  std::vector<unsigned int> import_indices_chunks_by_rank_data;
723 
729 
734  std::vector<unsigned int> ghost_indices_subset_chunks_by_rank_data;
735 
741  std::vector<std::pair<unsigned int, unsigned int>>
743 
747  unsigned int my_pid;
748 
752  unsigned int n_procs;
753 
758 
763  };
764 
765 
766 
767  /*--------------------- Inline functions --------------------------------*/
768 
769 #ifndef DOXYGEN
770 
772  Partitioner::size() const
773  {
774  return global_size;
775  }
776 
777 
778 
779  inline const IndexSet &
781  {
783  }
784 
785 
786 
787  inline std::pair<types::global_dof_index, types::global_dof_index>
789  {
790  return local_range_data;
791  }
792 
793 
794 
795  inline unsigned int
797  {
799  local_range_data.second - local_range_data.first;
802  return static_cast<unsigned int>(size);
803  }
804 
805 
806 
807  inline bool
810  {
811  return (local_range_data.first <= global_index &&
812  global_index < local_range_data.second);
813  }
814 
815 
816 
817  inline bool
820  {
821  // if the index is in the global range, it is trivially not a ghost
822  if (in_local_range(global_index) == true)
823  return false;
824  else
826  }
827 
828 
829 
830  inline unsigned int
833  {
837  return static_cast<unsigned int>(global_index - local_range_data.first);
838  else if (is_ghost_entry(global_index))
839  return (local_size() +
840  static_cast<unsigned int>(
842  else
843  // should only end up here in optimized mode, when we use this large
844  // number to trigger a segfault when using this method for array
845  // access
847  }
848 
849 
850 
852  Partitioner::local_to_global(const unsigned int local_index) const
853  {
855  if (local_index < local_size())
856  return local_range_data.first + types::global_dof_index(local_index);
857  else
858  return ghost_indices_data.nth_index_in_set(local_index - local_size());
859  }
860 
861 
862 
863  inline const IndexSet &
865  {
866  return ghost_indices_data;
867  }
868 
869 
870 
871  inline unsigned int
873  {
874  return n_ghost_indices_data;
875  }
876 
877 
878 
879  inline const std::vector<std::pair<unsigned int, unsigned int>> &
881  {
883  }
884 
885 
886 
887  inline const std::vector<std::pair<unsigned int, unsigned int>> &
889  {
890  return ghost_targets_data;
891  }
892 
893 
894  inline const std::vector<std::pair<unsigned int, unsigned int>> &
896  {
897  return import_indices_data;
898  }
899 
900 
901 
902  inline unsigned int
904  {
905  return n_import_indices_data;
906  }
907 
908 
909 
910  inline const std::vector<std::pair<unsigned int, unsigned int>> &
912  {
913  return import_targets_data;
914  }
915 
916 
917 
918  inline unsigned int
920  {
921  // return the id from the variable stored in this class instead of
922  // Utilities::MPI::this_mpi_process() in order to make this query also
923  // work when MPI is not initialized.
924  return my_pid;
925  }
926 
927 
928 
929  inline unsigned int
931  {
932  // return the number of MPI processes from the variable stored in this
933  // class instead of Utilities::MPI::n_mpi_processes() in order to make
934  // this query also work when MPI is not initialized.
935  return n_procs;
936  }
937 
938 
939 
940  inline const MPI_Comm &
942  {
943  return communicator;
944  }
945 
946 
947 
948  inline bool
950  {
951  return have_ghost_indices;
952  }
953 
954 #endif // ifndef DOXYGEN
955 
956  } // end of namespace MPI
957 
958 } // end of namespace Utilities
959 
960 
962 
963 #endif
array_view.h
Utilities::MPI::Partitioner::n_ghost_indices_in_larger_set
unsigned int n_ghost_indices_in_larger_set
Definition: partitioner.h:728
Utilities::MPI::Partitioner::set_ghost_indices
void set_ghost_indices(const IndexSet &ghost_indices, const IndexSet &larger_ghost_index_set=IndexSet())
Definition: partitioner.cc:152
IndexSet
Definition: index_set.h:74
Utilities::MPI::Partitioner::n_mpi_processes
unsigned int n_mpi_processes() const
Utilities::MPI::Partitioner::Partitioner
Partitioner()
Definition: partitioner.cc:26
Utilities::MPI::Partitioner
Definition: partitioner.h:195
types.h
Utilities::MPI::Partitioner::is_ghost_entry
bool is_ghost_entry(const types::global_dof_index global_index) const
StandardExceptions::ExcNotImplemented
static ::ExceptionBase & ExcNotImplemented()
Utilities::MPI::Partitioner::import_targets_data
std::vector< std::pair< unsigned int, unsigned int > > import_targets_data
Definition: partitioner.h:716
ArrayView
Definition: array_view.h:77
memory_consumption.h
utilities.h
AssertIndexRange
#define AssertIndexRange(index, range)
Definition: exceptions.h:1649
MPI_Comm
Utilities::MPI::Partitioner::global_size
types::global_dof_index global_size
Definition: partitioner.h:652
Utilities::MPI::Partitioner::size
types::global_dof_index size() const
Utilities::MPI::Partitioner::ExcIndexNotPresent
static ::ExceptionBase & ExcIndexNotPresent(types::global_dof_index arg1, unsigned int arg2)
Utilities::MPI::Partitioner::n_import_indices_data
unsigned int n_import_indices_data
Definition: partitioner.h:710
Utilities::MPI::Partitioner::import_indices_data
std::vector< std::pair< unsigned int, unsigned int > > import_indices_data
Definition: partitioner.h:690
Utilities::MPI::Partitioner::import_indices
const std::vector< std::pair< unsigned int, unsigned int > > & import_indices() const
Utilities::MPI::Partitioner::ghost_targets_data
std::vector< std::pair< unsigned int, unsigned int > > ghost_targets_data
Definition: partitioner.h:682
Utilities::MPI::Partitioner::have_ghost_indices
bool have_ghost_indices
Definition: partitioner.h:762
Utilities::MPI::Partitioner::export_to_ghosted_array_finish
void export_to_ghosted_array_finish(const ArrayView< Number, MemorySpaceType > &ghost_array, std::vector< MPI_Request > &requests) const
Utilities::MPI::Partitioner::ghost_indices_within_larger_ghost_set
const std::vector< std::pair< unsigned int, unsigned int > > & ghost_indices_within_larger_ghost_set() const
Utilities::MPI::Partitioner::n_ghost_indices_data
unsigned int n_ghost_indices_data
Definition: partitioner.h:676
Utilities::MPI::Partitioner::in_local_range
bool in_local_range(const types::global_dof_index global_index) const
vector_operation.h
Utilities::MPI::Partitioner::set_owned_indices
void set_owned_indices(const IndexSet &locally_owned_indices)
Definition: partitioner.cc:111
communication_pattern_base.h
types::global_dof_index
unsigned int global_dof_index
Definition: types.h:76
Utilities::MPI::Partitioner::ghost_indices_subset_data
std::vector< std::pair< unsigned int, unsigned int > > ghost_indices_subset_data
Definition: partitioner.h:742
Utilities::MPI::Partitioner::is_compatible
bool is_compatible(const Partitioner &part) const
Definition: partitioner.cc:435
Utilities::MPI::Partitioner::memory_consumption
std::size_t memory_consumption() const
Definition: partitioner.cc:471
Utilities::MPI::Partitioner::this_mpi_process
unsigned int this_mpi_process() const
mpi.h
index_set.h
Utilities::MPI::Partitioner::n_ghost_indices
unsigned int n_ghost_indices() const
DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
Utilities::MPI::Partitioner::ghost_indices_subset_chunks_by_rank_data
std::vector< unsigned int > ghost_indices_subset_chunks_by_rank_data
Definition: partitioner.h:734
DeclException3
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:564
IndexSet::is_element
bool is_element(const size_type index) const
Definition: index_set.h:1766
Utilities::MPI::Partitioner::import_from_ghosted_array_start
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
VectorOperation::values
values
Definition: vector_operation.h:40
Utilities::MPI::Partitioner::locally_owned_range_data
IndexSet locally_owned_range_data
Definition: partitioner.h:657
Utilities::MPI::Partitioner::n_import_indices
unsigned int n_import_indices() const
Utilities::MPI::Partitioner::global_to_local
unsigned int global_to_local(const types::global_dof_index global_index) const
Utilities::MPI::Partitioner::local_size
unsigned int local_size() const
unsigned int
Utilities::MPI::Partitioner::communicator
MPI_Comm communicator
Definition: partitioner.h:757
Utilities::MPI::Partitioner::is_globally_compatible
bool is_globally_compatible(const Partitioner &part) const
Definition: partitioner.cc:462
Assert
#define Assert(cond, exc)
Definition: exceptions.h:1419
IndexSet::nth_index_in_set
size_type nth_index_in_set(const size_type local_index) const
Definition: index_set.h:1881
Utilities::MPI::Partitioner::ghost_indices_data
IndexSet ghost_indices_data
Definition: partitioner.h:670
Utilities::MPI::Partitioner::ghost_targets
const std::vector< std::pair< unsigned int, unsigned int > > & ghost_targets() const
vector.h
Utilities::MPI::Partitioner::export_to_ghosted_array_start
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
Utilities::MPI::Partitioner::import_targets
const std::vector< std::pair< unsigned int, unsigned int > > & import_targets() const
numbers::invalid_unsigned_int
static const unsigned int invalid_unsigned_int
Definition: types.h:191
Utilities::MPI::Partitioner::local_range
std::pair< types::global_dof_index, types::global_dof_index > local_range() const
Utilities::MPI::Partitioner::import_indices_plain_dev
std::vector< std::pair< std::unique_ptr< unsigned int[], void(*)(unsigned int *)>, unsigned int > > import_indices_plain_dev
Definition: partitioner.h:704
Utilities::MPI::Partitioner::reinit
virtual void reinit(const IndexSet &vector_space_vector_index_set, const IndexSet &read_write_vector_index_set, const MPI_Comm &communicator) override
Definition: partitioner.cc:98
memory_space.h
IndexSet::index_within_set
size_type index_within_set(const size_type global_index) const
Definition: index_set.h:1922
config.h
Utilities::MPI::Partitioner::ExcGhostIndexArrayHasWrongSize
static ::ExceptionBase & ExcGhostIndexArrayHasWrongSize(unsigned int arg1, unsigned int arg2, unsigned int arg3)
Utilities::MPI::Partitioner::n_procs
unsigned int n_procs
Definition: partitioner.h:752
Utilities::MPI::Partitioner::ghost_indices
const IndexSet & ghost_indices() const
Utilities::MPI::Partitioner::local_to_global
types::global_dof_index local_to_global(const unsigned int local_index) const
Utilities::MPI::Partitioner::my_pid
unsigned int my_pid
Definition: partitioner.h:747
DEAL_II_NAMESPACE_CLOSE
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
Utilities::MPI::Partitioner::locally_owned_range
const IndexSet & locally_owned_range() const
Utilities::MPI::Partitioner::import_from_ghosted_array_finish
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
TrilinosWrappers::global_index
TrilinosWrappers::types::int_type global_index(const Epetra_BlockMap &map, const ::types::global_dof_index i)
Definition: trilinos_index_access.h:82
DeclException2
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:541
Utilities::MPI::Partitioner::initialize_import_indices_plain_dev
void initialize_import_indices_plain_dev() const
LinearAlgebra::CommunicationPatternBase
Definition: communication_pattern_base.h:42
Utilities
Definition: cuda.h:31
Utilities::MPI::Partitioner::ghost_indices_initialized
bool ghost_indices_initialized() const
Utilities::MPI::Partitioner::import_indices_chunks_by_rank_data
std::vector< unsigned int > import_indices_chunks_by_rank_data
Definition: partitioner.h:722
Utilities::MPI::max
T max(const T &t, const MPI_Comm &mpi_communicator)
Utilities::MPI::Partitioner::local_range_data
std::pair< types::global_dof_index, types::global_dof_index > local_range_data
Definition: partitioner.h:664
Utilities::MPI::Partitioner::get_mpi_communicator
virtual const MPI_Comm & get_mpi_communicator() const override