Reference documentation for deal.II version 8.5.1
partitioner.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2011 - 2016 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 at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 #ifndef dealii__partitioner_h
17 #define dealii__partitioner_h
18 
19 #include <deal.II/base/config.h>
20 #include <deal.II/base/index_set.h>
21 #include <deal.II/base/mpi.h>
22 #include <deal.II/base/types.h>
23 #include <deal.II/base/utilities.h>
24 #include <deal.II/base/memory_consumption.h>
25 #include <deal.II/lac/communication_pattern_base.h>
26 
27 #include <limits>
28 
29 
30 DEAL_II_NAMESPACE_OPEN
31 
32 namespace Utilities
33 {
34  namespace MPI
35  {
63  {
64  public:
68  Partitioner ();
69 
74  Partitioner (const unsigned int size);
75 
83  Partitioner (const IndexSet &locally_owned_indices,
84  const IndexSet &ghost_indices_in,
85  const MPI_Comm communicator_in);
86 
94  Partitioner (const IndexSet &locally_owned_indices,
95  const MPI_Comm communicator_in);
96 
104  virtual void reinit(const IndexSet &vector_space_vector_index_set,
105  const IndexSet &read_write_vector_index_set,
106  const MPI_Comm &communicator);
107 
111  void set_owned_indices (const IndexSet &locally_owned_indices);
112 
118 
123 
128  unsigned int local_size() const;
129 
136  const IndexSet &locally_owned_range() const;
137 
143  std::pair<types::global_dof_index,types::global_dof_index>
144  local_range() const;
145 
150  bool in_local_range (const types::global_dof_index global_index) const;
151 
161  unsigned int
162  global_to_local (const types::global_dof_index global_index) const;
163 
172  local_to_global (const unsigned int local_index) const;
173 
179  bool is_ghost_entry (const types::global_dof_index global_index) const;
180 
184  const IndexSet &ghost_indices() const;
185 
190  unsigned int n_ghost_indices() const;
191 
197  const std::vector<std::pair<unsigned int, unsigned int> > &
198  ghost_targets() const;
199 
206  const std::vector<std::pair<unsigned int, unsigned int> > &
207  import_indices() const;
208 
213  unsigned int n_import_indices() const;
214 
221  const std::vector<std::pair<unsigned int, unsigned int> > &
222  import_targets() const;
223 
233  bool is_compatible (const Partitioner &part) const;
234 
248  bool is_globally_compatible (const Partitioner &part) const;
249 
254  unsigned int this_mpi_process () const;
255 
260  unsigned int n_mpi_processes () const;
261 
265  const MPI_Comm &get_communicator() const DEAL_II_DEPRECATED;
266 
270  virtual const MPI_Comm &get_mpi_communicator() const;
271 
277  bool ghost_indices_initialized() const;
278 
282  std::size_t memory_consumption() const;
283 
289  unsigned int,
290  << "Global index " << arg1
291  << " neither owned nor ghost on proc " << arg2 << ".");
292 
293  private:
298 
303 
308  std::pair<types::global_dof_index,types::global_dof_index> local_range_data;
309 
315 
320  unsigned int n_ghost_indices_data;
321 
326  std::vector<std::pair<unsigned int, unsigned int> > ghost_targets_data;
327 
334  std::vector<std::pair<unsigned int, unsigned int> > import_indices_data;
335 
340  unsigned int n_import_indices_data;
341 
346  std::vector<std::pair<unsigned int, unsigned int> > import_targets_data;
347 
351  unsigned int my_pid;
352 
356  unsigned int n_procs;
357 
361  MPI_Comm communicator;
362 
367  };
368 
369 
370 
371  /*----------------------- Inline functions ----------------------------------*/
372 
373 #ifndef DOXYGEN
374 
375  inline
377  {
378  return global_size;
379  }
380 
381 
382 
383  inline
385  {
387  }
388 
389 
390 
391  inline
392  std::pair<types::global_dof_index,types::global_dof_index>
394  {
395  return local_range_data;
396  }
397 
398 
399 
400  inline
401  unsigned int
402  Partitioner::local_size () const
403  {
405  Assert(size<=std::numeric_limits<unsigned int>::max(),
407  return static_cast<unsigned int>(size);
408  }
409 
410 
411 
412  inline
413  bool
414  Partitioner::in_local_range (const types::global_dof_index global_index) const
415  {
416  return (local_range_data.first <= global_index &&
417  global_index < local_range_data.second);
418  }
419 
420 
421 
422  inline
423  bool
424  Partitioner::is_ghost_entry (const types::global_dof_index global_index) const
425  {
426  // if the index is in the global range, it is trivially not a ghost
427  if (in_local_range(global_index) == true)
428  return false;
429  else
430  return ghost_indices().is_element(global_index);
431  }
432 
433 
434 
435  inline
436  unsigned int
437  Partitioner::global_to_local (const types::global_dof_index global_index) const
438  {
439  Assert(in_local_range(global_index) || is_ghost_entry (global_index),
440  ExcIndexNotPresent(global_index, my_pid));
441  if (in_local_range(global_index))
442  return static_cast<unsigned int>(global_index - local_range_data.first);
443  else if (is_ghost_entry (global_index))
444  return (local_size() +
445  static_cast<unsigned int>(ghost_indices_data.index_within_set (global_index)));
446  else
447  // should only end up here in optimized mode, when we use this large
448  // number to trigger a segfault when using this method for array
449  // access
451  }
452 
453 
454 
455  inline
457  Partitioner::local_to_global (const unsigned int local_index) const
458  {
460  if (local_index < local_size())
461  return local_range_data.first + types::global_dof_index(local_index);
462  else
463  return ghost_indices_data.nth_index_in_set (local_index-local_size());
464  }
465 
466 
467 
468  inline
469  const IndexSet &Partitioner::ghost_indices() const
470  {
471  return ghost_indices_data;
472  }
473 
474 
475 
476  inline
477  unsigned int
479  {
480  return n_ghost_indices_data;
481  }
482 
483 
484 
485  inline
486  const std::vector<std::pair<unsigned int, unsigned int> > &
488  {
489  return ghost_targets_data;
490  }
491 
492 
493  inline
494  const std::vector<std::pair<unsigned int, unsigned int> > &
496  {
497  return import_indices_data;
498  }
499 
500 
501 
502  inline
503  unsigned int
505  {
506  return n_import_indices_data;
507  }
508 
509 
510 
511  inline
512  const std::vector<std::pair<unsigned int, unsigned int> > &
514  {
515  return import_targets_data;
516  }
517 
518 
519 
520  inline
521  unsigned int
523  {
524  // return the id from the variable stored in this class instead of
525  // Utilities::MPI::this_mpi_process() in order to make this query also
526  // work when MPI is not initialized.
527  return my_pid;
528  }
529 
530 
531 
532  inline
533  unsigned int
535  {
536  // return the number of MPI processes from the variable stored in this
537  // class instead of Utilities::MPI::n_mpi_processes() in order to make
538  // this query also work when MPI is not initialized.
539  return n_procs;
540  }
541 
542 
543 
544  inline
545  const MPI_Comm &
547  {
548  return communicator;
549  }
550 
551 
552 
553  inline
554  const MPI_Comm &
556  {
557  return communicator;
558  }
559 
560 
561 
562  inline
563  bool
565  {
566  return have_ghost_indices;
567  }
568 
569 #endif // ifndef DOXYGEN
570 
571  } // end of namespace MPI
572 
573 } // end of namespace Utilities
574 
575 
576 DEAL_II_NAMESPACE_CLOSE
577 
578 #endif
std::vector< std::pair< unsigned int, unsigned int > > import_indices_data
Definition: partitioner.h:334
const IndexSet & locally_owned_range() const
bool is_globally_compatible(const Partitioner &part) const
Definition: partitioner.cc:392
static const unsigned int invalid_unsigned_int
Definition: types.h:170
#define DeclException2(Exception2, type1, type2, outsequence)
Definition: exceptions.h:576
virtual void reinit(const IndexSet &vector_space_vector_index_set, const IndexSet &read_write_vector_index_set, const MPI_Comm &communicator)
Definition: partitioner.cc:93
bool is_compatible(const Partitioner &part) const
Definition: partitioner.cc:366
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
size_type nth_index_in_set(const unsigned int local_index) const
Definition: index_set.h:1612
const std::vector< std::pair< unsigned int, unsigned int > > & import_indices() const
virtual const MPI_Comm & get_mpi_communicator() const
types::global_dof_index global_size
Definition: partitioner.h:297
types::global_dof_index local_to_global(const unsigned int local_index) const
#define AssertIndexRange(index, range)
Definition: exceptions.h:1170
unsigned int n_ghost_indices_data
Definition: partitioner.h:320
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:106
bool ghost_indices_initialized() const
unsigned int this_mpi_process() const
const IndexSet & ghost_indices() const
unsigned int n_ghost_indices() const
unsigned int global_dof_index
Definition: types.h:88
#define Assert(cond, exc)
Definition: exceptions.h:313
size_type index_within_set(const size_type global_index) const
Definition: index_set.h:1653
unsigned int n_mpi_processes() const
const std::vector< std::pair< unsigned int, unsigned int > > & ghost_targets() const
Definition: mpi.h:48
types::global_dof_index size() const
std::size_t memory_consumption() const
Definition: partitioner.cc:401
std::vector< std::pair< unsigned int, unsigned int > > import_targets_data
Definition: partitioner.h:346
const MPI_Comm & get_communicator() const 1
std::vector< std::pair< unsigned int, unsigned int > > ghost_targets_data
Definition: partitioner.h:326
static ::ExceptionBase & ExcNotImplemented()
bool is_element(const size_type index) const
Definition: index_set.h:1489
std::pair< types::global_dof_index, types::global_dof_index > local_range_data
Definition: partitioner.h:308
std::pair< types::global_dof_index, types::global_dof_index > local_range() const
unsigned int n_import_indices() const
unsigned int n_import_indices_data
Definition: partitioner.h:340
bool is_ghost_entry(const types::global_dof_index global_index) const
void set_ghost_indices(const IndexSet &ghost_indices)
Definition: partitioner.cc:142