data_type.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_DATA_TYPE_H
20 #define LIBMESH_DATA_TYPE_H
21 
22 // Parallel includes
24 
25 // libMesh includes
26 #include "libmesh/libmesh_common.h"
27 
28 namespace libMesh
29 {
30 
38 namespace Parallel
39 {
40 
41 #ifdef LIBMESH_HAVE_MPI
42 //-------------------------------------------------------------------
46 typedef MPI_Datatype data_type;
47 
48 #else
49 
50 // These shouldn't actually be needed, but must be
51 // unique types for function overloading to work
52 // properly.
53 struct data_type { /* unsigned int t; */ };
54 
55 #endif // LIBMESH_HAVE_MPI
56 
57 
58 
59 //-------------------------------------------------------------------
63 class DataType
64 {
65 public:
66  DataType () : _datatype() {}
67 
68  DataType (const DataType & other) :
69  _datatype(other._datatype)
70  {}
71 
72  DataType (const data_type & type) :
73  _datatype(type)
74  {}
75 
76  DataType (const DataType & other, unsigned int count)
77  {
78  // FIXME - if we nest an inner type here will we run into bug
79  // https://github.com/libMesh/libmesh/issues/631 again?
80  libmesh_call_mpi(MPI_Type_contiguous(count, other._datatype, &_datatype));
81  libmesh_ignore(other, count); // ifndef LIBMESH_HAVE_MPI
82  this->commit();
83  }
84 
85  DataType & operator = (const DataType & other)
86  { _datatype = other._datatype; return *this; }
87 
88  DataType & operator = (const data_type & type)
89  { _datatype = type; return *this; }
90 
91  operator const data_type & () const
92  { return _datatype; }
93 
94  operator data_type & ()
95  { return _datatype; }
96 
97  // operator data_type const * () const
98  // { return &_datatype; }
99 
100  // operator data_type * ()
101  // { return &_datatype; }
102 
103  void commit ()
104  {
105  libmesh_call_mpi
106  (MPI_Type_commit (&_datatype));
107  }
108 
109  void free ()
110  {
111  libmesh_call_mpi
112  (MPI_Type_free (&_datatype));
113  }
114 
115 protected:
116 
118 };
119 
120 } // namespace Parallel
121 
122 } // namespace libMesh
123 
124 #endif // LIBMESH_DATA_TYPE_H
DataType & operator=(const DataType &other)
Definition: data_type.h:85
MPI_Datatype data_type
Definition: data_type.h:46
void libmesh_ignore(const Args &...)
DataType(const data_type &type)
Definition: data_type.h:72
DataType(const DataType &other)
Definition: data_type.h:68
DataType(const DataType &other, unsigned int count)
Definition: data_type.h:76