Skip to content

Commit

Permalink
introduced madness:is_trivially_copyable trait (can be specialized to…
Browse files Browse the repository at this point in the history
… override legally-required limitations of std::is_trivially_copyable)
  • Loading branch information
evaleev committed Dec 18, 2024
1 parent 2dfa2f4 commit 3f33d06
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 7 additions & 0 deletions src/madness/world/type_traits.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,13 @@ namespace madness {
template <typename T> struct is_any_function_pointer<T, std::enable_if_t<std::is_member_function_pointer<T>::value || is_function_pointer_v<T>>> : public std::true_type {};
template <typename T> constexpr bool is_any_function_pointer_v = is_any_function_pointer<T>::value;

/// trait for trivial (=bitwise) copyability of T, defaults to std::is_trivially_copyable<T> but can be specialized as needed
template <typename T>
struct is_trivially_copyable : std::is_trivially_copyable<T> {};

template <typename T>
inline constexpr bool is_trivially_copyable_v = is_trivially_copyable<T>::value;

/// This defines stuff that is serializable by bitwise copy.
/// \warning This reports true for \c T that is an aggregate type
/// (struct or array) that includes pointers.
Expand Down
8 changes: 4 additions & 4 deletions src/madness/world/worldgop.h
Original file line number Diff line number Diff line change
Expand Up @@ -730,19 +730,19 @@ namespace madness {
/// Broadcasts typed contiguous data from process root while still processing AM & tasks

/// Optimizations can be added for long messages
template <typename T, typename = std::enable_if_t<std::is_trivially_copyable_v<T>>>
template <typename T, typename = std::enable_if_t<madness::is_trivially_copyable_v<T>>>
inline void broadcast(T* buf, size_t nelem, ProcessID root) {
broadcast((void *) buf, nelem*sizeof(T), root);
}

/// Broadcast of a scalar from node 0 to all other nodes
template <typename T, typename = std::enable_if_t<std::is_trivially_copyable_v<T>>>
template <typename T, typename = std::enable_if_t<madness::is_trivially_copyable_v<T>>>
void broadcast(T& t) {
broadcast(&t, 1, 0);
}

/// Broadcast of a scalar from node root to all other nodes
template <typename T, typename = std::enable_if_t<std::is_trivially_copyable_v<T>>>
template <typename T, typename = std::enable_if_t<madness::is_trivially_copyable_v<T>>>
void broadcast(T& t, ProcessID root) {
broadcast(&t, 1, root);
}
Expand Down Expand Up @@ -781,7 +781,7 @@ namespace madness {
/// Optimizations can be added for long messages and to reduce the memory footprint
template <typename T, class opT>
void reduce(T* buf, std::size_t nelem, opT op) {
static_assert(std::is_trivially_copyable_v<T>, "T must be trivially copyable");
static_assert(madness::is_trivially_copyable_v<T>, "T must be trivially copyable");

ProcessID parent, child0, child1;
world_.mpi.binary_tree_info(0, parent, child0, child1);
Expand Down

0 comments on commit 3f33d06

Please sign in to comment.