From 8c670ba6d235b5fac5a8bae734e4ca2106b54444 Mon Sep 17 00:00:00 2001 From: Marc Fehling Date: Sat, 13 Apr 2024 21:17:42 +0200 Subject: [PATCH] Introduce get_communicator_by_value(). --- include/deal.II/sundials/n_vector.templates.h | 43 +++++++++++++++++-- 1 file changed, 40 insertions(+), 3 deletions(-) diff --git a/include/deal.II/sundials/n_vector.templates.h b/include/deal.II/sundials/n_vector.templates.h index c756a7ccdc..7671ea7d12 100644 --- a/include/deal.II/sundials/n_vector.templates.h +++ b/include/deal.II/sundials/n_vector.templates.h @@ -403,6 +403,14 @@ namespace SUNDIALS const MPI_Comm & get_communicator(N_Vector v); +# if DEAL_II_SUNDIALS_VERSION_GTE(7, 0, 0) + /** + * Sundials likes their own communicator type by value. + */ + template + inline SUNComm + get_communicator_by_value(N_Vector v); +# else /** * Sundials likes a void* but we want to use the above functions * internally with a safe type. @@ -410,6 +418,7 @@ namespace SUNDIALS template inline void * get_communicator_as_void_ptr(N_Vector v); +# endif } // namespace NVectorOperations } // namespace internal } // namespace SUNDIALS @@ -728,22 +737,45 @@ namespace SUNDIALS +# if DEAL_II_SUNDIALS_VERSION_GTE(7, 0, 0) + template + SUNComm + get_communicator_by_value(N_Vector v) + { +# ifndef DEAL_II_WITH_MPI + (void)v; + return SUN_COMM_NULL; +# else + if (is_serial_vector::value == false) + // SUNDIALS asks for a `SUNComm` object, which is a MPI-aware typedef + // for `MPI_Comm` or `int`. To be clear, we adopt the SUNDIALS + // interface here. + // + // Further, we need to cast away const here, as SUNDIALS demands the + // communicator by value. + return const_cast(get_communicator(v)); + else + return SUN_COMM_NULL; +# endif + } +# else template void * get_communicator_as_void_ptr(N_Vector v) { -# ifndef DEAL_II_WITH_MPI +# ifndef DEAL_II_WITH_MPI (void)v; return nullptr; -# else +# else if (is_serial_vector::value == false) // We need to cast away const here, as SUNDIALS demands a pure // `void*`. return &(const_cast(get_communicator(v))); else return nullptr; -# endif +# endif } +# endif @@ -1238,8 +1270,13 @@ namespace SUNDIALS v->ops->nvcloneempty = &NVectorOperations::clone_empty; v->ops->nvdestroy = &NVectorOperations::destroy; // v->ops->nvspace = undef; +# if DEAL_II_SUNDIALS_VERSION_GTE(7, 0, 0) + v->ops->nvgetcommunicator = + &NVectorOperations::get_communicator_by_value; +# else v->ops->nvgetcommunicator = &NVectorOperations::get_communicator_as_void_ptr; +# endif v->ops->nvgetlength = &NVectorOperations::get_global_length; /* standard vector operations */ -- 2.39.5