Reference documentation for deal.II version 8.4.2
partitioner.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2011 - 2015 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 
26 #include <limits>
27 
28 
29 DEAL_II_NAMESPACE_OPEN
30 
31 namespace Utilities
32 {
33  namespace MPI
34  {
62  {
63  public:
67  Partitioner ();
68 
73  Partitioner (const unsigned int size);
74 
82  Partitioner (const IndexSet &locally_owned_indices,
83  const IndexSet &ghost_indices_in,
84  const MPI_Comm communicator_in);
85 
93  Partitioner (const IndexSet &locally_owned_indices,
94  const MPI_Comm communicator_in);
95 
99  void set_owned_indices (const IndexSet &locally_owned_indices);
100 
106 
111 
116  unsigned int local_size() const;
117 
124  const IndexSet &locally_owned_range() const;
125 
131  std::pair<types::global_dof_index,types::global_dof_index>
132  local_range() const;
133 
138  bool in_local_range (const types::global_dof_index global_index) const;
139 
149  unsigned int
150  global_to_local (const types::global_dof_index global_index) const;
151 
160  local_to_global (const unsigned int local_index) const;
161 
167  bool is_ghost_entry (const types::global_dof_index global_index) const;
168 
172  const IndexSet &ghost_indices() const;
173 
178  unsigned int n_ghost_indices() const;
179 
185  const std::vector<std::pair<unsigned int, unsigned int> > &
186  ghost_targets() const;
187 
194  const std::vector<std::pair<unsigned int, unsigned int> > &
195  import_indices() const;
196 
201  unsigned int n_import_indices() const;
202 
209  const std::vector<std::pair<unsigned int, unsigned int> > &
210  import_targets() const;
211 
221  bool is_compatible (const Partitioner &part) const;
222 
236  bool is_globally_compatible (const Partitioner &part) const;
237 
242  unsigned int this_mpi_process () const;
243 
248  unsigned int n_mpi_processes () const;
249 
253  const MPI_Comm &get_communicator() const;
254 
260  bool ghost_indices_initialized() const;
261 
265  std::size_t memory_consumption() const;
266 
270  DeclException2 (ExcIndexNotPresent,
272  unsigned int,
273  << "Global index " << arg1
274  << " neither owned nor ghost on proc " << arg2);
275 
276  private:
281 
286 
291  std::pair<types::global_dof_index,types::global_dof_index> local_range_data;
292 
298 
303  unsigned int n_ghost_indices_data;
304 
309  std::vector<std::pair<unsigned int, unsigned int> > ghost_targets_data;
310 
317  std::vector<std::pair<unsigned int, unsigned int> > import_indices_data;
318 
323  unsigned int n_import_indices_data;
324 
329  std::vector<std::pair<unsigned int, unsigned int> > import_targets_data;
330 
334  unsigned int my_pid;
335 
339  unsigned int n_procs;
340 
344  const MPI_Comm communicator;
345 
350  };
351 
352 
353 
354  /*----------------------- Inline functions ----------------------------------*/
355 
356 #ifndef DOXYGEN
357 
358  inline
360  {
361  return global_size;
362  }
363 
364 
365 
366  inline
368  {
370  }
371 
372 
373 
374  inline
375  std::pair<types::global_dof_index,types::global_dof_index>
377  {
378  return local_range_data;
379  }
380 
381 
382 
383  inline
384  unsigned int
385  Partitioner::local_size () const
386  {
388  Assert(size<=std::numeric_limits<unsigned int>::max(),
389  ExcNotImplemented());
390  return static_cast<unsigned int>(size);
391  }
392 
393 
394 
395  inline
396  bool
397  Partitioner::in_local_range (const types::global_dof_index global_index) const
398  {
399  return (local_range_data.first <= global_index &&
400  global_index < local_range_data.second);
401  }
402 
403 
404 
405  inline
406  bool
407  Partitioner::is_ghost_entry (const types::global_dof_index global_index) const
408  {
409  // if the index is in the global range, it is trivially not a ghost
410  if (in_local_range(global_index) == true)
411  return false;
412  else
413  return ghost_indices().is_element(global_index);
414  }
415 
416 
417 
418  inline
419  unsigned int
420  Partitioner::global_to_local (const types::global_dof_index global_index) const
421  {
422  Assert(in_local_range(global_index) || is_ghost_entry (global_index),
423  ExcIndexNotPresent(global_index, my_pid));
424  if (in_local_range(global_index))
425  return static_cast<unsigned int>(global_index - local_range_data.first);
426  else if (is_ghost_entry (global_index))
427  return (local_size() +
428  static_cast<unsigned int>(ghost_indices_data.index_within_set (global_index)));
429  else
430  // should only end up here in optimized mode, when we use this large
431  // number to trigger a segfault when using this method for array
432  // access
434  }
435 
436 
437 
438  inline
440  Partitioner::local_to_global (const unsigned int local_index) const
441  {
443  if (local_index < local_size())
444  return local_range_data.first + types::global_dof_index(local_index);
445  else
446  return ghost_indices_data.nth_index_in_set (local_index-local_size());
447  }
448 
449 
450 
451  inline
452  const IndexSet &Partitioner::ghost_indices() const
453  {
454  return ghost_indices_data;
455  }
456 
457 
458 
459  inline
460  unsigned int
462  {
463  return n_ghost_indices_data;
464  }
465 
466 
467 
468  inline
469  const std::vector<std::pair<unsigned int, unsigned int> > &
471  {
472  return ghost_targets_data;
473  }
474 
475 
476  inline
477  const std::vector<std::pair<unsigned int, unsigned int> > &
479  {
480  return import_indices_data;
481  }
482 
483 
484 
485  inline
486  unsigned int
488  {
489  return n_import_indices_data;
490  }
491 
492 
493 
494  inline
495  const std::vector<std::pair<unsigned int, unsigned int> > &
497  {
498  return import_targets_data;
499  }
500 
501 
502 
503  inline
504  unsigned int
506  {
507  // return the id from the variable stored in this class instead of
508  // Utilities::MPI::this_mpi_process() in order to make this query also
509  // work when MPI is not initialized.
510  return my_pid;
511  }
512 
513 
514 
515  inline
516  unsigned int
518  {
519  // return the number of MPI processes from the variable stored in this
520  // class instead of Utilities::MPI::n_mpi_processes() in order to make
521  // this query also work when MPI is not initialized.
522  return n_procs;
523  }
524 
525 
526 
527  inline
528  const MPI_Comm &
530  {
531  return communicator;
532  }
533 
534 
535 
536  inline
537  bool
539  {
540  return have_ghost_indices;
541  }
542 
543 #endif // ifndef DOXYGEN
544 
545  } // end of namespace MPI
546 
547 } // end of namespace Utilities
548 
549 
550 DEAL_II_NAMESPACE_CLOSE
551 
552 #endif
std::vector< std::pair< unsigned int, unsigned int > > import_indices_data
Definition: partitioner.h:317
const IndexSet & locally_owned_range() const
bool is_globally_compatible(const Partitioner &part) const
Definition: partitioner.cc:368
static const unsigned int invalid_unsigned_int
Definition: types.h:164
bool is_compatible(const Partitioner &part) const
Definition: partitioner.cc:343
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:1432
const std::vector< std::pair< unsigned int, unsigned int > > & import_indices() const
types::global_dof_index local_to_global(const unsigned int local_index) const
#define AssertIndexRange(index, range)
Definition: exceptions.h:1081
unsigned int n_ghost_indices_data
Definition: partitioner.h:303
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:93
DeclException2(ExcIndexNotPresent, types::global_dof_index, unsigned int,<< "Global index "<< arg1<< " neither owned nor ghost on proc "<< arg2)
bool ghost_indices_initialized() const
unsigned int this_mpi_process() const
const IndexSet & ghost_indices() const
const MPI_Comm & get_communicator() const
unsigned int n_ghost_indices() const
unsigned int global_dof_index
Definition: types.h:88
const MPI_Comm communicator
Definition: partitioner.h:344
#define Assert(cond, exc)
Definition: exceptions.h:294
size_type index_within_set(const size_type global_index) const
Definition: index_set.h:1475
unsigned int n_mpi_processes() const
const types::global_dof_index global_size
Definition: partitioner.h:280
const std::vector< std::pair< unsigned int, unsigned int > > & ghost_targets() const
Definition: mpi.h:55
types::global_dof_index size() const
std::size_t memory_consumption() const
Definition: partitioner.cc:377
std::vector< std::pair< unsigned int, unsigned int > > import_targets_data
Definition: partitioner.h:329
std::vector< std::pair< unsigned int, unsigned int > > ghost_targets_data
Definition: partitioner.h:309
bool is_element(const size_type index) const
Definition: index_set.h:1317
std::pair< types::global_dof_index, types::global_dof_index > local_range_data
Definition: partitioner.h:291
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:323
bool is_ghost_entry(const types::global_dof_index global_index) const
void set_ghost_indices(const IndexSet &ghost_indices)
Definition: partitioner.cc:129