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
310  global_to_local(const types::global_dof_index global_index) const;
311 
320  local_to_global(const unsigned int local_index) const;
321 
327  bool
328  is_ghost_entry(const types::global_dof_index global_index) const;
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 
757  MPI_Comm communicator;
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
819  const types::global_dof_index global_index) const
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
825  return ghost_indices().is_element(global_index);
826  }
827 
828 
829 
830  inline unsigned int
832  const types::global_dof_index global_index) const
833  {
834  Assert(in_local_range(global_index) || is_ghost_entry(global_index),
835  ExcIndexNotPresent(global_index, my_pid));
836  if (in_local_range(global_index))
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>(
841  ghost_indices_data.index_within_set(global_index)));
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
std::vector< std::pair< unsigned int, unsigned int > > import_indices_data
Definition: partitioner.h:690
const IndexSet & locally_owned_range() const
bool is_globally_compatible(const Partitioner &part) const
Definition: partitioner.cc:462
static const unsigned int invalid_unsigned_int
Definition: types.h:191
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:541
bool is_compatible(const Partitioner &part) const
Definition: partitioner.cc:435
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:652
types::global_dof_index local_to_global(const unsigned int local_index) const
#define AssertIndexRange(index, range)
Definition: exceptions.h:1649
unsigned int n_ghost_indices_data
Definition: partitioner.h:676
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:111
std::vector< unsigned int > ghost_indices_subset_chunks_by_rank_data
Definition: partitioner.h:734
std::vector< unsigned int > import_indices_chunks_by_rank_data
Definition: partitioner.h:722
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:1419
size_type index_within_set(const size_type global_index) const
Definition: index_set.h:1922
unsigned int n_mpi_processes() const
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:359
std::vector< std::pair< unsigned int, unsigned int > > ghost_indices_subset_data
Definition: partitioner.h:742
const std::vector< std::pair< unsigned int, unsigned int > > & ghost_targets() const
unsigned int global_dof_index
Definition: types.h:76
Definition: cuda.h:31
types::global_dof_index size() const
std::size_t memory_consumption() const
Definition: partitioner.cc:471
void initialize_import_indices_plain_dev() const
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:358
std::vector< std::pair< unsigned int, unsigned int > > import_targets_data
Definition: partitioner.h:716
std::pair< types::global_dof_index, types::global_dof_index > local_range_data
Definition: partitioner.h:664
std::vector< std::pair< unsigned int, unsigned int > > ghost_targets_data
Definition: partitioner.h:682
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:1766
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:564
std::vector< std::pair< std::unique_ptr< unsigned int[], void(*)(unsigned int *)>, unsigned int > > import_indices_plain_dev
Definition: partitioner.h:704
unsigned int n_import_indices() const
unsigned int n_import_indices_data
Definition: partitioner.h:710
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
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:1881
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:728
void set_ghost_indices(const IndexSet &ghost_indices, const IndexSet &larger_ghost_index_set=IndexSet())
Definition: partitioner.cc:152