From 6702c6d6d7b2bde242f54d273c0f9cace9fe9f59 Mon Sep 17 00:00:00 2001
From: Stefano Zampini <stefano.zampini@gmail.com>
Date: Sun, 22 Jan 2023 15:40:41 +0300
Subject: [PATCH] Fix sundials test

---
 tests/sundials/n_vector.cc | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/tests/sundials/n_vector.cc b/tests/sundials/n_vector.cc
index a23fbcba81..2c18911145 100644
--- a/tests/sundials/n_vector.cc
+++ b/tests/sundials/n_vector.cc
@@ -29,6 +29,10 @@
 #include "../../include/deal.II/sundials/n_vector.templates.h"
 #include <deal.II/sundials/n_vector.h>
 
+#ifdef DEAL_II_WITH_MPI
+#  include <mpi.h>
+#endif
+
 #include "../tests.h"
 
 using namespace SUNDIALS::internal;
@@ -371,9 +375,16 @@ test_get_communicator()
                                     global_nvector_context
 #endif
   );
-  Assert(*static_cast<MPI_Comm *>(N_VGetCommunicator(n_vector)) ==
-           MPI_COMM_WORLD,
-         NVectorTestError());
+  // PETSc duplicates the user communicator. It does not make sense to
+  // compare MPI_Comm using "==", which is equivalent to MPI_IDENT.
+  // MPI_CONGRUENT indicates same group but different context (e.g. tags,
+  // keyvals, etc.)
+#ifdef DEAL_II_WITH_MPI
+  int  result;
+  auto comm = static_cast<MPI_Comm *>(N_VGetCommunicator(n_vector));
+  MPI_Comm_compare(*comm, MPI_COMM_WORLD, &result);
+  Assert(result == MPI_IDENT || result == MPI_CONGRUENT, NVectorTestError());
+#endif
 
   deallog << "test_get_communicator OK" << std::endl;
 }
-- 
2.39.5