From: Wolfgang Bangerth Date: Sun, 27 Feb 2022 00:33:47 +0000 (-0700) Subject: Add a test. X-Git-Tag: v9.4.0-rc1~413^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=44e8810d9a3638322b0d108eaa1d3932928279de;p=dealii.git Add a test. --- diff --git a/tests/mpi/mpi_type_id_for_type_01.cc b/tests/mpi/mpi_type_id_for_type_01.cc new file mode 100644 index 0000000000..f76075b3d1 --- /dev/null +++ b/tests/mpi/mpi_type_id_for_type_01.cc @@ -0,0 +1,107 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2022 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE.md at +// the top level directory of deal.II. +// +// --------------------------------------------------------------------- + + + +// Check Utilities::MPI::mpi_type_id_for_type + + +#include +#include + +#include + +#include "../tests.h" + + + +template +using mpi_type_id_for_type_t = + decltype(Utilities::MPI::internal::MPIDataTypes::mpi_type_id( + &std::declval())); + + +template +void +test(const char *type, MPI_Datatype mpi_type) +{ + deallog << std::boolalpha; + deallog << "--------- Checking <" << type << "> ---------------" << std::endl; + deallog + << "T is supported: " + << internal::is_supported_operation << std::endl; + deallog << "T[] is supported: " + << internal::is_supported_operation << std::endl; + deallog << "T* is supported: " + << internal::is_supported_operation << std::endl; + + Assert(Utilities::MPI::mpi_type_id_for_type == mpi_type, + ExcInternalError()); +} + + +int +main(int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + initlog(); + + // Go through the entire list of MPI-supported data types: +#define TEST(a, b) test(#a, b) + TEST(signed char, MPI_SIGNED_CHAR); + TEST(unsigned char, MPI_UNSIGNED_CHAR); + TEST(wchar_t, MPI_WCHAR); + TEST(short, MPI_SHORT); + TEST(unsigned short, MPI_UNSIGNED_SHORT); + TEST(int, MPI_INT); + TEST(unsigned int, MPI_UNSIGNED); + TEST(long, MPI_LONG); + TEST(unsigned long, MPI_UNSIGNED_LONG); + TEST(long long, MPI_LONG_LONG_INT); + TEST(long long int, MPI_LONG_LONG); + TEST(unsigned long long, MPI_UNSIGNED_LONG_LONG); + TEST(float, MPI_FLOAT); + TEST(double, MPI_DOUBLE); + TEST(long double, MPI_LONG_DOUBLE); + + // The following types have their own MPI tags, but these tags are + // aliases for some of the types above and consequently are + // indistinguishable even though the tags are distinguishable. That + // is: while the type system cannot distinguish between 'unsigned + // char' and 'uint8_t', the tags 'MPI_SIGNED_CHAR' and 'MPI_INT8_T' + // are different. We cannot test, then, that the tag we get for + // these types equals their tags... + + // TEST(int8_t, MPI_INT8_T); + // TEST(int16_t, MPI_INT16_T); + // TEST(int32_t, MPI_INT32_T); + // TEST(int64_t, MPI_INT64_T); + // TEST(uint8_t, MPI_UINT8_T); + // TEST(uint16_t, MPI_UINT16_T); + // TEST(uint32_t, MPI_UINT32_T); + // TEST(uint64_t, MPI_UINT64_T); + + // Now make sure that the following type is not supported: + struct X + {}; + + using T = X; + deallog << "--------- Checking ---------------" << std::endl; + deallog + << "T is supported: " + << internal::is_supported_operation << std::endl; +} diff --git a/tests/mpi/mpi_type_id_for_type_01.output b/tests/mpi/mpi_type_id_for_type_01.output new file mode 100644 index 0000000000..b67252a5ec --- /dev/null +++ b/tests/mpi/mpi_type_id_for_type_01.output @@ -0,0 +1,63 @@ + +DEAL::--------- Checking --------------- +DEAL::T is supported: true +DEAL::T[] is supported: false +DEAL::T* is supported: false +DEAL::--------- Checking --------------- +DEAL::T is supported: true +DEAL::T[] is supported: false +DEAL::T* is supported: false +DEAL::--------- Checking --------------- +DEAL::T is supported: true +DEAL::T[] is supported: false +DEAL::T* is supported: false +DEAL::--------- Checking --------------- +DEAL::T is supported: true +DEAL::T[] is supported: false +DEAL::T* is supported: false +DEAL::--------- Checking --------------- +DEAL::T is supported: true +DEAL::T[] is supported: false +DEAL::T* is supported: false +DEAL::--------- Checking --------------- +DEAL::T is supported: true +DEAL::T[] is supported: false +DEAL::T* is supported: false +DEAL::--------- Checking --------------- +DEAL::T is supported: true +DEAL::T[] is supported: false +DEAL::T* is supported: false +DEAL::--------- Checking --------------- +DEAL::T is supported: true +DEAL::T[] is supported: false +DEAL::T* is supported: false +DEAL::--------- Checking --------------- +DEAL::T is supported: true +DEAL::T[] is supported: false +DEAL::T* is supported: false +DEAL::--------- Checking --------------- +DEAL::T is supported: true +DEAL::T[] is supported: false +DEAL::T* is supported: false +DEAL::--------- Checking --------------- +DEAL::T is supported: true +DEAL::T[] is supported: false +DEAL::T* is supported: false +DEAL::--------- Checking --------------- +DEAL::T is supported: true +DEAL::T[] is supported: false +DEAL::T* is supported: false +DEAL::--------- Checking --------------- +DEAL::T is supported: true +DEAL::T[] is supported: false +DEAL::T* is supported: false +DEAL::--------- Checking --------------- +DEAL::T is supported: true +DEAL::T[] is supported: false +DEAL::T* is supported: false +DEAL::--------- Checking --------------- +DEAL::T is supported: true +DEAL::T[] is supported: false +DEAL::T* is supported: false +DEAL::--------- Checking --------------- +DEAL::T is supported: false