Reference documentation for deal.II version 9.1.0-pre
partitioner.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2011 - 2018 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 
21 #include <deal.II/base/array_view.h>
22 #include <deal.II/base/index_set.h>
23 #include <deal.II/base/memory_consumption.h>
24 #include <deal.II/base/mpi.h>
25 #include <deal.II/base/types.h>
26 #include <deal.II/base/utilities.h>
27 
28 #include <deal.II/lac/communication_pattern_base.h>
29 #include <deal.II/lac/vector.h>
30 #include <deal.II/lac/vector_operation.h>
31 
32 #include <limits>
33 
34 
35 DEAL_II_NAMESPACE_OPEN
36 
37 namespace Utilities
38 {
39  namespace MPI
40  {
127  {
128  public:
132  Partitioner();
133 
138  Partitioner(const unsigned int size);
139 
147  Partitioner(const IndexSet &locally_owned_indices,
148  const IndexSet &ghost_indices_in,
149  const MPI_Comm communicator_in);
150 
158  Partitioner(const IndexSet &locally_owned_indices,
159  const MPI_Comm communicator_in);
160 
168  virtual void
169  reinit(const IndexSet &vector_space_vector_index_set,
170  const IndexSet &read_write_vector_index_set,
171  const MPI_Comm &communicator) override;
172 
176  void
177  set_owned_indices(const IndexSet &locally_owned_indices);
178 
189  void
191  const IndexSet &larger_ghost_index_set = IndexSet());
192 
197  size() const;
198 
203  unsigned int
204  local_size() const;
205 
212  const IndexSet &
213  locally_owned_range() const;
214 
220  std::pair<types::global_dof_index, types::global_dof_index>
221  local_range() const;
222 
227  bool
228  in_local_range(const types::global_dof_index global_index) const;
229 
239  unsigned int
240  global_to_local(const types::global_dof_index global_index) const;
241 
250  local_to_global(const unsigned int local_index) const;
251 
257  bool
258  is_ghost_entry(const types::global_dof_index global_index) const;
259 
263  const IndexSet &
264  ghost_indices() const;
265 
270  unsigned int
271  n_ghost_indices() const;
272 
283  const std::vector<std::pair<unsigned int, unsigned int>> &
285 
291  const std::vector<std::pair<unsigned int, unsigned int>> &
292  ghost_targets() const;
293 
302  const std::vector<std::pair<unsigned int, unsigned int>> &
303  import_indices() const;
304 
309  unsigned int
310  n_import_indices() const;
311 
321  const std::vector<std::pair<unsigned int, unsigned int>> &
322  import_targets() const;
323 
333  bool
334  is_compatible(const Partitioner &part) const;
335 
349  bool
350  is_globally_compatible(const Partitioner &part) const;
351 
356  unsigned int
357  this_mpi_process() const;
358 
363  unsigned int
364  n_mpi_processes() const;
365 
369  DEAL_II_DEPRECATED
370  const MPI_Comm &
371  get_communicator() const;
372 
376  virtual const MPI_Comm &
377  get_mpi_communicator() const override;
378 
384  bool
386 
387 #ifdef DEAL_II_WITH_MPI
388 
422  template <typename Number>
423  void
425  const unsigned int communication_channel,
426  const ArrayView<const Number> &locally_owned_array,
427  const ArrayView<Number> & temporary_storage,
428  const ArrayView<Number> & ghost_array,
429  std::vector<MPI_Request> & requests) const;
430 
448  template <typename Number>
449  void
451  std::vector<MPI_Request> &requests) const;
452 
489  template <typename Number>
490  void
492  const VectorOperation::values vector_operation,
493  const unsigned int communication_channel,
494  const ArrayView<Number> & ghost_array,
495  const ArrayView<Number> & temporary_storage,
496  std::vector<MPI_Request> & requests) const;
497 
532  template <typename Number>
533  void
535  const VectorOperation::values vector_operation,
536  const ArrayView<const Number> &temporary_storage,
537  const ArrayView<Number> & locally_owned_storage,
538  const ArrayView<Number> & ghost_array,
539  std::vector<MPI_Request> & requests) const;
540 #endif
541 
545  std::size_t
546  memory_consumption() const;
547 
553  unsigned int,
554  << "Global index " << arg1
555  << " neither owned nor ghost on proc " << arg2 << ".");
556 
561  unsigned int,
562  unsigned int,
563  unsigned int,
564  << "The size of the ghost index array (" << arg1
565  << ") must either equal the number of ghost in the "
566  << "partitioner (" << arg2
567  << ") or be equal in size to a more comprehensive index"
568  << "set which contains " << arg3
569  << " elements for this partitioner.");
570 
571  private:
576 
581 
586  std::pair<types::global_dof_index, types::global_dof_index>
588 
594 
599  unsigned int n_ghost_indices_data;
600 
605  std::vector<std::pair<unsigned int, unsigned int>> ghost_targets_data;
606 
613  std::vector<std::pair<unsigned int, unsigned int>> import_indices_data;
614 
619  unsigned int n_import_indices_data;
620 
625  std::vector<std::pair<unsigned int, unsigned int>> import_targets_data;
626 
631  std::vector<unsigned int> import_indices_chunks_by_rank_data;
632 
638 
643  std::vector<unsigned int> ghost_indices_subset_chunks_by_rank_data;
644 
650  std::vector<std::pair<unsigned int, unsigned int>>
652 
656  unsigned int my_pid;
657 
661  unsigned int n_procs;
662 
666  MPI_Comm communicator;
667 
672  };
673 
674 
675 
676  /*--------------------- Inline functions --------------------------------*/
677 
678 #ifndef DOXYGEN
679 
681  Partitioner::size() const
682  {
683  return global_size;
684  }
685 
686 
687 
688  inline const IndexSet &
690  {
692  }
693 
694 
695 
696  inline std::pair<types::global_dof_index, types::global_dof_index>
698  {
699  return local_range_data;
700  }
701 
702 
703 
704  inline unsigned int
706  {
708  local_range_data.second - local_range_data.first;
709  Assert(size <= std::numeric_limits<unsigned int>::max(),
711  return static_cast<unsigned int>(size);
712  }
713 
714 
715 
716  inline bool
718  const types::global_dof_index global_index) const
719  {
720  return (local_range_data.first <= global_index &&
721  global_index < local_range_data.second);
722  }
723 
724 
725 
726  inline bool
728  const types::global_dof_index global_index) const
729  {
730  // if the index is in the global range, it is trivially not a ghost
731  if (in_local_range(global_index) == true)
732  return false;
733  else
734  return ghost_indices().is_element(global_index);
735  }
736 
737 
738 
739  inline unsigned int
741  const types::global_dof_index global_index) const
742  {
743  Assert(in_local_range(global_index) || is_ghost_entry(global_index),
744  ExcIndexNotPresent(global_index, my_pid));
745  if (in_local_range(global_index))
746  return static_cast<unsigned int>(global_index - local_range_data.first);
747  else if (is_ghost_entry(global_index))
748  return (local_size() +
749  static_cast<unsigned int>(
750  ghost_indices_data.index_within_set(global_index)));
751  else
752  // should only end up here in optimized mode, when we use this large
753  // number to trigger a segfault when using this method for array
754  // access
756  }
757 
758 
759 
761  Partitioner::local_to_global(const unsigned int local_index) const
762  {
764  if (local_index < local_size())
765  return local_range_data.first + types::global_dof_index(local_index);
766  else
767  return ghost_indices_data.nth_index_in_set(local_index - local_size());
768  }
769 
770 
771 
772  inline const IndexSet &
774  {
775  return ghost_indices_data;
776  }
777 
778 
779 
780  inline unsigned int
782  {
783  return n_ghost_indices_data;
784  }
785 
786 
787 
788  inline const std::vector<std::pair<unsigned int, unsigned int>> &
790  {
792  }
793 
794 
795 
796  inline const std::vector<std::pair<unsigned int, unsigned int>> &
798  {
799  return ghost_targets_data;
800  }
801 
802 
803  inline const std::vector<std::pair<unsigned int, unsigned int>> &
805  {
806  return import_indices_data;
807  }
808 
809 
810 
811  inline unsigned int
813  {
814  return n_import_indices_data;
815  }
816 
817 
818 
819  inline const std::vector<std::pair<unsigned int, unsigned int>> &
821  {
822  return import_targets_data;
823  }
824 
825 
826 
827  inline unsigned int
829  {
830  // return the id from the variable stored in this class instead of
831  // Utilities::MPI::this_mpi_process() in order to make this query also
832  // work when MPI is not initialized.
833  return my_pid;
834  }
835 
836 
837 
838  inline unsigned int
840  {
841  // return the number of MPI processes from the variable stored in this
842  // class instead of Utilities::MPI::n_mpi_processes() in order to make
843  // this query also work when MPI is not initialized.
844  return n_procs;
845  }
846 
847 
848 
849  inline const MPI_Comm &
851  {
852  return communicator;
853  }
854 
855 
856 
857  inline const MPI_Comm &
859  {
860  return communicator;
861  }
862 
863 
864 
865  inline bool
867  {
868  return have_ghost_indices;
869  }
870 
871 #endif // ifndef DOXYGEN
872 
873  } // end of namespace MPI
874 
875 } // end of namespace Utilities
876 
877 
878 DEAL_II_NAMESPACE_CLOSE
879 
880 #endif
std::vector< std::pair< unsigned int, unsigned int > > import_indices_data
Definition: partitioner.h:613
unsigned int n_ghost_indices() const
static const unsigned int invalid_unsigned_int
Definition: types.h:173
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:420
static::ExceptionBase & ExcIndexNotPresent(types::global_dof_index arg1, unsigned int arg2)
unsigned int this_mpi_process() const
bool is_ghost_entry(const types::global_dof_index global_index) const
const std::vector< std::pair< unsigned int, unsigned int > > & import_indices() const
virtual const MPI_Comm & get_mpi_communicator() const override
types::global_dof_index size() const
types::global_dof_index global_size
Definition: partitioner.h:575
const std::vector< std::pair< unsigned int, unsigned int > > & ghost_targets() const
#define AssertIndexRange(index, range)
Definition: exceptions.h:1407
void import_from_ghosted_array_start(const VectorOperation::values vector_operation, const unsigned int communication_channel, const ArrayView< Number > &ghost_array, const ArrayView< Number > &temporary_storage, std::vector< MPI_Request > &requests) const
unsigned int n_ghost_indices_data
Definition: partitioner.h:599
void export_to_ghosted_array_start(const unsigned int communication_channel, const ArrayView< const Number > &locally_owned_array, const ArrayView< Number > &temporary_storage, const ArrayView< Number > &ghost_array, std::vector< MPI_Request > &requests) const
const MPI_Comm & get_communicator() const
const std::vector< std::pair< unsigned int, unsigned int > > & ghost_indices_within_larger_ghost_set() const
const std::vector< std::pair< unsigned int, unsigned int > > & import_targets() const
const IndexSet & locally_owned_range() const
unsigned long long int global_dof_index
Definition: types.h:72
void set_owned_indices(const IndexSet &locally_owned_indices)
Definition: partitioner.cc:110
std::vector< unsigned int > ghost_indices_subset_chunks_by_rank_data
Definition: partitioner.h:643
std::vector< unsigned int > import_indices_chunks_by_rank_data
Definition: partitioner.h:631
void import_from_ghosted_array_finish(const VectorOperation::values vector_operation, const ArrayView< const Number > &temporary_storage, const ArrayView< Number > &locally_owned_storage, const ArrayView< Number > &ghost_array, std::vector< MPI_Request > &requests) const
#define Assert(cond, exc)
Definition: exceptions.h:1227
std::pair< types::global_dof_index, types::global_dof_index > local_range() const
std::size_t memory_consumption() const
Definition: partitioner.cc:511
types::global_dof_index local_to_global(const unsigned int local_index) const
std::vector< std::pair< unsigned int, unsigned int > > ghost_indices_subset_data
Definition: partitioner.h:651
bool ghost_indices_initialized() const
bool is_globally_compatible(const Partitioner &part) const
Definition: partitioner.cc:502
unsigned int n_import_indices() const
unsigned int global_to_local(const types::global_dof_index global_index) const
const IndexSet & ghost_indices() const
void export_to_ghosted_array_finish(const ArrayView< Number > &ghost_array, std::vector< MPI_Request > &requests) const
bool is_compatible(const Partitioner &part) const
Definition: partitioner.cc:475
bool in_local_range(const types::global_dof_index global_index) const
Definition: cuda.h:32
std::vector< std::pair< unsigned int, unsigned int > > import_targets_data
Definition: partitioner.h:625
std::pair< types::global_dof_index, types::global_dof_index > local_range_data
Definition: partitioner.h:587
unsigned int n_mpi_processes() const
std::vector< std::pair< unsigned int, unsigned int > > ghost_targets_data
Definition: partitioner.h:605
size_type index_within_set(const size_type global_index) const
Definition: index_set.h:1834
bool is_element(const size_type index) const
Definition: index_set.h:1676
static::ExceptionBase & ExcNotImplemented()
#define DeclException3(Exception3, type1, type2, type3, outsequence)
Definition: exceptions.h:432
size_type nth_index_in_set(const unsigned int local_index) const
Definition: index_set.h:1793
unsigned int n_import_indices_data
Definition: partitioner.h:619
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:97
static::ExceptionBase & ExcGhostIndexArrayHasWrongSize(unsigned int arg1, unsigned int arg2, unsigned int arg3)
unsigned int local_size() const
unsigned int n_ghost_indices_in_larger_set
Definition: partitioner.h:637
void set_ghost_indices(const IndexSet &ghost_indices, const IndexSet &larger_ghost_index_set=IndexSet())
Definition: partitioner.cc:151