]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Make the SUNDIALS solvers usuable for serial vector types 5592/head
authorDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Wed, 6 Dec 2017 23:43:12 +0000 (00:43 +0100)
committerDaniel Arndt <daniel.arndt@iwr.uni-heidelberg.de>
Thu, 7 Dec 2017 00:21:58 +0000 (01:21 +0100)
source/sundials/arkode.cc
source/sundials/ida.cc
source/sundials/kinsol.cc
tests/sundials/serial_sundials.cc [new file with mode: 0644]
tests/sundials/serial_sundials.output [new file with mode: 0644]

index 33d62dbf70fe9f09da90518193719fdd36cee8ac..68ebed5cb8405b3eb9dad4e7dbba2df71cb03ca8 100644 (file)
@@ -221,7 +221,9 @@ namespace SUNDIALS
                              const MPI_Comm mpi_comm) :
     data(data),
     arkode_mem(nullptr),
-    communicator(Utilities::MPI::duplicate_communicator(mpi_comm))
+    communicator(is_serial_vector<VectorType>::value ?
+                 MPI_COMM_SELF :
+                 Utilities::MPI::duplicate_communicator(mpi_comm))
   {
     set_functions_to_trigger_an_assert();
   }
@@ -232,7 +234,11 @@ namespace SUNDIALS
     if (arkode_mem)
       ARKodeFree(&arkode_mem);
 #ifdef DEAL_II_WITH_MPI
-    MPI_Comm_free(&communicator);
+    if (is_serial_vector<VectorType>::value == false)
+      {
+        const int ierr = MPI_Comm_free(&communicator);
+        AssertThrowMPI(ierr);
+      }
 #endif
   }
 
index 3bbc1eada68b57b6e2d2520d1a8449ede09fb859..cd887d4ed75775d5d1e197e2b98aca6599541f0d 100644 (file)
@@ -142,7 +142,9 @@ namespace SUNDIALS
                        const MPI_Comm mpi_comm) :
     data(data),
     ida_mem(nullptr),
-    communicator(Utilities::MPI::duplicate_communicator(mpi_comm))
+    communicator(is_serial_vector<VectorType>::value ?
+                 MPI_COMM_SELF :
+                 Utilities::MPI::duplicate_communicator(mpi_comm))
   {
     set_functions_to_trigger_an_assert();
   }
@@ -153,7 +155,11 @@ namespace SUNDIALS
     if (ida_mem)
       IDAFree(&ida_mem);
 #ifdef DEAL_II_WITH_MPI
-    MPI_Comm_free(&communicator);
+    if (is_serial_vector<VectorType>::value == false)
+      {
+        const int ierr = MPI_Comm_free(&communicator);
+        AssertThrowMPI(ierr);
+      }
 #endif
   }
 
index d807fbfda068d5312f80102c4c5d8615a175152b..fe00b17db2cbf3e7a4815ed1a3bc918fd8ec8488 100644 (file)
@@ -148,7 +148,9 @@ namespace SUNDIALS
   KINSOL<VectorType>::KINSOL(const AdditionalData &data, const MPI_Comm mpi_comm) :
     data(data),
     kinsol_mem(nullptr),
-    communicator(Utilities::MPI::duplicate_communicator(mpi_comm))
+    communicator(is_serial_vector<VectorType>::value ?
+                 MPI_COMM_SELF :
+                 Utilities::MPI::duplicate_communicator(mpi_comm))
   {
     set_functions_to_trigger_an_assert();
   }
@@ -161,7 +163,11 @@ namespace SUNDIALS
     if (kinsol_mem)
       KINFree(&kinsol_mem);
 #ifdef DEAL_II_WITH_MPI
-    MPI_Comm_free(&communicator);
+    if (is_serial_vector<VectorType>::value == false)
+      {
+        const int ierr = MPI_Comm_free(&communicator);
+        AssertThrowMPI(ierr);
+      }
 #endif
   }
 
diff --git a/tests/sundials/serial_sundials.cc b/tests/sundials/serial_sundials.cc
new file mode 100644 (file)
index 0000000..9dd8b89
--- /dev/null
@@ -0,0 +1,44 @@
+//-----------------------------------------------------------
+//
+//    Copyright (C) 2017 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 at
+//    the top level of the deal.II distribution.
+//
+//-----------------------------------------------------------
+
+// Make sure that we can initialize the SUNDIALS solvers
+// for serial vector types without initializing MPI
+
+#include "../tests.h"
+#include <deal.II/lac/vector.h>
+#include <deal.II/sundials/arkode.h>
+#include <deal.II/sundials/ida.h>
+#include <deal.II/sundials/kinsol.h>
+
+
+int main()
+{
+  initlog();
+
+  SUNDIALS::IDA<Vector<double>> ida_solver;
+  (void) ida_solver;
+  deallog << "IDA OK" << std::endl;
+
+  SUNDIALS::KINSOL<Vector<double>> kinsol_solver;
+  (void) kinsol_solver;
+  deallog << "KINSOL OK" << std::endl;
+
+  SUNDIALS::ARKode<Vector<double>> arkode_solver;
+  (void) arkode_solver;
+  deallog << "ARKODE OK" << std::endl;
+
+  return 0;
+}
+
diff --git a/tests/sundials/serial_sundials.output b/tests/sundials/serial_sundials.output
new file mode 100644 (file)
index 0000000..779a52b
--- /dev/null
@@ -0,0 +1,4 @@
+
+DEAL::IDA OK
+DEAL::KINSOL OK
+DEAL::ARKODE OK

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.