libMesh
parallel_object.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_PARALLEL_OBJECT_H
21 #define LIBMESH_PARALLEL_OBJECT_H
22 
23 
24 // libMesh includes
25 #include "libmesh/libmesh_common.h" // libmesh_dbg_var
26 #include "libmesh/parallel_only.h"
27 
28 // TIMPI includes
29 #include "timpi/communicator.h"
30 
31 
32 // Macro to identify and debug functions which should only be called in
33 // parallel on every processor at once
34 #undef parallel_object_only
35 #ifndef NDEBUG
36 #define parallel_object_only() libmesh_parallel_only(this->comm())
37 #else
38 #define parallel_object_only() ((void) 0)
39 #endif
40 
41 
42 namespace libMesh
43 {
56 {
57 public:
58 
63  ParallelObject (const Parallel::Communicator & comm_in) :
64  _communicator(comm_in)
65  {}
66 
70  ParallelObject (const ParallelObject & other) :
72  {}
73 
79  ParallelObject & operator= (const ParallelObject & libmesh_dbg_var(other))
80  {
81  libmesh_assert_equal_to (&_communicator, &other._communicator);
82  return *this;
83  }
84 
88  virtual ~ParallelObject () {}
89 
94  const Parallel::Communicator & comm () const
95  { return _communicator; }
96 
101  { return cast_int<processor_id_type>(_communicator.size()); }
102 
107  { return cast_int<processor_id_type>(_communicator.rank()); }
108 
109 
110 protected:
111 
112  const Parallel::Communicator & _communicator;
113 };
114 } // namespace libMesh
115 
116 #endif // LIBMESH_PARALLEL_OBJECT_H
libMesh::ParallelObject::ParallelObject
ParallelObject(const ParallelObject &other)
Copy Constructor.
Definition: parallel_object.h:70
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::ParallelObject::comm
const Parallel::Communicator & comm() const
Definition: parallel_object.h:94
libMesh::ParallelObject::operator=
ParallelObject & operator=(const ParallelObject &libmesh_dbg_var(other))
"Assignment" operator.
Definition: parallel_object.h:79
libMesh::ParallelObject::~ParallelObject
virtual ~ParallelObject()
Destructor.
Definition: parallel_object.h:88
libMesh::ParallelObject::ParallelObject
ParallelObject(const Parallel::Communicator &comm_in)
Constructor.
Definition: parallel_object.h:63
libMesh::ParallelObject::n_processors
processor_id_type n_processors() const
Definition: parallel_object.h:100
libMesh::ParallelObject::processor_id
processor_id_type processor_id() const
Definition: parallel_object.h:106
libMesh::ParallelObject::_communicator
const Parallel::Communicator & _communicator
Definition: parallel_object.h:112
libMesh::processor_id_type
uint8_t processor_id_type
Definition: id_types.h:104
libMesh::ParallelObject
An object whose state is distributed along a set of processors.
Definition: parallel_object.h:55
communicator.h