@@ -77,12 +77,12 @@ namespace mpi {
77
77
#undef D
78
78
79
79
/* *
80
- * @brief Specialization of mpi::mpi_type for enum types
81
- * @tparam T C++ enum type.
80
+ * @brief Specialization of mpi::mpi_type for enum types.
81
+ * @tparam E C++ enum type.
82
82
*/
83
- template <typename T >
84
- requires (std::is_enum_v<T >)
85
- struct mpi_type<T > : mpi_type<std::underlying_type_t<T >> {};
83
+ template <typename E >
84
+ requires (std::is_enum_v<E >)
85
+ struct mpi_type<E > : mpi_type<std::underlying_type_t<E >> {};
86
86
87
87
/* *
88
88
* @brief Specialization of mpi::mpi_type for `const` types.
@@ -143,9 +143,9 @@ namespace mpi {
143
143
* @brief Specialization of mpi::mpi_type for std::tuple.
144
144
* @tparam Ts Tuple element types.
145
145
*/
146
- template <typename ... T > struct mpi_type <std::tuple<T ...>> {
146
+ template <typename ... Ts > struct mpi_type <std::tuple<Ts ...>> {
147
147
[[nodiscard]] static MPI_Datatype get () noexcept {
148
- static MPI_Datatype type = get_mpi_type (std::tuple<T ...>{});
148
+ static MPI_Datatype type = get_mpi_type (std::tuple<Ts ...>{});
149
149
return type;
150
150
}
151
151
};
@@ -167,18 +167,15 @@ namespace mpi {
167
167
* auto tie_data(foo f) {
168
168
* return std::tie(f.x, f.y);
169
169
* }
170
- *
171
- * // provide a specialization of mpi_type
172
- * template <> struct mpi::mpi_type<foo> : mpi::mpi_type_from_tie<foo> {};
173
170
* @endcode
174
171
*
175
- * @tparam T Type to be converted to an `MPI_Datatype`.
172
+ * @tparam U Type to be converted to an `MPI_Datatype`.
176
173
*/
177
- template <typename T >
178
- requires requires (T t ) { tie_data (t ); }
179
- struct mpi_type <T > {
174
+ template <typename U >
175
+ requires ( not Serializable<U>) and requires(U u ) { tie_data (u ); }
176
+ struct mpi_type <U > {
180
177
[[nodiscard]] static MPI_Datatype get () noexcept {
181
- static MPI_Datatype type = get_mpi_type (tie_data (T {}));
178
+ static MPI_Datatype type = get_mpi_type (tie_data (U {}));
182
179
return type;
183
180
}
184
181
};
@@ -194,18 +191,19 @@ namespace mpi {
194
191
public:
195
192
explicit MpiArchive (const void *base) { MPI_Get_address (base, &base_address); }
196
193
197
- // Overloaded operator& to process members
194
+ // Overloaded operator& to process members to set the block lengths, displacements and MPI types.
198
195
template <typename T>
199
196
requires (has_mpi_type<T>)
200
197
MpiArchive &operator &(const T &member) {
201
198
types.push_back (mpi_type<T>::get ());
202
199
MPI_Aint address{};
203
200
MPI_Get_address (&member, &address);
204
- displacements.push_back (address - base_address);
201
+ displacements.push_back (MPI_Aint_diff ( address, base_address) );
205
202
block_lengths.push_back (1 );
206
203
return *this ;
207
204
}
208
205
};
206
+
209
207
} // namespace detail
210
208
211
209
/* *
@@ -229,18 +227,18 @@ namespace mpi {
229
227
detail::MpiArchive ar (&obj);
230
228
obj.serialize (ar);
231
229
MPI_Datatype mpi_type{};
232
- MPI_Type_create_struct (ar.block_lengths .size (), ar.block_lengths .data (), ar.displacements .data (), ar.types .data (), &mpi_type);
230
+ MPI_Type_create_struct (static_cast < int >( ar.block_lengths .size () ), ar.block_lengths .data (), ar.displacements .data (), ar.types .data (), &mpi_type);
233
231
MPI_Type_commit (&mpi_type);
234
232
return mpi_type;
235
233
}
236
234
237
235
/* *
238
236
* @brief Specialization of mpi::mpi_type for serializable types.
239
- * @tparam T Serializable type.
237
+ * @tparam S Serializable type.
240
238
*/
241
- template <Serializable T > struct mpi_type <T > {
239
+ template <Serializable S > struct mpi_type <S > {
242
240
[[nodiscard]] static MPI_Datatype get () noexcept {
243
- static MPI_Datatype type = get_mpi_type (T {});
241
+ static MPI_Datatype type = get_mpi_type (S {});
244
242
return type;
245
243
}
246
244
};
0 commit comments