status.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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 #ifndef LIBMESH_STATUS_H
20 #define LIBMESH_STATUS_H
21 
22 // Parallel includes
23 #include "libmesh/data_type.h"
24 
25 // libMesh Includes
26 #include "libmesh/libmesh_common.h"
27 
28 namespace libMesh
29 {
30 
31 namespace Parallel
32 {
33 
34 #ifdef LIBMESH_HAVE_MPI
35 
36 //-------------------------------------------------------------------
37 
41 typedef MPI_Status status;
42 
43 #else
44 
45 // This shouldn't actually be needed, but must be
46 // unique types for function overloading to work
47 // properly.
48 struct status { /* unsigned int s; */ };
49 
50 #endif // LIBMESH_HAVE_MPI
51 
52 
53 
54 //-------------------------------------------------------------------
59 class Status
60 {
61 public:
62  Status ();
63 
64  explicit Status (const data_type & type);
65 
66  explicit Status (const status & status);
67 
68  Status (const status & status,
69  const data_type & type);
70 
71  Status (const Status & status);
72 
73  Status (const Status & status,
74  const data_type & type);
75 
76  status * get() { return &_status; }
77 
78  status const * get() const { return &_status; }
79 
80  int source () const;
81 
82  int tag () const;
83 
84  data_type & datatype () { return _datatype; }
85 
86  const data_type & datatype () const { return _datatype; }
87 
88  unsigned int size (const data_type & type) const;
89 
90  unsigned int size () const;
91 
92 private:
93 
96 };
97 
98 // ------------------------------------------------------------
99 // Status member functions
100 
101 inline Status::Status () :
102  _status(),
103  _datatype()
104 {}
105 
106 inline Status::Status (const data_type & type) :
107  _status(),
108  _datatype(type)
109 {}
110 
111 inline Status::Status (const status & stat) :
112  _status(stat),
113  _datatype()
114 {}
115 
116 inline Status::Status (const status & stat,
117  const data_type & type) :
118  _status(stat),
119  _datatype(type)
120 {}
121 
122 inline Status::Status (const Status & stat) :
123  _status(stat._status),
124  _datatype(stat._datatype)
125 {}
126 
127 inline Status::Status (const Status & stat,
128  const data_type & type) :
129  _status(stat._status),
130  _datatype(type)
131 {}
132 
133 inline int Status::source () const
134 {
135 #ifdef LIBMESH_HAVE_MPI
136  return _status.MPI_SOURCE;
137 #else
138  return 0;
139 #endif
140 }
141 
142 inline int Status::tag () const
143 {
144 #ifdef LIBMESH_HAVE_MPI
145  return _status.MPI_TAG;
146 #else
147  libmesh_not_implemented();
148  return 0;
149 #endif
150 }
151 
152 inline unsigned int Status::size (const data_type & type) const
153 {
154  libmesh_ignore(type); // We don't use this ifndef LIBMESH_HAVE_MPI
155  int msg_size = 1;
156  libmesh_call_mpi
157  (MPI_Get_count (const_cast<MPI_Status*>(&_status), type,
158  &msg_size));
159 
160  libmesh_assert_greater_equal (msg_size, 0);
161  return msg_size;
162 }
163 
164 inline unsigned int Status::size () const
165 { return this->size (this->datatype()); }
166 
167 
168 } // namespace Parallel
169 
170 } // namespace libMesh
171 
172 #endif // LIBMESH_STATUS_H
int source() const
Definition: status.h:133
void libmesh_ignore(const Args &...)
MPI_Status status
Definition: status.h:41
data_type & datatype()
Definition: status.h:84
unsigned int size() const
Definition: status.h:164
const data_type & datatype() const
Definition: status.h:86