libMesh
Public Member Functions | Protected Attributes | List of all members
libMesh::Parallel::StandardType< Point > Class Template Reference

#include <parallel_algebra.h>

Inheritance diagram for libMesh::Parallel::StandardType< Point >:
[legend]

Public Member Functions

 StandardType (const Point *example=libmesh_nullptr)
 
 operator const data_type & () const
 
 operator data_type & ()
 
void commit ()
 
void free ()
 

Protected Attributes

data_type _datatype
 

Detailed Description

template<>
class libMesh::Parallel::StandardType< Point >

Definition at line 223 of file parallel_algebra.h.

Constructor & Destructor Documentation

Definition at line 227 of file parallel_algebra.h.

References libMesh::Parallel::DataType::_datatype, libMesh::libMeshPrivateData::_is_initialized, and libMesh::libmesh_ignore().

228  {
229  // Prevent unused variable warnings when !LIBMESH_HAVE_MPI
230  libmesh_ignore(example);
231 
232  // _static_type never gets freed, but it only gets committed once
233  // per T, so it's not a *huge* memory leak...
234  static data_type _static_type;
235  static bool _is_initialized = false;
236  if (!_is_initialized)
237  {
238 #ifdef LIBMESH_HAVE_MPI
239 
240  // We need an example for MPI_Address to use
241  Point * ex;
242 
243  UniquePtr<Point> temp;
244  if (example)
245  ex = const_cast<Point *>(example);
246  else
247  {
248  temp.reset(new Point());
249  ex = temp.get();
250  }
251 
252  StandardType<Real> T_type(&((*ex)(0)));
253 
254 #if MPI_VERSION == 1
255 
256  int blocklengths[3] = {1, LIBMESH_DIM, 1};
257  MPI_Aint displs[3];
258  MPI_Datatype types[3] = {MPI_LB, T_type, MPI_UB};
259  MPI_Aint start, later;
260 
261  libmesh_call_mpi
262  (MPI_Address(ex, &start));
263  displs[0] = 0;
264  libmesh_call_mpi
265  (MPI_Address(&((*ex)(0)), &later));
266  displs[1] = later - start;
267  libmesh_call_mpi
268  (MPI_Address((ex+1), &later));
269  displs[2] = later - start;
270 
271  libmesh_call_mpi
272  (MPI_Type_struct (3, blocklengths, displs, types,
273  &_static_type));
274 
275 #else // MPI_VERSION >= 2
276 
277  int blocklength = LIBMESH_DIM;
278  MPI_Aint displs, start;
279  MPI_Datatype tmptype, type = T_type;
280 
281  libmesh_call_mpi
282  (MPI_Get_address (ex, &start));
283  libmesh_call_mpi
284  (MPI_Get_address (&((*ex)(0)), &displs));
285 
286  // subtract off offset to first value from the beginning of the structure
287  displs -= start;
288 
289  // create a prototype structure
290  libmesh_call_mpi
291  (MPI_Type_create_struct (1, &blocklength, &displs, &type,
292  &tmptype));
293  libmesh_call_mpi
294  (MPI_Type_commit (&tmptype));
295 
296  // resize the structure type to account for padding, if any
297  libmesh_call_mpi
298  (MPI_Type_create_resized (tmptype, 0, sizeof(Point),
299  &_static_type));
300 #endif
301 
302  libmesh_call_mpi
303  (MPI_Type_commit (&_static_type));
304 #endif // #ifdef LIBMESH_HAVE_MPI
305 
306  _is_initialized = true;
307  }
308  _datatype = _static_type;
309  }
MPI_Datatype data_type
Data types for communication.
Definition: parallel.h:166
bool _is_initialized
Flag that tells if init() has been called.
Definition: libmesh.C:255
void libmesh_ignore(const T &)

Member Function Documentation

void libMesh::Parallel::DataType::commit ( )
inherited

Definition at line 334 of file parallel.h.

335  {
336 #ifdef LIBMESH_HAVE_MPI
337  MPI_Type_commit (&_datatype);
338 #endif
339  }
void libMesh::Parallel::DataType::free ( )
inherited
libMesh::Parallel::DataType::operator const data_type & ( ) const
inherited

Definition at line 322 of file parallel.h.

323  { return _datatype; }
libMesh::Parallel::DataType::operator data_type & ( )
inherited

Definition at line 325 of file parallel.h.

326  { return _datatype; }

Member Data Documentation

data_type libMesh::Parallel::DataType::_datatype
protectedinherited

The documentation for this class was generated from the following file: