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

#include <parallel_algebra.h>

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

Public Member Functions

 StandardType (const TypeVector< T > *example=libmesh_nullptr)
 
 operator const data_type & () const
 
 operator data_type & ()
 
void commit ()
 
void free ()
 

Protected Attributes

data_type _datatype
 

Detailed Description

template<typename T>
class libMesh::Parallel::StandardType< TypeVector< T > >

Definition at line 54 of file parallel_algebra.h.

Constructor & Destructor Documentation

template<typename T >
libMesh::Parallel::StandardType< TypeVector< T > >::StandardType ( const TypeVector< T > *  example = libmesh_nullptr)
explicit

Definition at line 58 of file parallel_algebra.h.

References libMesh::Parallel::DataType::_datatype, and libMesh::libMeshPrivateData::_is_initialized.

58  {
59  // We need an example for MPI_Address to use
60  TypeVector<T> * ex;
61  UniquePtr<TypeVector<T>> temp;
62  if (example)
63  ex = const_cast<TypeVector<T> *>(example);
64  else
65  {
66  temp.reset(new TypeVector<T>());
67  ex = temp.get();
68  }
69 
70  // _static_type never gets freed, but it only gets committed once
71  // per T, so it's not a *huge* memory leak...
72  static data_type _static_type;
73  static bool _is_initialized = false;
74  if (!_is_initialized)
75  {
76 #ifdef LIBMESH_HAVE_MPI
77  StandardType<T> T_type(&((*ex)(0)));
78 
79 #if MPI_VERSION == 1
80 
81  int blocklengths[3] = {1, LIBMESH_DIM, 1};
82  MPI_Aint displs[3];
83  MPI_Datatype types[3] = {MPI_LB, T_type, MPI_UB};
84  MPI_Aint start, later;
85 
86  libmesh_call_mpi
87  (MPI_Address(ex, &start));
88  displs[0] = 0;
89  libmesh_call_mpi
90  (MPI_Address(&((*ex)(0)), &later));
91  displs[1] = later - start;
92  libmesh_call_mpi
93  (MPI_Address((ex+1), &later));
94  displs[2] = later - start;
95 
96  libmesh_call_mpi
97  (MPI_Type_struct (3, blocklengths, displs, types,
98  &_static_type));
99 
100 #else // MPI_VERSION >= 2
101 
102  int blocklength = LIBMESH_DIM;
103  MPI_Aint displs, start;
104  MPI_Datatype tmptype, type = T_type;
105 
106  libmesh_call_mpi
107  (MPI_Get_address (ex, &start));
108  libmesh_call_mpi
109  (MPI_Get_address (&((*ex)(0)), &displs));
110 
111  // subtract off offset to first value from the beginning of the structure
112  displs -= start;
113 
114  // create a prototype structure
115  libmesh_call_mpi
116  (MPI_Type_create_struct (1, &blocklength, &displs, &type,
117  &tmptype));
118  libmesh_call_mpi
119  (MPI_Type_commit (&tmptype));
120 
121  // resize the structure type to account for padding, if any
122  libmesh_call_mpi
123  (MPI_Type_create_resized (tmptype, 0, sizeof(TypeVector<T>),
124  &_static_type));
125 #endif
126 
127  libmesh_call_mpi
128  (MPI_Type_commit (&_static_type));
129 #endif // #ifdef LIBMESH_HAVE_MPI
130 
131  _is_initialized = true;
132  }
133  _datatype = _static_type;
134  }
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

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: