12#ifdef HAVE_TPETRACORE_MPI
30computeKokkosComplexMpiDatatypeImpl(const ::Kokkos::complex<T>& z) {
31 static_assert(MpiTypeTraits<T>::isSpecialized,
33 "works if MpiTypeTraits<T>::isSpecialized.");
34 static_assert(!MpiTypeTraits<T>::needsFree,
35 "This function requires "
36 "! MpiTypeTraits<T>::needsFree, since otherwise it would "
40 MPI_Datatype innerDatatype = MpiTypeTraits<T>::getType(z.real());
41 MPI_Datatype outerDatatype;
48 if (
sizeof(::Kokkos::complex<T>) == 2 *
sizeof(T)) {
49 (void)MPI_Type_contiguous(2, innerDatatype, &outerDatatype);
56 MPI_Aint arrayOfDisplacements[3];
57 MPI_Datatype arrayOfTypes[3];
60 static_assert(
sizeof(MyComplex<T>) ==
sizeof(::Kokkos::complex<T>),
61 "Attempt to construct a struct of the same size and layout "
62 "as Kokkos::complex<T> failed.");
63 ::Teuchos::Details::Impl::MyComplex<T> z2;
72 arrayOfDisplacements[0] =
reinterpret_cast<uintptr_t
>(&z2.re) -
reinterpret_cast<uintptr_t
>(&z2);
73 arrayOfTypes[0] = innerDatatype;
77 arrayOfDisplacements[1] =
reinterpret_cast<uintptr_t
>(&z2.im) -
reinterpret_cast<uintptr_t
>(&z2);
78 arrayOfTypes[1] = innerDatatype;
83 arrayOfDisplacements[2] =
sizeof(MyComplex<T>);
84 arrayOfTypes[2] = MPI_UB;
89 (void)MPI_Type_struct(3, blockLengths, arrayOfDisplacements,
90 arrayOfTypes, &outerDatatype);
93 (void)MPI_Type_create_struct(2, blockLengths, arrayOfDisplacements,
94 arrayOfTypes, &outerDatatype);
98 MPI_Type_commit(&outerDatatype);
104computeKokkosComplexMpiDatatype(const ::Kokkos::complex<double>& z) {
105 return computeKokkosComplexMpiDatatypeImpl<double>(z);
110computeKokkosComplexMpiDatatype(const ::Kokkos::complex<float>& z) {
111 return computeKokkosComplexMpiDatatypeImpl<float>(z);
117MpiTypeTraits< ::Kokkos::complex<double> >::
118 getType(const ::Kokkos::complex<double>& z) {
121 return MPI_C_DOUBLE_COMPLEX;
123 return MPI_DATATYPE_NULL;
126 return Impl::computeKokkosComplexMpiDatatype(z);
131MpiTypeTraits< ::Kokkos::complex<double> >::
135 return MPI_C_DOUBLE_COMPLEX;
137 return MPI_DATATYPE_NULL;
142 ::Kokkos::complex<double> z(3.0, 4.0);
143 return Impl::computeKokkosComplexMpiDatatype(z);
148MpiTypeTraits< ::Kokkos::complex<float> >::
149 getType(const ::Kokkos::complex<float>& z) {
152 return MPI_C_FLOAT_COMPLEX;
154 return MPI_DATATYPE_NULL;
157 return Impl::computeKokkosComplexMpiDatatype(z);
162MpiTypeTraits< ::Kokkos::complex<float> >::
166 return MPI_C_FLOAT_COMPLEX;
168 return MPI_DATATYPE_NULL;
173 ::Kokkos::complex<float> z(3.0, 4.0);
174 return Impl::computeKokkosComplexMpiDatatype(z);
Add specializations of Teuchos::Details::MpiTypeTraits for Kokkos::complex<float> and Kokkos::complex...
Implementation details of Tpetra.