]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add wrappers for Paralution preconditioners.
authorturcksin <turcksin@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 2 Jun 2014 15:10:58 +0000 (15:10 +0000)
committerturcksin <turcksin@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 2 Jun 2014 15:10:58 +0000 (15:10 +0000)
git-svn-id: https://svn.dealii.org/branches/branch_paralution@33006 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/lac/paralution_precondition.h [new file with mode: 0644]
deal.II/include/deal.II/lac/paralution_solver.h
deal.II/include/deal.II/lac/paralution_sparse_matrix.h
deal.II/include/deal.II/lac/paralution_vector.h
deal.II/source/lac/CMakeLists.txt
deal.II/source/lac/paralution_precondition.cc [new file with mode: 0644]
deal.II/source/lac/paralution_solver.cc
deal.II/source/lac/paralution_sparse_matrix.cc
tests/lac/paralution_solver_01.cc
tests/lac/paralution_sparse_matrix_01.cc

diff --git a/deal.II/include/deal.II/lac/paralution_precondition.h b/deal.II/include/deal.II/lac/paralution_precondition.h
new file mode 100644 (file)
index 0000000..5f07ed9
--- /dev/null
@@ -0,0 +1,392 @@
+// ---------------------------------------------------------------------
+// $Id: paralution_precondition.h 30040 2013-07-18 17:06:48Z maier $
+//
+// Copyright (C) 2014 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.
+//
+// ---------------------------------------------------------------------
+
+#ifndef __deal2__paralution_precondition_h
+#define __deal2__paralution_precondition_h
+
+
+#include <deal.II/base/config.h>
+
+#ifdef DEAL_II_WITH_PARALUTION
+
+#include <deal.II/base/std_cxx1x/shared_ptr.h>
+
+#include <paralution.hpp>
+
+DEAL_II_NAMESPACE_OPEN
+
+
+namespace ParalutionWrappers
+{
+  /**
+   * The base class for the preconditioner classes using the Paralution
+   * functionality. In Paralution, the preconditioners are not built at the same
+   * time as the solver. Therefore, only the declaration is done in the
+   * preconditiner classes.
+   *
+   * @ingroup ParalutionWrappers
+   * @ingroup Preconditioners
+   * @author Bruno Turcksin, 2014
+   */
+  //TODO: preconditioners are missing
+  template <typename Number>
+  class PreconditionBase
+  {
+    public :
+      /**
+       * Standardized data struct to pipe additional flags to the
+       * preconditioner.
+       */
+      struct AdditionalData 
+      {};
+
+      /**
+       * Constructor. Does not do anything.
+       */
+      PreconditionBase ();
+
+      friend class SolverBase;
+
+    protected :
+      /**
+       * This is a pointer to the preconditioner object that is used when
+       * applying the preconditioner.
+       */
+      std_cxx1x::shared_ptr<paralution::Preconditioner<paralution::LocalMatrix<Number>,
+        paralution::LocalVector<Number>,Number> > preconditioner;
+  };
+
+
+
+  /**
+   * A wrapper for Jacobi preconditioner for Paralution matrices.
+   *
+   * @ingroup ParalutionWrappers
+   * @ingroup Preconditioners
+   * @author Bruno Turcksin, 2014
+   */
+  template <typename Number>
+  class PreconditionJacobi : public PreconditionBase<Number>
+  {
+    public :
+      /**
+       * Standardized data struct to pipe additional flags to the
+       * preconditioner.
+       */               
+      struct AdditionalData
+      {};
+
+      /**
+       * Constructor.
+       */
+      PreconditionJacobi ();
+
+  private :
+    /**
+     * Store a copy of the flags for this
+     * particular preconditioner.
+     */
+    AdditionalData additional_data;
+  };
+
+
+
+  /**
+   * A wrapper for Symmetric Gauss-Seidel for Paralution matrices.
+   *
+   * @ingroup ParalutionWrappers
+   * @ingroup Preconditioners
+   * @author Bruno Turcksin, 2014
+   */
+  template <typename Number>
+  class PreconditionSGS : public PreconditionBase<Number>
+  {
+    public :
+      /**
+       * Standardized data struct to pipe additional flags to the
+       * preconditioner.
+       */               
+      struct AdditionalData
+      {};
+
+      /**
+       * Constructor.
+       */
+      PreconditionSGS ();
+
+  private :
+    /**
+     * Store a copy of the flags for this
+     * particular preconditioner.
+     */
+    AdditionalData additional_data;
+
+  };
+
+
+
+  /**
+   * A wrapper for multi-colored Symmetric Gauss-Seidel for Paralution matrices.
+   *
+   * @ingroup ParalutionWrappers
+   * @ingroup Preconditioners
+   * @author Bruno Turcksin, 2014
+   */
+  template <typename Number>
+  class PreconditionMultiColoredSGS : public PreconditionBase<Number>
+  {
+    public :
+      /**
+       * Standardized data struct to pipe additional flags to the
+       * preconditioner.
+       */               
+      struct AdditionalData
+      {};
+
+      /**
+       * Constructor.
+       */
+      PreconditionMultiColoredSGS ();
+
+  private :
+    /**
+     * Store a copy of the flags for this
+     * particular preconditioner.
+     */
+    AdditionalData additional_data;
+
+  };
+
+
+
+  /**
+   * A wrapper for multi-colored SOR for Paralution matrices.
+   *
+   * @ingroup ParalutionWrappers
+   * @ingroup Preconditioners
+   * @author Bruno Turcksin, 2014
+   */
+  template <typename Number>
+  class PreconditionMultiColoredSOR : public PreconditionBase<Number>
+  {
+    public :
+      /**
+       * Standardized data struct to pipe additional flags to the
+       * preconditioner.
+       */
+      struct AdditionalData
+      {
+        /**
+         * Constructor. By default, set the damping parameter to one.
+         */
+        AdditionalData (const double omega = 1);
+
+        /**
+         * Relaxation parameter.
+         */
+        double omega;
+      };
+
+      /** 
+       * Constructor. Take additional flags if there are any.
+       */
+      PreconditionMultiColoredSOR (const AdditionalData &additional_data = AdditionalData());
+
+      /**
+       * This function changes the value of the additional flags.
+       */
+      void initialize (const AdditionalData &additional_data = AdditionalData());
+
+    private :
+      /**
+       * Store a copy of the flags for this particular preconditioner.
+       */
+      AdditionalData additional_data;
+  };
+
+
+
+  /**
+   * A wrapper for ILU(p) for Paralution matrices.
+   *
+   * @ingroup ParalutionWrappers
+   * @ingroup Preconditioners
+   * @author Bruno Turcksin, 2014
+   */
+  template <typename Number>
+  class PreconditionILU : public PreconditionBase<Number>
+  {
+    public :
+      /**
+       * Standardized data struct to pipe additional flags to the
+       * preconditioner.
+       */
+      struct AdditionalData
+      {
+        /**
+         * Constructor. By default, set the fill-in parameter to zero.
+         */
+        AdditionalData (const unsigned int levels = 0);
+
+        /**
+         * Fill-in parameter.
+         */
+        unsigned int levels;
+      };
+
+      /**
+       * Constructor. Take additional flags if there are any.
+       */
+      PreconditionILU (const AdditionalData &additional_data = AdditionalData());
+
+      /**
+       * This function changes the value of the additional flags.
+       */
+      void initialize (const AdditionalData &additional_data = AdditionalData());
+
+    private :
+      /**
+       * Store a copy of the flags for this particular preconditioner.
+       */
+      AdditionalData additional_data;
+  };
+
+
+
+  /**
+   * A wrapper for ILUT(t,m) factorization based on threshold (t) and maximum
+   * number of elements per row (m) for Paralution matrices. The preconditioner
+   * can be initialized using only the threshild value or both the threshold
+   * value and the maximum number of elements per row.
+   *
+   * @ingroup ParalutionWrappers
+   * @ingroup Preconditioners
+   * @author Bruno Turcksin, 2014
+   */
+  template <typename Number>
+  class PreconditionILUT : public PreconditionBase<Number>
+  {
+    public :
+      /**
+       * Standardized data struct to pipe additional flags to the 
+       * preconditioner.
+       */
+      struct AdditionalData 
+      {
+        /**
+         * Constructor. By default, set the threshold to zero.
+         */
+        AdditionalData (const Number threshold = 0.);
+
+        /**
+         * Constructor.
+         */
+        AdditionalData (const Number threshold, const unsigned int max_row);
+
+        /**
+         * Threshold.
+         */
+        Number threshold;
+
+        /**
+         * Maximum number of elements per row.
+         */
+        unsigned int max_row;
+      };
+
+      /**
+       * Constructor. Take additional flags if there are any.
+       */
+      PreconditionILUT (const AdditionalData &additional_data = AdditionalData());
+
+      /**
+       * This function changes the value of the additional flags.
+       */
+      void initialize (const AdditionalData &additional_data = AdditionalData());
+
+    private :
+      /**
+       * Store a copy of the flags for this particular preconditioner.
+       */
+      AdditionalData additional_data;
+  };
+
+
+
+  /**
+   * A wrapper for ILU(p,q) for Paralution matrices. ILU(p,q) is based on ILU(p)
+   * with a power(q)-pattern method. Compared to the standard ILU(p), ILU(p,q)
+   * provides a higher degree of parallelism of forward and backward
+   * substitution.
+   *
+   * @ingroup ParalutionWrappers
+   * @ingroup Preconditioners
+   * @author Bruno Turcksin, 2014
+   */
+  template <typename Number>
+  class PreconditionMultiColoredILU : public PreconditionBase<Number>
+  {
+    public :
+      /**
+       * Standardized data struct to pipe additional flags to the
+       * preconditioner.
+       */
+      struct AdditionalData
+      {
+        /**
+         * Constructor. By default, set the fill-in parameter to zero and the
+         * power-pattern to one.
+         */
+        AdditionalData (const unsigned int levels = 0, const unsigned int power = 1);
+
+        /**
+         * Fill-in parameter.
+         */
+        unsigned int levels;
+
+        /**
+         * Power parameter.
+         */
+        unsigned int power;
+      };
+
+      /**
+       * Constructor. Take additional flags if there are any.
+       */
+      PreconditionMultiColoredILU (const AdditionalData &additional_data = AdditionalData());
+
+      /**
+       * This function changes the value of additional flags.
+       */
+      void initialize (const AdditionalData &additional_data = AdditionalData());
+
+      private :
+      /**
+       * Store a copy of the flags for this particular preconditioner.
+       */
+      AdditionalData additional_data;
+  };
+}
+
+
+DEAL_II_NAMESPACE_CLOSE
+
+#endif // DEAL_II_WITH_PARALUTION
+
+/*----------------------------   paralution_precondition.h     ---------------------------*/
+
+#endif
+/*----------------------------   paralution_precondition.h     ---------------------------*/
index 1e559b2b6b787363eb6458894769834e76a863ee..03ff4a06b2a5cb14818799292173fba6306f8509 100644 (file)
@@ -1,7 +1,7 @@
 // ---------------------------------------------------------------------
 // $Id: paralution_solver.h 30040 2013-07-18 17:06:48Z maier $
 //
-// Copyright (C) 2013 by the deal.II authors
+// Copyright (C) 2013, 2014 by the deal.II authors
 //
 // This file is part of the deal.II library.
 //
 
 #ifdef DEAL_II_WITH_PARALUTION
 
+#include <deal.II/base/std_cxx1x/shared_ptr.h>
 #include <deal.II/lac/exceptions.h>
 #include <deal.II/lac/solver_control.h>
+#include <deal.II/lac/paralution_precondition.h>
 #include <deal.II/lac/paralution_vector.h>
 #include <deal.II/lac/paralution_sparse_matrix.h>
 
+#include <paralution.hpp>
 
 DEAL_II_NAMESPACE_OPEN
 
@@ -52,6 +55,18 @@ namespace ParalutionWrappers
     SolverControl &control() const;
 
   protected:
+    /**
+     * Initialize the solver and solve the system of equations.
+     */
+    template <typename Number>
+    void execute_solve(std_cxx1x::shared_ptr<paralution::IterativeLinearSolver<paralution::
+                       LocalMatrix<Number>,paralution::LocalVector<Number>,Number> > solver,
+                       const SparseMatrix<Number>     &A,
+                       Vector<Number>                 &x,
+                       const Vector<Number>           &b,
+                       const PreconditionBase<Number> &preconditioner,
+                       bool                            move_to_accelerator);
+
     /**
      * Reference to the object that controls convergence of the iteratove
      * solver. In fact, for these Paralution wrappers, Paralution does so
@@ -83,10 +98,11 @@ namespace ParalutionWrappers
      * solver is built on the accelerator.
      */
     template <typename Number>
-    void solve (const SparseMatrix<Number> &A,
-                Vector<Number>             &x,
-                const Vector<Number>       &b,
-                bool                        move_to_accelerator=false);
+    void solve (const SparseMatrix<Number>     &A,
+                Vector<Number>                 &x,
+                const Vector<Number>           &b,
+                const PreconditionBase<Number> &preconditioner,
+                bool                            move_to_accelerator=false);
   };
 
 
@@ -109,10 +125,11 @@ namespace ParalutionWrappers
      * solver is built on the accelerator.
      */
     template <typename Number>
-    void solve (const SparseMatrix<Number> &A,
-                Vector<Number>             &x,
-                const Vector<Number>       &b,
-                bool                        move_to_accelerator=false);
+    void solve (const SparseMatrix<Number>     &A,
+                Vector<Number>                 &x,
+                const Vector<Number>           &b,
+                const PreconditionBase<Number> &preconditioner,
+                bool                            move_to_accelerator=false);
   };
 
 
@@ -154,10 +171,11 @@ namespace ParalutionWrappers
      * solver is built on the accelerator.
      */
     template <typename Number>
-    void solve (const SparseMatrix<Number> &A,
-                Vector<Number>             &x,
-                const Vector<Number>       &b,
-                bool                        move_to_accelerator=false);
+    void solve (const SparseMatrix<Number>     &A,
+                Vector<Number>                 &x,
+                const Vector<Number>           &b,
+                const PreconditionBase<Number> &preconditioner,
+                bool                            move_to_accelerator=false);
 
   private:
     /**
@@ -171,7 +189,7 @@ DEAL_II_NAMESPACE_CLOSE
 
 #endif // DEAL_II_WITH_PARALUTION
 
-/*----------------------------   trilinos_solver.h     ---------------------------*/
+/*----------------------------   paralution_solver.h     ---------------------------*/
 
 #endif
-/*----------------------------   trilinos_solver.h     ---------------------------*/
+/*----------------------------   paralution_solver.h     ---------------------------*/
index 6eca8f0ae2d76db045da3e2cd1a449603ec0a226..20861a30286d6cdae91f309cc50a5754dc60d4c7 100644 (file)
@@ -26,7 +26,7 @@
 #include <deal.II/lac/sparse_matrix.h>
 #include <algorithm>
 
-#include "paralution.hpp"
+#include <paralution.hpp>
 
 DEAL_II_NAMESPACE_OPEN
 
@@ -46,7 +46,7 @@ namespace ParalutionWrappers
    * exchangeable. However, Paralution LocalMatix only supports float and double.
    *
    * @ingroup ParalutionWrappers
-   * @ingroup Matrix1
+   * @ingroup Matrix
    * @author Bruno Turcksin, 2013
    */
   template <typename Number>
@@ -135,14 +135,12 @@ namespace ParalutionWrappers
      * of dimension $m \times n$. This function works only after
      * convert_to_paralution_csr has been called.
      */
-    //TODO make the function work all the time
     size_type m() const;
 
     /**
      * Return the dimension of the range space. To remember: the matrix is
      * of dimension $m \times n$.
      */
-    //TODO make the function work all the time
     size_type n() const;
     //@}
     /**
index 366c1ee724f9020100103ce5c56f7f2e10f0dbc7..c8136a3866b1aa6953105f618b2de8029d01a139 100644 (file)
@@ -27,7 +27,7 @@
 #include <deal.II/lac/vector.h>
 #include <deal.II/base/memory_consumption.h>
 
-#include "paralution.hpp"
+#include <paralution.hpp>
 
 DEAL_II_NAMESPACE_OPEN
 
index ddb98aa206aa1f4d3e1e7645452bc570f170cc5a..259004d6c2c8d6caaaf10adf8183c5ff8239fbaa 100644 (file)
@@ -33,6 +33,7 @@ SET(_src
   matrix_lib.cc
   matrix_out.cc
   parallel_vector.cc
+  paralution_precondition.cc
   paralution_sparse_matrix.cc
   paralution_solver.cc
   petsc_block_sparse_matrix.cc
diff --git a/deal.II/source/lac/paralution_precondition.cc b/deal.II/source/lac/paralution_precondition.cc
new file mode 100644 (file)
index 0000000..9502c32
--- /dev/null
@@ -0,0 +1,233 @@
+// ---------------------------------------------------------------------
+// $Id: paralution_precondition.cc 31349 2013-10-20 19:07:06Z maier $
+//
+// Copyright (C) 2014 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.
+//
+// ---------------------------------------------------------------------
+
+#include <deal.II/lac/paralution_precondition.h>
+
+#ifdef DEAL_II_WITH_PARALUTION
+
+DEAL_II_NAMESPACE_OPEN
+
+namespace ParalutionWrappers
+{
+  template <typename Number>
+  PreconditionBase<Number>::PreconditionBase()
+  {}
+
+
+
+  /* -------------------------- PreconditionJacobi -------------------------- */
+
+  template <typename Number>
+  PreconditionJacobi<Number>::PreconditionJacobi()
+  {
+    this->preconditioner.reset(new paralution::Jacobi<paralution::LocalMatrix<Number>,
+                   paralution::LocalVector<Number>,Number>);
+  }
+
+
+
+  /* -------------------------- PreconditionSGS ----------------------------- */
+
+  template <typename Number>
+  PreconditionSGS<Number>::PreconditionSGS()
+  {
+    this->preconditioner.reset(new paralution::SGS<paralution::LocalMatrix<Number>,
+                   paralution::LocalVector<Number>,Number>);
+  }
+
+
+
+  /* -------------------------- PreconditionMultiColoredSGS ----------------- */
+
+  template <typename Number>
+  PreconditionMultiColoredSGS<Number>::PreconditionMultiColoredSGS()
+  {
+    this->preconditioner.reset(new paralution::MultiColoredSGS<paralution::LocalMatrix<Number>,
+                   paralution::LocalVector<Number>,Number>);
+  }
+
+
+
+  /* -------------------------- PreconditionMulticoloredSOR ----------------- */
+
+  template <typename Number>
+  PreconditionMultiColoredSOR<Number>::AdditionalData::
+  AdditionalData(const double omega) 
+  :
+    omega(omega)
+  {}
+
+
+  template <typename Number>
+  PreconditionMultiColoredSOR<Number>::PreconditionMultiColoredSOR(
+      const AdditionalData &additional_data)
+  :
+    additional_data(additional_data)
+  {
+    this->preconditioner.reset(new paralution::MultiColoredGS<paralution::LocalMatrix<Number>,
+                   paralution::LocalVector<Number>,Number>);
+
+    initialize(additional_data);
+  }
+
+  template <typename Number>
+  void PreconditionMultiColoredSOR<Number>::initialize(const AdditionalData &additional_data)
+  {
+    // Downcast the preconditioner pointer to use SetRelaxation
+    paralution::MultiColoredGS<paralution::LocalMatrix<Number>,paralution::
+      LocalVector<Number>,Number>* downcasted_ptr = static_cast<paralution::
+      MultiColoredGS<paralution::LocalMatrix<Number>,paralution::LocalVector<Number>,
+      Number>* >(this->preconditioner.get());
+
+    downcasted_ptr->SetRelaxation(additional_data.omega);
+  } 
+
+
+
+  /* -------------------------- PreconditionILU ----------------------------- */
+
+  template <typename Number>
+  PreconditionILU<Number>::AdditionalData::AdditionalData(const unsigned int levels)
+  :
+    levels(levels)
+  {}
+
+  template <typename Number>
+  PreconditionILU<Number>::PreconditionILU(const AdditionalData &additional_data)
+  :
+    additional_data(additional_data)
+  {
+    this->preconditioner.reset(new paralution::ILU<paralution::LocalMatrix<Number>,
+                   paralution::LocalVector<Number>,Number>);
+  
+    initialize(additional_data);
+  }
+
+  template <typename Number>
+  void PreconditionILU<Number>::initialize(const AdditionalData &additional_data)
+  {
+    // Downcast the preconditioner pointer to use Set
+    paralution::ILU<paralution::LocalMatrix<Number>,paralution::LocalVector<Number>,
+      Number>* downcasted_ptr = static_cast<paralution::ILU<paralution::
+        LocalMatrix<Number>,paralution::LocalVector<Number>,Number>* >(this->preconditioner.get());
+
+    downcasted_ptr->Set(additional_data.levels);
+  }
+
+
+
+  /* -------------------------- PreconditionILUT ---------------------------- */
+
+  template <typename Number>
+  PreconditionILUT<Number>::AdditionalData::AdditionalData(const Number threshold)
+  :
+    threshold(threshold),
+    max_row(0)
+  {}
+
+  template <typename Number>
+  PreconditionILUT<Number>::AdditionalData::AdditionalData(const Number threshold,
+      const unsigned int max_row)
+  :
+    threshold(threshold),
+    max_row(max_row)
+  {}
+
+  template <typename Number>
+  PreconditionILUT<Number>::PreconditionILUT(const AdditionalData &additional_data)
+  :
+    additional_data(additional_data)
+  {
+    this->preconditioner.reset(new paralution::ILUT<paralution::LocalMatrix<Number>,
+                   paralution::LocalVector<Number>,Number>);
+
+    initialize(additional_data);
+  }  
+  
+  template <typename Number>
+  void PreconditionILUT<Number>::initialize(const AdditionalData &additional_data)
+  {
+    // Downcast the preconditioner pointer to use Set
+    paralution::ILUT<paralution::LocalMatrix<Number>,paralution::LocalVector<Number>,
+      Number>* downcasted_ptr = static_cast<paralution::ILUT<paralution::
+        LocalMatrix<Number>,paralution::LocalVector<Number>,Number>* >(this->preconditioner.get());
+
+   if (additional_data.max_row==0)
+     downcasted_ptr->Set(additional_data.threshold);
+   else
+     downcasted_ptr->Set(additional_data.threshold,additional_data.max_row);
+  }
+
+
+
+  /* -------------------------- PreconditionMulticoloredILU --------------- */
+
+  template <typename Number>
+  PreconditionMultiColoredILU<Number>::AdditionalData::
+  AdditionalData(const unsigned int levels, const unsigned int power)
+  :
+    levels(levels),
+    power(power)
+  {}
+
+  template <typename Number>
+  PreconditionMultiColoredILU<Number>::
+  PreconditionMultiColoredILU(const AdditionalData &additional_data)
+  :
+    additional_data(additional_data)
+  {
+    this->preconditioner.reset(new paralution::MultiColoredILU<paralution::LocalMatrix<Number>,
+                   paralution::LocalVector<Number>,Number>);
+
+    initialize(additional_data);
+  }
+
+  template <typename Number>
+  void PreconditionMultiColoredILU<Number>::initialize(const AdditionalData &additional_data)
+  {
+    // Downcast the preconditioner pointer to use Set
+    paralution::MultiColoredILU<paralution::LocalMatrix<Number>,paralution::LocalVector<Number>,
+      Number>* downcasted_ptr = static_cast<paralution::MultiColoredILU<paralution::
+        LocalMatrix<Number>,paralution::LocalVector<Number>,Number>* >(this->preconditioner.get());
+
+    downcasted_ptr->Set(additional_data.levels,additional_data.power);
+  }
+}
+
+// Explicit instantiations
+namespace ParalutionWrappers
+{
+  template class PreconditionBase<float>;
+  template class PreconditionBase<double>;
+  template class PreconditionJacobi<float>;
+  template class PreconditionJacobi<double>;
+  template class PreconditionSGS<float>;
+  template class PreconditionSGS<double>;
+  template class PreconditionMultiColoredSGS<float>;
+  template class PreconditionMultiColoredSGS<double>;
+  template class PreconditionMultiColoredSOR<float>;
+  template class PreconditionMultiColoredSOR<double>;
+  template class PreconditionILU<float>;
+  template class PreconditionILU<double>;
+  template class PreconditionILUT<float>;
+  template class PreconditionILUT<double>;
+  template class PreconditionMultiColoredILU<float>;
+  template class PreconditionMultiColoredILU<double>;
+}
+
+DEAL_II_NAMESPACE_CLOSE
+
+#endif // DEAL_II_WITH_PARALUTION
index 3bf9e3668bdd679ee4aafdfc58494e8ee9c527cb..59c999830b271504ac70a90ab21532eec495f5cf 100644 (file)
@@ -1,7 +1,7 @@
 // ---------------------------------------------------------------------
 // $Id: paralution_solver.cc 31349 2013-10-20 19:07:06Z maier $
 //
-// Copyright (C) 2013 by the deal.II authors
+// Copyright (C) 2013, 2014 by the deal.II authors
 //
 // This file is part of the deal.II library.
 //
@@ -18,8 +18,6 @@
 
 #ifdef DEAL_II_WITH_PARALUTION
 
-#include "paralution.hpp"
-
 DEAL_II_NAMESPACE_OPEN
 
 namespace ParalutionWrappers
@@ -36,6 +34,34 @@ namespace ParalutionWrappers
     return solver_control;
   }
 
+  template <typename Number>
+  void SolverBase::execute_solve(std_cxx1x::shared_ptr<paralution::IterativeLinearSolver<paralution::
+                                 LocalMatrix<Number>,paralution::LocalVector<Number>,Number> > solver,
+                                 const SparseMatrix<Number>     &A,
+                                 Vector<Number>                 &x,
+                                 const Vector<Number>           &b,
+                                 const PreconditionBase<Number> &preconditioner,
+                                 bool                            move_to_accelerator)
+  {
+    // Set the preconditioner.
+    solver->SetPreconditioner(*(preconditioner.preconditioner));
+
+    // Set the system to solve
+    solver->SetOperator(A.paralution_matrix());
+
+    // Set absolute tolerance, relative tolerance, divergence tolerance,
+    // maximum number of iterations.
+    solver->Init(solver_control.tolerance(),0.,1.e100,
+                solver_control.max_steps());
+
+    // Move the solver to the accelerator if necessary.
+    if (move_to_accelerator==true)
+      solver->MoveToAccelerator();
+
+    solver->Build();
+    solver->Solve(b.paralution_vector(),&(x.paralution_vector()));
+  }
+
 
 
   /* ---------------------- SolverCG ------------------------ */
@@ -48,22 +74,17 @@ namespace ParalutionWrappers
 
 
   template <typename Number>
-  void SolverCG::solve(const SparseMatrix<Number> &A,
-                       Vector<Number>             &x,
-                       const Vector<Number>       &b,
-                       bool                        move_to_accelerator)
+  void SolverCG::solve(const SparseMatrix<Number>     &A,
+                       Vector<Number>                 &x,
+                       const Vector<Number>           &b,
+                       const PreconditionBase<Number> &preconditioner,
+                       bool                            move_to_accelerator)
   {
-    paralution::CG<paralution::LocalMatrix<Number>,
-               paralution::LocalVector<Number>,Number> solver;
-    solver.SetOperator(A.paralution_matrix());
-    // Set absolute tolerance, relative tolerance, divergence tolerance,
-    // maximum number of iterations.
-    solver.Init(solver_control.tolerance(),0.,1.e100,
-                solver_control.max_steps());
-    if (move_to_accelerator==true)
-      solver.MoveToAccelerator();
-    solver.Build();
-    solver.Solve(b.paralution_vector(),&(x.paralution_vector()));
+    std_cxx1x::shared_ptr<paralution::CG<paralution::LocalMatrix<Number>,
+      paralution::LocalVector<Number>,Number> > solver(new  paralution::
+        CG<paralution::LocalMatrix<Number>,paralution::LocalVector<Number>,Number>);
+
+    this->execute_solve<Number>(solver,A,x,b,preconditioner,move_to_accelerator);
   }
 
 
@@ -78,21 +99,17 @@ namespace ParalutionWrappers
 
 
   template <typename Number>
-  void SolverBicgstab::solve(const SparseMatrix<Number> &A,
-                             Vector<Number>             &x,
-                             const Vector<Number>       &b,
-                             bool                        move_to_accelerator)
+  void SolverBicgstab::solve(const SparseMatrix<Number>     &A,
+                             Vector<Number>                 &x,
+                             const Vector<Number>           &b,
+                             const PreconditionBase<Number> &preconditioner,
+                             bool                            move_to_accelerator)
   {
-    paralution::BiCGStab<paralution::LocalMatrix<Number>,
-               paralution::LocalVector<Number>,Number> solver;
-    // Set absolute tolerance, relative tolerance, divergence tolerance,
-    // maximum number of iterations.
-    solver.Init(solver_control.tolerance(),0.,1.e100,
-                solver_control.max_steps());
-    if (move_to_accelerator==true)
-      solver.MoveToAccelerator();
-    solver.Build();
-    solver.Solve(b.paralution_vector(),&(x.paralution_vector()));
+    std_cxx1x::shared_ptr<paralution::BiCGStab<paralution::LocalMatrix<Number>,
+      paralution::LocalVector<Number>,Number> > solver(new  paralution::
+        BiCGStab<paralution::LocalMatrix<Number>,paralution::LocalVector<Number>,Number>);
+
+    this->execute_solve<Number>(solver,A,x,b,preconditioner,move_to_accelerator);
   }
 
 
@@ -109,25 +126,21 @@ namespace ParalutionWrappers
 
 
   template <typename Number>
-  void SolverGMRES::solve(const SparseMatrix<Number> &A,
-                          Vector<Number>             &x,
-                          const Vector<Number>       &b,
-                          bool                        move_to_accelerator)
+  void SolverGMRES::solve(const SparseMatrix<Number>     &A,
+                          Vector<Number>                 &x,
+                          const Vector<Number>           &b,
+                          const PreconditionBase<Number> &preconditioner,
+                          bool                            move_to_accelerator)
   {
-    paralution::GMRES<paralution::LocalMatrix<Number>,
-               paralution::LocalVector<Number>,Number> solver;
-    // Set absolute tolerance, relative tolerance, divergence tolerance,
-    // maximum number of iterations.
-    solver.Init(solver_control.tolerance(),0.,1.e100,
-                solver_control.max_steps());
-    solver.SetBasisSize(additional_data.restart_parameter);
-    if (move_to_accelerator==true)
-      solver.MoveToAccelerator();
-    solver.Build();
-    solver.Solve(b.paralution_vector(),&(x.paralution_vector()));
-  }
+    std_cxx1x::shared_ptr<paralution::GMRES<paralution::LocalMatrix<Number>,
+      paralution::LocalVector<Number>,Number> > solver(new  paralution::
+        GMRES<paralution::LocalMatrix<Number>, paralution::LocalVector<Number>,Number>);
 
+    // Set the restart parameter.
+    solver->SetBasisSize(additional_data.restart_parameter);
 
+    this->execute_solve<Number>(solver,A,x,b,preconditioner,move_to_accelerator);
+  }
 }
 
 
@@ -135,35 +148,41 @@ namespace ParalutionWrappers
 // Explicit instantiations
 namespace ParalutionWrappers
 {
-  template void SolverCG::solve<float>(const SparseMatrix<float> &A,
-                                       Vector<float>             &x,
-                                       const Vector<float>       &b,
-                                       bool                       move_to_accelerator);
-
-  template void SolverCG::solve<double>(const SparseMatrix<double> &A,
-                                        Vector<double>             &x,
-                                        const Vector<double>       &b,
-                                        bool                       move_to_accelerator);
-
-  template void SolverBicgstab::solve<float>(const SparseMatrix<float> &A,
-                                             Vector<float>             &x,
-                                             const Vector<float>       &b,
-                                             bool                       move_to_accelerator);
-
-  template void SolverBicgstab::solve<double>(const SparseMatrix<double> &A,
-                                              Vector<double>             &x,
-                                              const Vector<double>       &b,
-                                              bool                       move_to_accelerator);
-
-  template void SolverGMRES::solve<float>(const SparseMatrix<float> &A,
-                                          Vector<float>             &x,
-                                          const Vector<float>       &b,
-                                          bool                       move_to_accelerator);
-
-  template void SolverGMRES::solve<double>(const SparseMatrix<double> &A,
-                                           Vector<double>             &x,
-                                           const Vector<double>       &b,
-                                           bool                       move_to_accelerator);
+  template void SolverCG::solve<float>(const SparseMatrix<float>     &A,
+                                       Vector<float>                 &x,
+                                       const Vector<float>           &b,
+                                       const PreconditionBase<float> &preconditioner,
+                                       bool                           move_to_accelerator);
+
+  template void SolverCG::solve<double>(const SparseMatrix<double>     &A,
+                                        Vector<double>                 &x,
+                                        const Vector<double>           &b,
+                                        const PreconditionBase<double> &preconditioner,
+                                        bool                            move_to_accelerator);
+
+  template void SolverBicgstab::solve<float>(const SparseMatrix<float>     &A,
+                                             Vector<float>                 &x,
+                                             const Vector<float>           &b,
+                                             const PreconditionBase<float> &preconditioner,
+                                             bool                           move_to_accelerator);
+
+  template void SolverBicgstab::solve<double>(const SparseMatrix<double>     &A,
+                                              Vector<double>                 &x,
+                                              const Vector<double>           &b,
+                                              const PreconditionBase<double> &preconditioner,
+                                              bool                            move_to_accelerator);
+
+  template void SolverGMRES::solve<float>(const SparseMatrix<float>     &A,
+                                          Vector<float>                 &x,
+                                          const Vector<float>           &b,
+                                          const PreconditionBase<float> &preconditioner,
+                                          bool                           move_to_accelerator);
+
+  template void SolverGMRES::solve<double>(const SparseMatrix<double>     &A,
+                                           Vector<double>                 &x,
+                                           const Vector<double>           &b,
+                                           const PreconditionBase<double> &preconditioner,
+                                           bool                            move_to_accelerator);
 }
 
 DEAL_II_NAMESPACE_CLOSE
index 46cadb95d234fcb2e3ea64fc2c46f2486b83e0a0..38d924f3d262d9c9366f1399ed16f411d0cd4a25 100644 (file)
@@ -76,6 +76,7 @@ namespace ParalutionWrappers
 
     // Free the memory used by sparse_matrix.
     sparse_matrix.clear();
+    is_local_matrix = true;
   }
 }
 
index fd730e1642731a9fa892fcd40e472af302cd0769..720f95e07416c5f004d6825af8b66fec038e0235 100644 (file)
@@ -26,6 +26,7 @@
 #include <deal.II/lac/paralution_sparse_matrix.h>
 #include <deal.II/lac/paralution_vector.h>
 #include <deal.II/lac/paralution_solver.h>
+#include <deal.II/lac/paralution_precondition.h>
 
 int main()
 {
@@ -56,6 +57,9 @@ int main()
     testproblem.five_point(A);
     A.convert_to_paralution_csr();
 
+    //Preconditioner
+    ParalutionWrappers::PreconditionJacobi<double> p;
+
     ParalutionWrappers::Vector<double> u(dim);
     ParalutionWrappers::Vector<double> f(dim);
     for (unsigned int i=0; i<dim; ++i)
@@ -63,7 +67,7 @@ int main()
       u[i] = 0.;
       f[i] = 1.;
     }
-    solver.solve(A,u,f);
+    solver.solve(A,u,f,p);
   }
 
   paralution::stop_paralution();
index f1b55bfd57c14029a722670d5f03cc8dfe9a73d3..44335a3de8c33def6b6fba2133ea4f96a779b94f 100644 (file)
 template <typename Number>
 void check()
 {
-  ParalutionWrappers::SparseMatrix<Number> matrix;
-  SparsityPattern pattern(4,5,2);
-  pattern.add(0,2);
-  pattern.add(0,0);
-  pattern.add(1,0);
-  pattern.add(1,3);
-  pattern.add(2,4);
-  pattern.add(2,2);
-  pattern.add(3,0);
-  pattern.add(3,4);
-  pattern.compress();
+  SparsityPattern sparsity_pattern(4,5,2);
+  sparsity_pattern.add(0,2);
+  sparsity_pattern.add(0,0);
+  sparsity_pattern.add(1,0);
+  sparsity_pattern.add(1,3);
+  sparsity_pattern.add(2,4);
+  sparsity_pattern.add(2,2);
+  sparsity_pattern.add(3,0);
+  sparsity_pattern.add(3,4);
+  sparsity_pattern.compress();
 
+  ParalutionWrappers::SparseMatrix<Number> matrix;
   matrix.reinit(sparsity_pattern);
   matrix.add(0,2,3.5);
   matrix.add(0,0,1.);

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.