]> https://gitweb.dealii.org/ - dealii.git/commitdiff
N_Vector get_communicator return nullptr in serial 11736/head
authorSebastian Proell <proell@lnm.mw.tum.de>
Fri, 12 Feb 2021 15:34:27 +0000 (16:34 +0100)
committerSebastian Proell <proell@lnm.mw.tum.de>
Fri, 12 Feb 2021 17:26:48 +0000 (18:26 +0100)
include/deal.II/sundials/n_vector.templates.h
tests/sundials/n_vector.cc

index 55e08e77d00bcb8df55a08d8aacd5f28fbfeaceb..c1c10838cd62119526497708bcda7b6c3c11b711 100644 (file)
@@ -252,22 +252,13 @@ namespace SUNDIALS
 
       template <
         typename VectorType,
-        typename std::enable_if_t<is_serial_vector<VectorType>::value, int> = 0>
-      MPI_Comm get_communicator(N_Vector);
-
-      template <
-        typename VectorType,
-        typename std::enable_if_t<!is_serial_vector<VectorType>::value &&
-                                    !IsBlockVector<VectorType>::value,
-                                  int> = 0>
+        typename std::enable_if_t<!IsBlockVector<VectorType>::value, int> = 0>
       MPI_Comm
       get_communicator(N_Vector v);
 
       template <
         typename VectorType,
-        typename std::enable_if_t<!is_serial_vector<VectorType>::value &&
-                                    IsBlockVector<VectorType>::value,
-                                  int> = 0>
+        typename std::enable_if_t<IsBlockVector<VectorType>::value, int> = 0>
       MPI_Comm
       get_communicator(N_Vector v);
 
@@ -275,17 +266,17 @@ namespace SUNDIALS
        * Sundials likes a void* but we want to use the above functions
        * internally with a safe type.
        */
-      template <typename VectorType>
+      template <
+        typename VectorType,
+        typename std::enable_if_t<is_serial_vector<VectorType>::value, int> = 0>
       inline void *
-      get_communicator_as_void_ptr(N_Vector v)
-      {
-#  ifndef DEAL_II_WITH_MPI
-        (void)v;
-        return nullptr;
-#  else
-        return get_communicator<VectorType>(v);
-#  endif
-      }
+      get_communicator_as_void_ptr(N_Vector v);
+
+      template <typename VectorType,
+                typename std::enable_if_t<!is_serial_vector<VectorType>::value,
+                                          int> = 0>
+      inline void *
+      get_communicator_as_void_ptr(N_Vector v);
 
     } // namespace NVectorOperations
   }   // namespace internal
@@ -489,34 +480,47 @@ SUNDIALS::internal::NVectorOperations::destroy(N_Vector v)
 
 
 template <typename VectorType,
-          std::enable_if_t<is_serial_vector<VectorType>::value, int>>
-MPI_Comm SUNDIALS::internal::NVectorOperations::get_communicator(N_Vector)
+          std::enable_if_t<IsBlockVector<VectorType>::value, int>>
+MPI_Comm
+SUNDIALS::internal::NVectorOperations::get_communicator(N_Vector v)
 {
-  return MPI_COMM_SELF;
+  return unwrap_nvector_const<VectorType>(v)->block(0).get_mpi_communicator();
 }
 
 
 
 template <typename VectorType,
-          std::enable_if_t<!is_serial_vector<VectorType>::value &&
-                             IsBlockVector<VectorType>::value,
-                           int>>
+          std::enable_if_t<!IsBlockVector<VectorType>::value, int>>
 MPI_Comm
 SUNDIALS::internal::NVectorOperations::get_communicator(N_Vector v)
 {
-  return unwrap_nvector_const<VectorType>(v)->block(0).get_mpi_communicator();
+  return unwrap_nvector_const<VectorType>(v)->get_mpi_communicator();
 }
 
 
 
 template <typename VectorType,
-          std::enable_if_t<!is_serial_vector<VectorType>::value &&
-                             !IsBlockVector<VectorType>::value,
-                           int>>
-MPI_Comm
-SUNDIALS::internal::NVectorOperations::get_communicator(N_Vector v)
+          typename std::enable_if_t<is_serial_vector<VectorType>::value, int>>
+void *
+  SUNDIALS::internal::NVectorOperations::get_communicator_as_void_ptr(N_Vector)
 {
-  return unwrap_nvector_const<VectorType>(v)->get_mpi_communicator();
+  // required by SUNDIALS: MPI-unaware vectors should return the nullptr as comm
+  return nullptr;
+}
+
+
+
+template <typename VectorType,
+          typename std::enable_if_t<!is_serial_vector<VectorType>::value, int>>
+void *
+SUNDIALS::internal::NVectorOperations::get_communicator_as_void_ptr(N_Vector v)
+{
+#  ifndef DEAL_II_WITH_MPI
+  (void)v;
+  return nullptr;
+#  else
+  return get_communicator<VectorType>(v);
+#  endif
 }
 
 
index 89e5414129a0a3b43e25f1ba26dcbfe9d44ea0f5..80b60017bf4461b03629146883c4e335ab17e480 100644 (file)
@@ -314,6 +314,7 @@ test_get_communicator()
 {
   auto vector   = create_test_vector<VectorType>();
   auto n_vector = make_nvector_view(vector);
+  // required by SUNDIALS: MPI-unaware vectors should return the nullptr
   Assert(N_VGetCommunicator(n_vector) == nullptr, 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.