--- /dev/null
+// ---------------------------------------------------------------------
+// $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 ---------------------------*/
// ---------------------------------------------------------------------
// $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
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
* 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);
};
* 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);
};
* 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:
/**
#endif // DEAL_II_WITH_PARALUTION
-/*---------------------------- trilinos_solver.h ---------------------------*/
+/*---------------------------- paralution_solver.h ---------------------------*/
#endif
-/*---------------------------- trilinos_solver.h ---------------------------*/
+/*---------------------------- paralution_solver.h ---------------------------*/
#include <deal.II/lac/sparse_matrix.h>
#include <algorithm>
-#include "paralution.hpp"
+#include <paralution.hpp>
DEAL_II_NAMESPACE_OPEN
* exchangeable. However, Paralution LocalMatix only supports float and double.
*
* @ingroup ParalutionWrappers
- * @ingroup Matrix1
+ * @ingroup Matrix
* @author Bruno Turcksin, 2013
*/
template <typename Number>
* 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;
//@}
/**
#include <deal.II/lac/vector.h>
#include <deal.II/base/memory_consumption.h>
-#include "paralution.hpp"
+#include <paralution.hpp>
DEAL_II_NAMESPACE_OPEN
matrix_lib.cc
matrix_out.cc
parallel_vector.cc
+ paralution_precondition.cc
paralution_sparse_matrix.cc
paralution_solver.cc
petsc_block_sparse_matrix.cc
--- /dev/null
+// ---------------------------------------------------------------------
+// $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
// ---------------------------------------------------------------------
// $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.
//
#ifdef DEAL_II_WITH_PARALUTION
-#include "paralution.hpp"
-
DEAL_II_NAMESPACE_OPEN
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 ------------------------ */
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);
}
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);
}
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);
+ }
}
// 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
// Free the memory used by sparse_matrix.
sparse_matrix.clear();
+ is_local_matrix = true;
}
}
#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()
{
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)
u[i] = 0.;
f[i] = 1.;
}
- solver.solve(A,u,f);
+ solver.solve(A,u,f,p);
}
paralution::stop_paralution();
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.);