Loading [MathJax]/extensions/tex2jax.js
TIMPI
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
data_type.h
Go to the documentation of this file.
1 // The TIMPI Message-Passing Parallelism Library.
2 // Copyright (C) 2002-2025 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 TIMPI_DATA_TYPE_H
20 #define TIMPI_DATA_TYPE_H
21 
22 // TIMPI includes
23 #include "timpi/timpi_call_mpi.h"
24 
25 namespace TIMPI
26 {
27 
28 #ifdef TIMPI_HAVE_MPI
29 //-------------------------------------------------------------------
33 typedef MPI_Datatype data_type;
34 
35 #else
36 
37 // These shouldn't actually be needed, but must be
38 // unique types for function overloading to work
39 // properly.
40 struct data_type { /* unsigned int t; */ };
41 
42 #endif // TIMPI_HAVE_MPI
43 
44 
45 
46 //-------------------------------------------------------------------
50 class DataType
51 {
52 public:
53  DataType () = default;
54  DataType (const DataType & other) = default;
55  DataType (DataType && other) = default;
56  static const bool is_fixed_type = true;
57 
58  DataType (const data_type & type) :
59  _datatype(type)
60  {}
61 
62  DataType (const DataType & other, unsigned int count)
63  {
64  // FIXME - if we nest an inner type here will we run into bug
65  // https://github.com/libMesh/libmesh/issues/631 again?
66  timpi_call_mpi(MPI_Type_contiguous(count, other._datatype, &_datatype));
67  ignore(other, count); // ifndef TIMPI_HAVE_MPI
68  this->commit();
69  }
70 
71  virtual ~DataType () = default;
72 
73  DataType & operator = (const DataType & other) = default;
74  DataType & operator = (DataType && other) = default;
75 
76  DataType & operator = (const data_type & type)
77  { _datatype = type; return *this; }
78 
79  operator const data_type & () const
80  { return _datatype; }
81 
82  operator data_type & ()
83  { return _datatype; }
84 
85  // operator data_type const * () const
86  // { return &_datatype; }
87 
88  // operator data_type * ()
89  // { return &_datatype; }
90 
91  void commit ()
92  {
93  timpi_call_mpi
94  (MPI_Type_commit (&_datatype));
95  }
96 
97  void free ()
98  {
99  timpi_call_mpi
100  (MPI_Type_free (&_datatype));
101  }
102 
103 protected:
104 
106 };
107 
121 {
122 public:
123  NotADataType () = default;
124  NotADataType (const NotADataType & other) = default;
125  NotADataType (NotADataType && other) = default;
126  ~NotADataType () = default;
127  NotADataType & operator = (const NotADataType & other) = default;
128  NotADataType & operator = (NotADataType && other) = default;
129 
130  static const bool is_fixed_type = false;
131 };
132 
133 template <bool>
135  typedef DataType type;
136 };
137 
138 template <>
139 struct MaybeADataType<false>
140 {
142 };
143 
144 } // namespace TIMPI
145 
146 #endif // TIMPI_DATA_TYPE_H
MPI_Datatype data_type
Data types for communication.
Definition: data_type.h:33
void commit()
Definition: data_type.h:91
DataType()=default
Encapsulates the MPI_Datatype.
Definition: data_type.h:50
DataType & operator=(const DataType &other)=default
DataType(const DataType &other, unsigned int count)
Definition: data_type.h:62
NotADataType()=default
void ignore(const Args &...)
Definition: timpi_assert.h:54
~NotADataType()=default
DataType(const data_type &type)
Definition: data_type.h:58
data_type _datatype
Definition: data_type.h:105
static const bool is_fixed_type
Definition: data_type.h:130
static const bool is_fixed_type
Definition: data_type.h:56
StandardType<T>&#39;s which do not define a way to MPI_Type T should inherit from this class...
Definition: data_type.h:120
NotADataType & operator=(const NotADataType &other)=default
virtual ~DataType()=default