42 #ifndef TEUCHOS_DETAILS_MPITYPETRAITS_HPP 43 #define TEUCHOS_DETAILS_MPITYPETRAITS_HPP 49 #include "Teuchos_config.h" 51 #ifdef HAVE_TEUCHOS_MPI 74 static const bool isSpecialized =
false;
92 static const bool needsFree =
false;
110 static MPI_Datatype getType (
const T&) {
116 return MPI_DATATYPE_NULL;
128 class MpiTypeTraits<char> {
131 static const bool isSpecialized =
true;
135 static const bool needsFree =
false;
138 static MPI_Datatype getType (
const char&) {
143 static MPI_Datatype getType () {
152 class MpiTypeTraits<unsigned char> {
155 static const bool isSpecialized =
true;
159 static const bool needsFree =
false;
162 static MPI_Datatype getType (
const unsigned char&) {
163 return MPI_UNSIGNED_CHAR;
167 static MPI_Datatype getType () {
168 return MPI_UNSIGNED_CHAR;
177 class MpiTypeTraits<signed char> {
180 static const bool isSpecialized =
true;
184 static const bool needsFree =
false;
187 static MPI_Datatype getType (
const signed char&) {
188 return MPI_SIGNED_CHAR;
192 static MPI_Datatype getType () {
193 return MPI_SIGNED_CHAR;
196 #endif // MPI_VERSION >= 2 239 computeStdComplexMpiDatatype (
const std::complex<T>& z)
241 #ifdef HAVE_TEUCHOSCORE_CXX11 242 static_assert (MpiTypeTraits<T>::isSpecialized,
"This function only " 243 "works if MpiTypeTraits<T>::isSpecialized.");
244 static_assert (! MpiTypeTraits<T>::needsFree,
"This function requires " 245 "! MpiTypeTraits<T>::needsFree, since otherwise it would " 247 #endif // HAVE_TEUCHOSCORE_CXX11 251 MPI_Datatype innerDatatype = MpiTypeTraits<T>::getType (z.real ());
252 MPI_Datatype outerDatatype;
259 if (
sizeof (std::complex<T>) == 2 *
sizeof (T)) {
260 (void) MPI_Type_contiguous (2, innerDatatype, &outerDatatype);
268 MPI_Aint arrayOfDisplacements[3];
269 MPI_Datatype arrayOfTypes[3];
271 #ifdef HAVE_TEUCHOSCORE_CXX11 273 static_assert (
sizeof (MyComplex<T>) ==
sizeof (std::complex<T>),
274 "Attempt to construct a struct of the same size and layout " 275 "as std::complex<T> failed.");
276 #endif // HAVE_TEUCHOSCORE_CXX11 286 arrayOfDisplacements[0] =
reinterpret_cast<char*
>(&z2.re) - reinterpret_cast<char*>(&z2);
287 arrayOfTypes[0] = innerDatatype;
291 arrayOfDisplacements[1] =
reinterpret_cast<char*
>(&z2.im) - reinterpret_cast<char*>(&z2);
292 arrayOfTypes[1] = innerDatatype;
297 arrayOfDisplacements[2] =
sizeof (MyComplex<T>);
298 arrayOfTypes[2] = MPI_UB;
299 #endif // MPI_VERSION < 2 303 (void) MPI_Type_struct (3, blockLengths, arrayOfDisplacements,
304 arrayOfTypes, &outerDatatype);
307 (void) MPI_Type_create_struct (2, blockLengths, arrayOfDisplacements,
308 arrayOfTypes, &outerDatatype);
309 #endif // MPI_VERSION < 2 312 MPI_Type_commit (&outerDatatype);
313 return outerDatatype;
321 class MpiTypeTraits< std::complex<double> > {
324 static const bool hasMpi3 =
true;
326 static const bool hasMpi3 =
false;
327 #endif // MPI_VERSION >= 3 331 static const bool isSpecialized =
true;
335 static const bool needsFree = ! hasMpi3;
338 static MPI_Datatype getType (
const std::complex<double>& z) {
341 return MPI_C_DOUBLE_COMPLEX;
343 return MPI_DATATYPE_NULL;
344 #endif // MPI_VERSION >= 3 347 return Impl::computeStdComplexMpiDatatype<double> (z);
352 static MPI_Datatype getType () {
355 return MPI_C_DOUBLE_COMPLEX;
357 return MPI_DATATYPE_NULL;
358 #endif // MPI_VERSION >= 3 363 std::complex<double> z (3.0, 4.0);
364 return Impl::computeStdComplexMpiDatatype<double> (z);
370 class MpiTypeTraits< std::complex<float> > {
373 static const bool hasMpi3 =
true;
375 static const bool hasMpi3 =
false;
376 #endif // MPI_VERSION >= 3 380 static const bool isSpecialized =
true;
384 static const bool needsFree = ! hasMpi3;
387 static MPI_Datatype getType (
const std::complex<float>& z) {
390 return MPI_C_FLOAT_COMPLEX;
392 return MPI_DATATYPE_NULL;
393 #endif // MPI_VERSION >= 3 396 return Impl::computeStdComplexMpiDatatype<float> (z);
401 static MPI_Datatype getType () {
404 return MPI_C_FLOAT_COMPLEX;
406 return MPI_DATATYPE_NULL;
407 #endif // MPI_VERSION >= 3 412 std::complex<float> z (3.0, 4.0);
413 return Impl::computeStdComplexMpiDatatype<float> (z);
420 class MpiTypeTraits<double> {
423 static const bool isSpecialized =
true;
427 static const bool needsFree =
false;
430 static MPI_Datatype getType (
const double&) {
435 static MPI_Datatype getType () {
442 class MpiTypeTraits<float> {
445 static const bool isSpecialized =
true;
449 static const bool needsFree =
false;
452 static MPI_Datatype getType (
const float&) {
457 static MPI_Datatype getType () {
462 #ifdef HAVE_TEUCHOS_LONG_LONG_INT 465 class MpiTypeTraits<long long> {
468 static const bool isSpecialized =
true;
472 static const bool needsFree =
false;
475 static MPI_Datatype getType (
const long long&) {
476 return MPI_LONG_LONG;
480 static MPI_Datatype getType () {
481 return MPI_LONG_LONG;
491 class MpiTypeTraits<unsigned long long> {
494 static const bool isSpecialized =
true;
498 static const bool needsFree =
false;
501 static MPI_Datatype getType (
const unsigned long long&) {
502 return MPI_UNSIGNED_LONG_LONG;
506 static MPI_Datatype getType () {
507 return MPI_UNSIGNED_LONG_LONG;
510 #endif // MPI_VERSION >= 2 511 #endif // HAVE_TEUCHOS_LONG_LONG_INT 515 class MpiTypeTraits<long> {
518 static const bool isSpecialized =
true;
522 static const bool needsFree =
false;
525 static MPI_Datatype getType (
const long&) {
530 static MPI_Datatype getType () {
537 class MpiTypeTraits<unsigned long> {
540 static const bool isSpecialized =
true;
544 static const bool needsFree =
false;
547 static MPI_Datatype getType (
const unsigned long&) {
548 return MPI_UNSIGNED_LONG;
552 static MPI_Datatype getType () {
553 return MPI_UNSIGNED_LONG;
559 class MpiTypeTraits<int> {
562 static const bool isSpecialized =
true;
566 static const bool needsFree =
false;
569 static MPI_Datatype getType (
const int&) {
574 static MPI_Datatype getType () {
581 class MpiTypeTraits<unsigned int> {
584 static const bool isSpecialized =
true;
588 static const bool needsFree =
false;
591 static MPI_Datatype getType (
const unsigned int&) {
596 static MPI_Datatype getType () {
603 class MpiTypeTraits<short> {
606 static const bool isSpecialized =
true;
610 static const bool needsFree =
false;
613 static MPI_Datatype getType (
const short&) {
618 static MPI_Datatype getType () {
625 class MpiTypeTraits<unsigned short> {
628 static const bool isSpecialized =
true;
632 static const bool needsFree =
false;
635 static MPI_Datatype getType (
const unsigned short&) {
636 return MPI_UNSIGNED_SHORT;
640 static MPI_Datatype getType () {
641 return MPI_UNSIGNED_SHORT;
648 #endif // HAVE_TEUCHOS_MPI 650 #endif // TEUCHOS_DETAILS_MPITYPETRAITS_HPP Namespace of implementation details.
The Teuchos namespace contains all of the classes, structs and enums used by Teuchos, as well as a number of utility routines.