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

#include <parallel_algebra.h>

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

Public Member Functions

 StandardType (const VectorValue< 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< VectorValue< T > >

Definition at line 138 of file parallel_algebra.h.

Constructor & Destructor Documentation

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

Definition at line 142 of file parallel_algebra.h.

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

142  {
143  // We need an example for MPI_Address to use
144  VectorValue<T> * ex;
145  UniquePtr<VectorValue<T>> temp;
146  if (example)
147  ex = const_cast<VectorValue<T> *>(example);
148  else
149  {
150  temp.reset(new VectorValue<T>());
151  ex = temp.get();
152  }
153 
154  // _static_type never gets freed, but it only gets committed once
155  // per T, so it's not a *huge* memory leak...
156  static data_type _static_type;
157  static bool _is_initialized = false;
158  if (!_is_initialized)
159  {
160 #ifdef LIBMESH_HAVE_MPI
161  StandardType<T> T_type(&((*ex)(0)));
162 
163 #if MPI_VERSION == 1
164 
165  int blocklengths[3] = {1, LIBMESH_DIM, 1};
166  MPI_Aint displs[3];
167  MPI_Datatype types[3] = {MPI_LB, T_type, MPI_UB};
168  MPI_Aint start, later;
169 
170  libmesh_call_mpi
171  (MPI_Address(ex, &start));
172  displs[0] = 0;
173  libmesh_call_mpi
174  (MPI_Address(&((*ex)(0)), &later));
175  displs[1] = later - start;
176  libmesh_call_mpi
177  (MPI_Address((ex+1), &later));
178  displs[2] = later - start;
179 
180  libmesh_call_mpi
181  (MPI_Type_struct (3, blocklengths, displs, types,
182  &_static_type));
183 
184 #else // MPI_VERSION >= 2
185 
186  int blocklength = LIBMESH_DIM;
187  MPI_Aint displs, start;
188  MPI_Datatype tmptype, type = T_type;
189 
190  libmesh_call_mpi
191  (MPI_Get_address (ex, &start));
192  libmesh_call_mpi
193  (MPI_Get_address (&((*ex)(0)), &displs));
194 
195  // subtract off offset to first value from the beginning of the structure
196  displs -= start;
197 
198  // create a prototype structure
199  libmesh_call_mpi
200  (MPI_Type_create_struct (1, &blocklength, &displs, &type,
201  &tmptype));
202  libmesh_call_mpi
203  (MPI_Type_commit (&tmptype));
204 
205  // resize the structure type to account for padding, if any
206  libmesh_call_mpi
207  (MPI_Type_create_resized (tmptype, 0,
208  sizeof(VectorValue<T>),
209  &_static_type));
210 #endif
211 
212  libmesh_call_mpi
213  (MPI_Type_commit (&_static_type));
214 #endif // #ifdef LIBMESH_HAVE_MPI
215 
216  _is_initialized = true;
217  }
218  _datatype = _static_type;
219  }
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: