]> https://gitweb.dealii.org/ - dealii.git/commitdiff
N_Vector now returns a pointer to MPI_Comm 12921/head
authorSebastian Proell <sebastian.proell@tum.de>
Fri, 5 Nov 2021 15:52:05 +0000 (16:52 +0100)
committerSebastian Proell <sebastian.proell@tum.de>
Fri, 5 Nov 2021 15:52:05 +0000 (16:52 +0100)
include/deal.II/sundials/n_vector.templates.h
tests/sundials/n_vector.cc

index f48798e41501e720adb88555feb8edefd25b186b..002eb5eb66d7e9c74e98dbe628027f4965e694b6 100644 (file)
@@ -265,13 +265,13 @@ namespace SUNDIALS
       template <
         typename VectorType,
         typename std::enable_if_t<!IsBlockVector<VectorType>::value, int> = 0>
-      MPI_Comm
+      const MPI_Comm &
       get_communicator(N_Vector v);
 
       template <
         typename VectorType,
         typename std::enable_if_t<IsBlockVector<VectorType>::value, int> = 0>
-      MPI_Comm
+      const MPI_Comm &
       get_communicator(N_Vector v);
 
       /**
@@ -503,7 +503,7 @@ namespace SUNDIALS
 
       template <typename VectorType,
                 std::enable_if_t<IsBlockVector<VectorType>::value, int>>
-      MPI_Comm
+      const MPI_Comm &
       get_communicator(N_Vector v)
       {
         return unwrap_nvector_const<VectorType>(v)
@@ -515,7 +515,7 @@ namespace SUNDIALS
 
       template <typename VectorType,
                 std::enable_if_t<!IsBlockVector<VectorType>::value, int>>
-      MPI_Comm
+      const MPI_Comm &
       get_communicator(N_Vector v)
       {
         return unwrap_nvector_const<VectorType>(v)->get_mpi_communicator();
@@ -545,7 +545,8 @@ namespace SUNDIALS
         (void)v;
         return nullptr;
 #  else
-        return get_communicator<VectorType>(v);
+        // We need to cast away const here, as SUNDIALS demands a pure `void *`.
+        return &(const_cast<MPI_Comm &>(get_communicator<VectorType>(v)));
 #  endif
       }
 
index ab5d1b4c3290f0850b4b0c7e31a74abf81e59233..14eb7a5a363964d5906b6742063a24ab5c18cbdf 100644 (file)
@@ -329,7 +329,9 @@ test_get_communicator()
 {
   auto vector   = create_test_vector<VectorType>();
   auto n_vector = make_nvector_view(vector);
-  Assert(N_VGetCommunicator(n_vector) == MPI_COMM_WORLD, NVectorTestError());
+  Assert(*static_cast<MPI_Comm *>(N_VGetCommunicator(n_vector)) ==
+           MPI_COMM_WORLD,
+         NVectorTestError());
 
   deallog << "test_get_communicator OK" << std::endl;
 }

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.