opm-simulators
Loading...
Searching...
No Matches
Dune::detail::StructMPITraitsImpl< Struct, Members > Struct Template Reference

Generic MPI traits implementation for structs. More...

#include <ReservoirCouplingMpiTraits.hpp>

Static Public Member Functions

static MPI_Datatype getType ()

Static Public Attributes

static constexpr bool is_intrinsic = false

Detailed Description

template<class Struct, auto... Members>
struct Dune::detail::StructMPITraitsImpl< Struct, Members >

Generic MPI traits implementation for structs.

This class template provides automatic MPI datatype creation for C++ structs by analyzing the struct's member pointers. It generates an MPI_Datatype that correctly represents the memory layout of the struct, allowing it to be sent via MPI communication functions.

The implementation handles:

  • Scalar fields of MPI-compatible types
  • C-style arrays (T[N])
  • std::array<T, N> containers
  • Enum fields (using their underlying type)

Thread Safety: The MPI datatype is created exactly once using std::call_once() to ensure thread-safe initialization in case this code is called from multiple threads.

Usage Example:

struct MyData {
double value;
std::array<int, 3> counts;
};
// Define the trait by listing member pointers:
template<>
struct MPITraits<MyData>
: detail::StructMPITraits<MyData, &MyData::value, &MyData::counts>
{ };
// Now MyData can be sent via MPI:
MPI_Send(&data, 1, MPITraits<MyData>::getType(), dest, tag, comm);
Template Parameters
StructThe struct type for which to create an MPI datatype
MembersVariadic pack of pointers-to-members listing all fields to include

Assumptions: Each field of the struct must be either:

  • An already defined MPI type (int, double, float, etc.)
  • A C array or std::array of an already defined MPI type
  • An enum whose underlying type is an already defined MPI type
Note
The order of member pointers in the template argument list determines the field order in the MPI datatype
The datatype is automatically resized to account for struct padding
See also
MPITraits

The documentation for this struct was generated from the following file: