Skip to content

Commit 9394743

Browse files
committed
Some doc updates and minor clean up
1 parent 7cf0126 commit 9394743

File tree

4 files changed

+35
-32
lines changed

4 files changed

+35
-32
lines changed

c++/mpi/datatypes.hpp

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -77,12 +77,12 @@ namespace mpi {
7777
#undef D
7878

7979
/**
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.
8282
*/
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>> {};
8686

8787
/**
8888
* @brief Specialization of mpi::mpi_type for `const` types.
@@ -143,9 +143,9 @@ namespace mpi {
143143
* @brief Specialization of mpi::mpi_type for std::tuple.
144144
* @tparam Ts Tuple element types.
145145
*/
146-
template <typename... T> struct mpi_type<std::tuple<T...>> {
146+
template <typename... Ts> struct mpi_type<std::tuple<Ts...>> {
147147
[[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...>{});
149149
return type;
150150
}
151151
};
@@ -167,18 +167,15 @@ namespace mpi {
167167
* auto tie_data(foo f) {
168168
* return std::tie(f.x, f.y);
169169
* }
170-
*
171-
* // provide a specialization of mpi_type
172-
* template <> struct mpi::mpi_type<foo> : mpi::mpi_type_from_tie<foo> {};
173170
* @endcode
174171
*
175-
* @tparam T Type to be converted to an `MPI_Datatype`.
172+
* @tparam U Type to be converted to an `MPI_Datatype`.
176173
*/
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> {
180177
[[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{}));
182179
return type;
183180
}
184181
};
@@ -194,18 +191,19 @@ namespace mpi {
194191
public:
195192
explicit MpiArchive(const void *base) { MPI_Get_address(base, &base_address); }
196193

197-
// Overloaded operator& to process members
194+
// Overloaded operator& to process members to set the block lengths, displacements and MPI types.
198195
template <typename T>
199196
requires(has_mpi_type<T>)
200197
MpiArchive &operator&(const T &member) {
201198
types.push_back(mpi_type<T>::get());
202199
MPI_Aint address{};
203200
MPI_Get_address(&member, &address);
204-
displacements.push_back(address - base_address);
201+
displacements.push_back(MPI_Aint_diff(address, base_address));
205202
block_lengths.push_back(1);
206203
return *this;
207204
}
208205
};
206+
209207
} // namespace detail
210208

211209
/**
@@ -229,18 +227,18 @@ namespace mpi {
229227
detail::MpiArchive ar(&obj);
230228
obj.serialize(ar);
231229
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);
233231
MPI_Type_commit(&mpi_type);
234232
return mpi_type;
235233
}
236234

237235
/**
238236
* @brief Specialization of mpi::mpi_type for serializable types.
239-
* @tparam T Serializable type.
237+
* @tparam S Serializable type.
240238
*/
241-
template <Serializable T> struct mpi_type<T> {
239+
template <Serializable S> struct mpi_type<S> {
242240
[[nodiscard]] static MPI_Datatype get() noexcept {
243-
static MPI_Datatype type = get_mpi_type(T{});
241+
static MPI_Datatype type = get_mpi_type(S{});
244242
return type;
245243
}
246244
};

c++/mpi/utils.hpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,8 @@ namespace mpi {
8383

8484
namespace detail {
8585

86-
// Helper struct to check if a types serialize function serializes only fundamental types or enums
86+
// Helper struct to check if a type's serialize function serializes only fundamental types or enums.
8787
struct serialize_checker {
88-
8988
template <typename T>
9089
void operator&(T const &t)
9190
requires(std::is_fundamental_v<T> or std::is_enum_v<T> or requires { t.serialize(*this); })
@@ -99,7 +98,10 @@ namespace mpi {
9998

10099
} // namespace detail
101100

102-
/// Check if objects of the type can be serialized and deserialized
101+
/**
102+
* @brief A concept that checks if objects of a type can be serialized and deserialized.
103+
* @tparam T Type to check.
104+
*/
103105
template <typename T>
104106
concept Serializable = requires(T a, detail::serialize_checker ar) {
105107
a.serialize(ar);

doc/DoxygenLayout.xml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,16 +32,20 @@
3232
<tab type="usergroup" url="@ref mpi::mpi_type" title="mpi_type">
3333
<tab type="user" url="@ref mpi::mpi_type< bool >" title="mpi_type<bool>"/>
3434
<tab type="user" url="@ref mpi::mpi_type< char >" title="mpi_type<char>"/>
35+
<tab type="user" url="@ref mpi::mpi_type< const T >" title="mpi_type<const T>"/>
36+
<tab type="user" url="@ref mpi::mpi_type< double >" title="mpi_type<double>"/>
37+
<tab type="user" url="@ref mpi::mpi_type< E >" title="mpi_type<E>"/>
38+
<tab type="user" url="@ref mpi::mpi_type< float >" title="mpi_type<float>"/>
3539
<tab type="user" url="@ref mpi::mpi_type< int >" title="mpi_type<int>"/>
3640
<tab type="user" url="@ref mpi::mpi_type< long >" title="mpi_type<long>"/>
3741
<tab type="user" url="@ref mpi::mpi_type< long long >" title="mpi_type<long long>"/>
38-
<tab type="user" url="@ref mpi::mpi_type< double >" title="mpi_type<double>"/>
39-
<tab type="user" url="@ref mpi::mpi_type< float >" title="mpi_type<float>"/>
42+
<tab type="user" url="@ref mpi::mpi_type< S >" title="mpi_type<S>"/>
4043
<tab type="user" url="@ref mpi::mpi_type< std::complex< double > >" title="mpi_type<std::complex<double>>"/>
44+
<tab type="user" url="@ref mpi::mpi_type< std::tuple< Ts... > >" title="mpi_type<std::tuple>"/>
45+
<tab type="user" url="@ref mpi::mpi_type< U >" title="mpi_type<U>"/>
4146
<tab type="user" url="@ref mpi::mpi_type< unsigned int >" title="mpi_type<unsigned int>"/>
4247
<tab type="user" url="@ref mpi::mpi_type< unsigned long >" title="mpi_type<unsigned long>"/>
4348
<tab type="user" url="@ref mpi::mpi_type< unsigned long long >" title="mpi_type<unsigned long long>"/>
44-
<tab type="user" url="@ref mpi::mpi_type< std::tuple< Ts... > >" title="mpi_type<std::tuple>"/>
4549
</tab>
4650
</tab>
4751
<tab type="user" url="@ref coll_comm" title="Collective MPI communication"/>
@@ -56,6 +60,7 @@
5660
</tab>
5761
<tab type="usergroup" url="@ref utilities" title="Utilities">
5862
<tab type="user" url="@ref mpi::contiguous_sized_range" title="contiguous_sized_range"/>
63+
<tab type="user" url="@ref mpi::Serializable" title="Serializable"/>
5964
</tab>
6065
<tab type="filelist" visible="yes" title="" intro=""/>
6166
</tab>

doc/ex3.md

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
[TOC]
44

5-
In this example, we show how to use mpi::mpi_type_from_tie, mpi::map_C_function and mpi::map_add to register a new MPI datatype and to define MPI operations for it.
5+
In this example, we show how to register a new MPI datatype and how to use mpi::map_C_function and mpi::map_add to
6+
define MPI operations for it.
67

78
```cpp
89
#include <mpi/mpi.hpp>
@@ -19,14 +20,11 @@ inline my_complex operator+(const my_complex& z1, const my_complex& z2) {
1920
return { z1.real + z2.real, z1.imag + z2.imag };
2021
}
2122

22-
// define a tie_data function for mpi_type_from_tie
23+
// define a tie_data function for my_complex to make it MPI compatible
2324
inline auto tie_data(const my_complex& z) {
2425
return std::tie(z.real, z.imag);
2526
}
2627

27-
// register my_complex as an MPI type
28-
template <> struct mpi::mpi_type<my_complex> : mpi::mpi_type_from_tie<my_complex> {};
29-
3028
int main(int argc, char *argv[]) {
3129
// initialize MPI environment
3230
mpi::environment env(argc, argv);

0 commit comments

Comments
 (0)