Reference documentation for deal.II version Git 67353a5f2d 2021-01-26 18:33:38 +0100
\(\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  {
194  {
195  public:
199  Partitioner();
200 
205  Partitioner(const unsigned int size);
206 
222  const types::global_dof_index ghost_size,
223  const MPI_Comm & communicator);
224 
232  Partitioner(const IndexSet &locally_owned_indices,
233  const IndexSet &ghost_indices_in,
234  const MPI_Comm &communicator_in);
235 
243  Partitioner(const IndexSet &locally_owned_indices,
244  const MPI_Comm &communicator_in);
245 
253  virtual void
254  reinit(const IndexSet &vector_space_vector_index_set,
255  const IndexSet &read_write_vector_index_set,
256  const MPI_Comm &communicator) override;
257 
261  void
262  set_owned_indices(const IndexSet &locally_owned_indices);
263 
274  void
276  const IndexSet &larger_ghost_index_set = IndexSet());
277 
282  size() const;
283 
288  unsigned int
289  local_size() const;
290 
297  const IndexSet &
298  locally_owned_range() const;
299 
305  std::pair<types::global_dof_index, types::global_dof_index>
306  local_range() const;
307 
312  bool
314 
325  unsigned int
326  global_to_local(const types::global_dof_index global_index) const;
327 
336  local_to_global(const unsigned int local_index) const;
337 
343  bool
344  is_ghost_entry(const types::global_dof_index global_index) const;
345 
349  const IndexSet &
350  ghost_indices() const;
351 
356  unsigned int
357  n_ghost_indices() const;
358 
369  const std::vector<std::pair<unsigned int, unsigned int>> &
371 
377  const std::vector<std::pair<unsigned int, unsigned int>> &
378  ghost_targets() const;
379 
388  const std::vector<std::pair<unsigned int, unsigned int>> &
389  import_indices() const;
390 
395  unsigned int
396  n_import_indices() const;
397 
407  const std::vector<std::pair<unsigned int, unsigned int>> &
408  import_targets() const;
409 
420  bool
421  is_compatible(const Partitioner &part) const;
422 
439  bool
440  is_globally_compatible(const Partitioner &part) const;
441 
446  unsigned int
447  this_mpi_process() const;
448 
453  unsigned int
454  n_mpi_processes() const;
455 
459  virtual const MPI_Comm &
460  get_mpi_communicator() const override;
461 
467  bool
469 
470 #ifdef DEAL_II_WITH_MPI
471 
506  template <typename Number, typename MemorySpaceType = MemorySpace::Host>
507  void
509  const unsigned int communication_channel,
510  const ArrayView<const Number, MemorySpaceType> &locally_owned_array,
511  const ArrayView<Number, MemorySpaceType> & temporary_storage,
512  const ArrayView<Number, MemorySpaceType> & ghost_array,
513  std::vector<MPI_Request> & requests) const;
514 
532  template <typename Number, typename MemorySpaceType = MemorySpace::Host>
533  void
535  const ArrayView<Number, MemorySpaceType> &ghost_array,
536  std::vector<MPI_Request> & requests) const;
537 
575  template <typename Number, typename MemorySpaceType = MemorySpace::Host>
576  void
578  const VectorOperation::values vector_operation,
579  const unsigned int communication_channel,
580  const ArrayView<Number, MemorySpaceType> &ghost_array,
581  const ArrayView<Number, MemorySpaceType> &temporary_storage,
582  std::vector<MPI_Request> & requests) const;
583 
618  template <typename Number, typename MemorySpaceType = MemorySpace::Host>
619  void
621  const VectorOperation::values vector_operation,
622  const ArrayView<const Number, MemorySpaceType> &temporary_storage,
623  const ArrayView<Number, MemorySpaceType> & locally_owned_storage,
624  const ArrayView<Number, MemorySpaceType> & ghost_array,
625  std::vector<MPI_Request> & requests) const;
626 #endif
627 
631  std::size_t
632  memory_consumption() const;
633 
639  unsigned int,
640  << "Global index " << arg1
641  << " neither owned nor ghost on proc " << arg2 << ".");
642 
647  unsigned int,
648  unsigned int,
649  unsigned int,
650  << "The size of the ghost index array (" << arg1
651  << ") must either equal the number of ghost in the "
652  << "partitioner (" << arg2
653  << ") or be equal in size to a more comprehensive index"
654  << "set which contains " << arg3
655  << " elements for this partitioner.");
656 
657  private:
662  void
664 
669 
674 
679  std::pair<types::global_dof_index, types::global_dof_index>
681 
687 
692  unsigned int n_ghost_indices_data;
693 
698  std::vector<std::pair<unsigned int, unsigned int>> ghost_targets_data;
699 
706  std::vector<std::pair<unsigned int, unsigned int>> import_indices_data;
707 
714  // The variable is mutable to enable lazy initialization in
715  // export_to_ghosted_array_start(). This way partitioner does not have to
716  // be templated on the MemorySpaceType.
717  mutable std::vector<
718  std::pair<std::unique_ptr<unsigned int[], void (*)(unsigned int *)>,
719  unsigned int>>
721 
726  unsigned int n_import_indices_data;
727 
732  std::vector<std::pair<unsigned int, unsigned int>> import_targets_data;
733 
738  std::vector<unsigned int> import_indices_chunks_by_rank_data;
739 
745 
750  std::vector<unsigned int> ghost_indices_subset_chunks_by_rank_data;
751 
757  std::vector<std::pair<unsigned int, unsigned int>>
759 
763  unsigned int my_pid;
764 
768  unsigned int n_procs;
769 
774 
779  };
780 
781 
782 
783  /*--------------------- Inline functions --------------------------------*/
784 
785 #ifndef DOXYGEN
786 
788  Partitioner::size() const
789  {
790  return global_size;
791  }
792 
793 
794 
795  inline const IndexSet &
797  {
799  }
800 
801 
802 
803  inline std::pair<types::global_dof_index, types::global_dof_index>
805  {
806  return local_range_data;
807  }
808 
809 
810 
811  inline unsigned int
813  {
815  local_range_data.second - local_range_data.first;
818  return static_cast<unsigned int>(size);
819  }
820 
821 
822 
823  inline bool
826  {
827  return (local_range_data.first <= global_index &&
828  global_index < local_range_data.second);
829  }
830 
831 
832 
833  inline bool
835  const types::global_dof_index global_index) const
836  {
837  // if the index is in the global range, it is trivially not a ghost
838  if (in_local_range(global_index) == true)
839  return false;
840  else
841  return ghost_indices().is_element(global_index);
842  }
843 
844 
845 
846  inline unsigned int
848  const types::global_dof_index global_index) const
849  {
850  Assert(in_local_range(global_index) || is_ghost_entry(global_index),
851  ExcIndexNotPresent(global_index, my_pid));
852  if (in_local_range(global_index))
853  return static_cast<unsigned int>(global_index - local_range_data.first);
854  else if (is_ghost_entry(global_index))
855  return (local_size() +
856  static_cast<unsigned int>(
857  ghost_indices_data.index_within_set(global_index)));
858  else
859  // should only end up here in optimized mode, when we use this large
860  // number to trigger a segfault when using this method for array
861  // access
863  }
864 
865 
866 
868  Partitioner::local_to_global(const unsigned int local_index) const
869  {
871  if (local_index < local_size())
872  return local_range_data.first + types::global_dof_index(local_index);
873  else
874  return ghost_indices_data.nth_index_in_set(local_index - local_size());
875  }
876 
877 
878 
879  inline const IndexSet &
881  {
882  return ghost_indices_data;
883  }
884 
885 
886 
887  inline unsigned int
889  {
890  return n_ghost_indices_data;
891  }
892 
893 
894 
895  inline const std::vector<std::pair<unsigned int, unsigned int>> &
897  {
899  }
900 
901 
902 
903  inline const std::vector<std::pair<unsigned int, unsigned int>> &
905  {
906  return ghost_targets_data;
907  }
908 
909 
910  inline const std::vector<std::pair<unsigned int, unsigned int>> &
912  {
913  return import_indices_data;
914  }
915 
916 
917 
918  inline unsigned int
920  {
921  return n_import_indices_data;
922  }
923 
924 
925 
926  inline const std::vector<std::pair<unsigned int, unsigned int>> &
928  {
929  return import_targets_data;
930  }
931 
932 
933 
934  inline unsigned int
936  {
937  // return the id from the variable stored in this class instead of
938  // Utilities::MPI::this_mpi_process() in order to make this query also
939  // work when MPI is not initialized.
940  return my_pid;
941  }
942 
943 
944 
945  inline unsigned int
947  {
948  // return the number of MPI processes from the variable stored in this
949  // class instead of Utilities::MPI::n_mpi_processes() in order to make
950  // this query also work when MPI is not initialized.
951  return n_procs;
952  }
953 
954 
955 
956  inline const MPI_Comm &
958  {
959  return communicator;
960  }
961 
962 
963 
964  inline bool
966  {
967  return have_ghost_indices;
968  }
969 
970 #endif // ifndef DOXYGEN
971 
972  } // end of namespace MPI
973 
974 } // end of namespace Utilities
975 
976 
978 
979 #endif
std::vector< std::pair< unsigned int, unsigned int > > import_indices_data
Definition: partitioner.h:706
const IndexSet & locally_owned_range() const
bool is_globally_compatible(const Partitioner &part) const
Definition: partitioner.cc:494
static const unsigned int invalid_unsigned_int
Definition: types.h:196
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:538
bool is_compatible(const Partitioner &part) const
Definition: partitioner.cc:467
static ::ExceptionBase & ExcIndexNotPresent(types::global_dof_index arg1, unsigned int arg2)
unsigned int local_size() 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
virtual const MPI_Comm & get_mpi_communicator() const override
const std::vector< std::pair< unsigned int, unsigned int > > & import_indices() const
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
types::global_dof_index global_size
Definition: partitioner.h:668
types::global_dof_index local_to_global(const unsigned int local_index) const
#define AssertIndexRange(index, range)
Definition: exceptions.h:1691
unsigned int n_ghost_indices_data
Definition: partitioner.h:692
const std::vector< std::pair< unsigned int, unsigned int > > & ghost_indices_within_larger_ghost_set() 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
void set_owned_indices(const IndexSet &locally_owned_indices)
Definition: partitioner.cc:145
std::vector< unsigned int > ghost_indices_subset_chunks_by_rank_data
Definition: partitioner.h:750
std::vector< unsigned int > import_indices_chunks_by_rank_data
Definition: partitioner.h:738
bool ghost_indices_initialized() const
unsigned int this_mpi_process() const
const IndexSet & ghost_indices() const
unsigned int n_ghost_indices() const
std::pair< types::global_dof_index, types::global_dof_index > local_range() const
#define Assert(cond, exc)
Definition: exceptions.h:1466
size_type index_within_set(const size_type global_index) const
Definition: index_set.h:1921
unsigned int n_mpi_processes() const
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:380
std::vector< std::pair< unsigned int, unsigned int > > ghost_indices_subset_data
Definition: partitioner.h:758
const std::vector< std::pair< unsigned int, unsigned int > > & ghost_targets() const
unsigned int global_dof_index
Definition: types.h:76
Definition: cuda.h:32
types::global_dof_index size() const
std::size_t memory_consumption() const
Definition: partitioner.cc:503
void initialize_import_indices_plain_dev() const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:379
std::vector< std::pair< unsigned int, unsigned int > > import_targets_data
Definition: partitioner.h:732
std::pair< types::global_dof_index, types::global_dof_index > local_range_data
Definition: partitioner.h:680
std::vector< std::pair< unsigned int, unsigned int > > ghost_targets_data
Definition: partitioner.h:698
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
void export_to_ghosted_array_finish(const ArrayView< Number, MemorySpaceType > &ghost_array, std::vector< MPI_Request > &requests) const
static ::ExceptionBase & ExcNotImplemented()
TrilinosWrappers::types::int_type global_index(const Epetra_BlockMap &map, const ::types::global_dof_index i)
bool is_element(const size_type index) const
Definition: index_set.h:1765
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:561
std::vector< std::pair< std::unique_ptr< unsigned int[], void(*)(unsigned int *)>, unsigned int > > import_indices_plain_dev
Definition: partitioner.h:720
unsigned int n_import_indices() const
unsigned int n_import_indices_data
Definition: partitioner.h:726
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:132
bool is_ghost_entry(const types::global_dof_index global_index) const
size_type nth_index_in_set(const size_type local_index) const
Definition: index_set.h:1880
T max(const T &t, const MPI_Comm &mpi_communicator)
static ::ExceptionBase & ExcGhostIndexArrayHasWrongSize(unsigned int arg1, unsigned int arg2, unsigned int arg3)
unsigned int n_ghost_indices_in_larger_set
Definition: partitioner.h:744
void set_ghost_indices(const IndexSet &ghost_indices, const IndexSet &larger_ghost_index_set=IndexSet())
Definition: partitioner.cc:186