44 #ifndef TPETRA_DETAILS_MPITYPETRAITS_HPP 45 #define TPETRA_DETAILS_MPITYPETRAITS_HPP 71 #include "TpetraCore_config.h" 72 #ifdef HAVE_TPETRACORE_MPI 74 #include "Kokkos_Complex.hpp" 75 #include "Teuchos_Details_MpiTypeTraits.hpp" 99 computeKokkosComplexMpiDatatype (const ::Kokkos::complex<T>& z)
101 static_assert (MpiTypeTraits<T>::isSpecialized,
"This function only " 102 "works if MpiTypeTraits<T>::isSpecialized.");
103 static_assert (! MpiTypeTraits<T>::needsFree,
"This function requires " 104 "! MpiTypeTraits<T>::needsFree, since otherwise it would " 108 MPI_Datatype innerDatatype = MpiTypeTraits<T>::getType (z.real ());
109 MPI_Datatype outerDatatype;
116 if (
sizeof ( ::Kokkos::complex<T>) == 2 *
sizeof (T)) {
117 (void) MPI_Type_contiguous (2, innerDatatype, &outerDatatype);
125 MPI_Aint arrayOfDisplacements[3];
126 MPI_Datatype arrayOfTypes[3];
129 static_assert (
sizeof (MyComplex<T>) ==
sizeof ( ::Kokkos::complex<T>),
130 "Attempt to construct a struct of the same size and layout " 131 "as Kokkos::complex<T> failed.");
132 ::Teuchos::Details::Impl::MyComplex<T> z2;
141 arrayOfDisplacements[0] =
reinterpret_cast<uintptr_t
> (&z2.re) - reinterpret_cast<uintptr_t> (&z2);
142 arrayOfTypes[0] = innerDatatype;
146 arrayOfDisplacements[1] =
reinterpret_cast<uintptr_t
> (&z2.im) - reinterpret_cast<uintptr_t> (&z2);
147 arrayOfTypes[1] = innerDatatype;
152 arrayOfDisplacements[2] =
sizeof (MyComplex<T>);
153 arrayOfTypes[2] = MPI_UB;
154 #endif // MPI_VERSION < 2 158 (void) MPI_Type_struct (3, blockLengths, arrayOfDisplacements,
159 arrayOfTypes, &outerDatatype);
162 (void) MPI_Type_create_struct (2, blockLengths, arrayOfDisplacements,
163 arrayOfTypes, &outerDatatype);
164 #endif // MPI_VERSION < 2 167 MPI_Type_commit (&outerDatatype);
168 return outerDatatype;
175 class MpiTypeTraits< ::Kokkos::complex<double> > {
178 static const bool hasMpi3 =
true;
180 static const bool hasMpi3 =
false;
181 #endif // MPI_VERSION >= 3 185 static const bool isSpecialized =
true;
189 static const bool needsFree = ! hasMpi3;
192 static MPI_Datatype getType (const ::Kokkos::complex<double>& z) {
195 return MPI_C_DOUBLE_COMPLEX;
197 return MPI_DATATYPE_NULL;
198 #endif // MPI_VERSION >= 3 201 return Impl::computeKokkosComplexMpiDatatype<double> (z);
206 static MPI_Datatype getType () {
209 return MPI_C_DOUBLE_COMPLEX;
211 return MPI_DATATYPE_NULL;
212 #endif // MPI_VERSION >= 3 217 ::Kokkos::complex<double> z (3.0, 4.0);
218 return Impl::computeKokkosComplexMpiDatatype<double> (z);
224 class MpiTypeTraits< ::Kokkos::complex<float> > {
227 static const bool hasMpi3 =
true;
229 static const bool hasMpi3 =
false;
230 #endif // MPI_VERSION >= 3 234 static const bool isSpecialized =
true;
238 static const bool needsFree = ! hasMpi3;
241 static MPI_Datatype getType (const ::Kokkos::complex<float>& z) {
244 return MPI_C_FLOAT_COMPLEX;
246 return MPI_DATATYPE_NULL;
247 #endif // MPI_VERSION >= 3 250 return Impl::computeKokkosComplexMpiDatatype<float> (z);
255 static MPI_Datatype getType () {
258 return MPI_C_FLOAT_COMPLEX;
260 return MPI_DATATYPE_NULL;
261 #endif // MPI_VERSION >= 3 266 ::Kokkos::complex<float> z (3.0, 4.0);
267 return Impl::computeKokkosComplexMpiDatatype<float> (z);
279 using ::Teuchos::Details::MpiTypeTraits;
284 #endif // HAVE_TPETRACORE_MPI 285 #endif // TPETRA_DETAILS_MPITYPETRAITS_HPP Namespace Tpetra contains the class and methods constituting the Tpetra library.
Implementation details of Tpetra.