]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Add a test.
authorWolfgang Bangerth <bangerth@colostate.edu>
Sun, 27 Feb 2022 00:33:47 +0000 (17:33 -0700)
committerWolfgang Bangerth <bangerth@colostate.edu>
Thu, 3 Mar 2022 21:42:52 +0000 (14:42 -0700)
tests/mpi/mpi_type_id_for_type_01.cc [new file with mode: 0644]
tests/mpi/mpi_type_id_for_type_01.output [new file with mode: 0644]

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 (file)
index 0000000..f76075b
--- /dev/null
@@ -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 <deal.II/base/mpi.h>
+#include <deal.II/base/template_constraints.h>
+
+#include <cstdint>
+
+#include "../tests.h"
+
+
+
+template <typename T>
+using mpi_type_id_for_type_t =
+  decltype(Utilities::MPI::internal::MPIDataTypes::mpi_type_id(
+    &std::declval<const T &>()));
+
+
+template <typename T>
+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<mpi_type_id_for_type_t, T> << std::endl;
+  deallog << "T[] is supported: "
+          << internal::is_supported_operation<mpi_type_id_for_type_t,
+                                              T[]> << std::endl;
+  deallog << "T* is supported: "
+          << internal::is_supported_operation<mpi_type_id_for_type_t,
+                                              T *> << std::endl;
+
+  Assert(Utilities::MPI::mpi_type_id_for_type<T> == 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>(#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 <X> ---------------" << std::endl;
+  deallog
+    << "T is supported: "
+    << internal::is_supported_operation<mpi_type_id_for_type_t, T> << 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 (file)
index 0000000..b67252a
--- /dev/null
@@ -0,0 +1,63 @@
+
+DEAL::--------- Checking <signed char> ---------------
+DEAL::T is supported: true
+DEAL::T[] is supported: false
+DEAL::T* is supported: false
+DEAL::--------- Checking <unsigned char> ---------------
+DEAL::T is supported: true
+DEAL::T[] is supported: false
+DEAL::T* is supported: false
+DEAL::--------- Checking <wchar_t> ---------------
+DEAL::T is supported: true
+DEAL::T[] is supported: false
+DEAL::T* is supported: false
+DEAL::--------- Checking <short> ---------------
+DEAL::T is supported: true
+DEAL::T[] is supported: false
+DEAL::T* is supported: false
+DEAL::--------- Checking <unsigned short> ---------------
+DEAL::T is supported: true
+DEAL::T[] is supported: false
+DEAL::T* is supported: false
+DEAL::--------- Checking <int> ---------------
+DEAL::T is supported: true
+DEAL::T[] is supported: false
+DEAL::T* is supported: false
+DEAL::--------- Checking <unsigned int> ---------------
+DEAL::T is supported: true
+DEAL::T[] is supported: false
+DEAL::T* is supported: false
+DEAL::--------- Checking <long> ---------------
+DEAL::T is supported: true
+DEAL::T[] is supported: false
+DEAL::T* is supported: false
+DEAL::--------- Checking <unsigned long> ---------------
+DEAL::T is supported: true
+DEAL::T[] is supported: false
+DEAL::T* is supported: false
+DEAL::--------- Checking <long long> ---------------
+DEAL::T is supported: true
+DEAL::T[] is supported: false
+DEAL::T* is supported: false
+DEAL::--------- Checking <long long int> ---------------
+DEAL::T is supported: true
+DEAL::T[] is supported: false
+DEAL::T* is supported: false
+DEAL::--------- Checking <unsigned long long> ---------------
+DEAL::T is supported: true
+DEAL::T[] is supported: false
+DEAL::T* is supported: false
+DEAL::--------- Checking <float> ---------------
+DEAL::T is supported: true
+DEAL::T[] is supported: false
+DEAL::T* is supported: false
+DEAL::--------- Checking <double> ---------------
+DEAL::T is supported: true
+DEAL::T[] is supported: false
+DEAL::T* is supported: false
+DEAL::--------- Checking <long double> ---------------
+DEAL::T is supported: true
+DEAL::T[] is supported: false
+DEAL::T* is supported: false
+DEAL::--------- Checking <X> ---------------
+DEAL::T is supported: false

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.