From: turcksin Date: Mon, 23 Jun 2014 15:00:32 +0000 (+0000) Subject: Merge from trunk. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=100deed0da375cbd2345bfd7646825e66f54f7f1;p=dealii-svn.git Merge from trunk. git-svn-id: https://svn.dealii.org/branches/branch_paralution@33080 0785d39b-7218-0410-832d-ea1e28bc413d --- 100deed0da375cbd2345bfd7646825e66f54f7f1 diff --cc deal.II/include/deal.II/lac/block_vector_base.h index a924af5d66,a924af5d66..65d369d8cc --- a/deal.II/include/deal.II/lac/block_vector_base.h +++ b/deal.II/include/deal.II/lac/block_vector_base.h @@@ -682,8 -682,8 +682,9 @@@ namespace interna * its own. * * The BlockVector is a collection of Vectors (e.g. of either deal.II Vector -- * objects or PETScWrappers::Vector object). Each of the vectors inside can -- * have a different size. ++ * objects, PETScWrappers::Vector object, TrilinosWrappers::Vector, or ++ * ParalutionWrappers::Vector). Each of the vectors inside can have a different ++ * size. * * The functionality of BlockVector includes everything a Vector can do, plus * the access to a single Vector inside the BlockVector by diff --cc deal.II/include/deal.II/lac/paralution_precondition.h index 4523c21b0d,0000000000..f6ffe9e21c mode 100644,000000..100644 --- a/deal.II/include/deal.II/lac/paralution_precondition.h +++ b/deal.II/include/deal.II/lac/paralution_precondition.h @@@ -1,392 -1,0 +1,505 @@@ +// --------------------------------------------------------------------- +// $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 + +#ifdef DEAL_II_WITH_PARALUTION + ++#include +#include + ++#include ++ +#include + +DEAL_II_NAMESPACE_OPEN + + +namespace ParalutionWrappers +{ ++ /** ++ * Cycle for multigrid preconditioner. ++ */ ++ enum mg_cycle {V_cycle, W_cycle, K_cycle, F_cycle}; ++ ++ /** ++ * Interpolation for grid transfer operator. ++ */ ++ enum mg_interpolation {aggregation, smoothed_aggregation}; ++ ++ /** ++ * Precondition for the smoother. ++ */ ++ enum mg_preconditioner {jacobi, sgs, multicolored_sgs, multicolored_sor, ilu, ++ ilut, multicolored_ilu ++ }; ++ ++ /** ++ * Solver used as smoother and to solve the coarse system. ++ */ ++ enum mg_solver {richardson, cg, cr, bicgstab, gmres, fgmres}; ++ + /** + * 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 + 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, ++ std_cxx1x::shared_ptr, + paralution::LocalVector,Number> > preconditioner; + }; + + + + /** + * A wrapper for Jacobi preconditioner for Paralution matrices. + * + * @ingroup ParalutionWrappers + * @ingroup Preconditioners + * @author Bruno Turcksin, 2014 + */ + template + class PreconditionJacobi : public PreconditionBase + { + 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 + class PreconditionSGS : public PreconditionBase + { + 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 + class PreconditionMultiColoredSGS : public PreconditionBase + { + 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 + class PreconditionMultiColoredSOR : public PreconditionBase + { + 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 + class PreconditionILU : public PreconditionBase + { + 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 + class PreconditionILUT : public PreconditionBase + { + 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 + class PreconditionMultiColoredILU : public PreconditionBase + { + 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()); ++ }; ++ ++ /** ++ * A simplified wrapper for AMG for Paralution matrices. To use other parameter ++ * combinations use the Paralution directly. AMG can only be built on the host. ++ * ++ * @ingroup ParalutionWrappers ++ * @ingroup Preconditioners ++ * @author Bruno Turcksin, 2014 ++ */ ++ template ++ class PreconditionAMG : public PreconditionBase ++ { ++ public : ++ /** ++ * Standardized data struct to pipe additional flags to the ++ * preconditioner. ++ */ ++ struct AdditionalData ++ { ++ /** ++ * Constructor. This constructor lets Paralution choose the parameters ++ * of the algebraic multigrid. ++ */ ++ AdditionalData (const unsigned int verbose = 0, const unsigned int max_iter = 2); ++ ++ /** ++ * Constructor. The relaxation parameter is used only when smoothed ++ * aggregation is selected. Otherwise, this parameter is disregarded. ++ */ ++ AdditionalData (const unsigned int verbose, ++ const unsigned int max_iter, ++ const mg_cycle cycle, ++ const mg_interpolation interpolation, ++ const mg_preconditioner preconditioner, ++ const mg_solver smoother, ++ const mg_solver coarse_solver, ++ const unsigned int n_unknowns_coarse_level, ++ const double relaxation_parameter = 1.2); ++ ++ /** ++ * The flag is true if the default parameters of Paralution should be ++ * used. ++ */ ++ bool default_parameters; ++ ++ /** ++ * Cycle used by the multigrid preconditioner: V cycle, W cycle, K ++ * cycle, or F cycle. ++ */ ++ mg_cycle cycle; ++ ++ /** ++ * Interpolation used by the multigrid preconditioner: smoothed ++ * aggregation or aggregation. ++ */ ++ mg_interpolation interpolation; ++ ++ /** ++ * Preconditioner for the smoother. ++ */ ++ mg_preconditioner preconditioner; ++ ++ /** ++ * Smoother. ++ */ ++ mg_solver smoother; ++ ++ /** ++ * Solver of the coarse system. ++ */ ++ mg_solver coarse_solver; ++ ++ /** ++ * Verbosity: 0 = no output, 1 = print information at the ++ * start and at the end, 3 = print residual at each iteration. ++ */ ++ unsigned int verbose; ++ ++ /** ++ * Number of unknowns on the coarsest level. ++ */ ++ unsigned int n_unknowns_coarse_level; ++ ++ /** ++ * Maximum number of iterations. ++ */ ++ unsigned int max_iter; ++ ++ /** ++ * Relaxation parameter for smoothed interpolation aggregation. ++ */ ++ double relaxation_parameter; ++ }; ++ ++ /** ++ * Constructor. Take additional flags if there are any. ++ */ ++ PreconditionAMG (const AdditionalData &additional_data = AdditionalData()); ++ ++ /** ++ * Destructor. ++ */ ++ ~PreconditionAMG(); ++ ++ /** ++ * 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. ++ * Free the smoothers, the preconditioners, and the coarse level solver. ++ */ ++ void clear(); ++ ++ /** ++ * Number of levels of the multigrid. ++ */ ++ unsigned int n_levels; ++ ++ /** ++ * Smoothers for each level. ++ */ ++ paralution::IterativeLinearSolver, paralution:: ++ LocalVector,Number> * *smoothers; ++ /** ++ * Preconditioners of the smoothers for each level. ++ */ ++ paralution::Preconditioner, paralution:: ++ LocalVector,Number> * *preconditioners; ++ /** ++ * Coarse grid solver. + */ - AdditionalData additional_data; ++ paralution::IterativeLinearSolver, paralution:: ++ LocalVector,Number> *coarse_solver; + }; +} + + +DEAL_II_NAMESPACE_CLOSE + +#endif // DEAL_II_WITH_PARALUTION + +/*---------------------------- paralution_precondition.h ---------------------------*/ + +#endif +/*---------------------------- paralution_precondition.h ---------------------------*/ diff --cc deal.II/include/deal.II/lac/paralution_solver.h index ca3ba6df2a,0000000000..555d0481c0 mode 100644,000000..100644 --- a/deal.II/include/deal.II/lac/paralution_solver.h +++ b/deal.II/include/deal.II/lac/paralution_solver.h @@@ -1,508 -1,0 +1,515 @@@ +// --------------------------------------------------------------------- +// $Id: paralution_solver.h 30040 2013-07-18 17:06:48Z maier $ +// +// Copyright (C) 2013, 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_solver_h +#define __deal2__paralution_solver_h + + +#include + +#ifdef DEAL_II_WITH_PARALUTION + +#include +#include +#include +#include +#include +#include + +#include + +DEAL_II_NAMESPACE_OPEN + +namespace ParalutionWrappers +{ + /** + * Base class for solver classes using the Paralution solvers. + * + * @ingroup ParalutionWrappers + * @author Bruno Turcksin 2013 + */ + class SolverBase + { + public: + /** + * Constructor. Takes the solver control object and creates the solver. + */ + SolverBase (SolverControl &cn); + + /** + * Access to object that controls convergence. + */ + SolverControl &control() const; + + protected: + /** + * Initialize the solver and solve the system of equations. + */ + template + void execute_solve(std_cxx1x::shared_ptr,paralution::LocalVector,Number> > solver, - const SparseMatrix &A, ++ SparseMatrix &A, + Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, ++ Vector &b, ++ PreconditionBase &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 + * itself, but we copy the data from this object solition process, and + * copy the data back into it afterwards. + */ + SolverControl &solver_control; + }; + + + + /** + * An implementation of the solver interface using the Paralution Richardson solver + * (paralution::fixed_point_iteration). + * + * @ingroup ParalutionWrappers + * @author Bruno Turcksin, 2014 + */ + class SolverRichardson : public SolverBase + { + public: + /** + * Standardized data struct to pipe additional data to the solver. + */ + struct AdditionalData + { + /** + * Constructor. By default, set the verbosity of the solver to zero and + * the relaxation parameter to one. + */ + AdditionalData (const unsigned int verbose = 0, + const double relaxation_parameter = 1.); + + /** + * Verbosity of the solver: 0 = no output, 1 = print information at the + * start and at the end, 3 = print residual at each iteration. + */ + unsigned int verbose; + + /** + * Relaxation parameter. + */ + double relaxation_parameter; + }; + + /** + * Constructor. AdditionalData is a structure that contains additional + * flags for tuning this particular solver. + */ + SolverRichardson (SolverControl &cn, + const AdditionalData &data = AdditionalData()); + + /** + * Solve the linear system Ax=b using the CG solver of + * Paralution. If the flag @p move_to_accelerator is set to true, the - * solver is built on the accelerator. ++ * solver, the right-hand side, the matrix, and the solution vector are ++ * moved on the accelerator once the solver is built. + */ + template - void solve (const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator=false); ++ void solve (SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator=false); + + private: + /** + * store a copy of the flags for this solver. + */ + const AdditionalData additional_data; + }; + + + + /** + * An implementation of the solver interface using the Paralution CG solver. + * + * @ingroup ParalutionWrappers + * @author Bruno Turcksin, 2013 + */ + class SolverCG : public SolverBase + { + public: + /** + * Standardized data struct to pipe additional data to the solver. + */ + struct AdditionalData + { + /** + * Constructor. By default, set the verbosity of the solver to zero. + */ + AdditionalData (const unsigned int verbose = 0); + + /** + * Verbosity of the solver: 0 = no output, 1 = print information at the + * start and at the end, 3 = print residual at each iteration. + */ + unsigned int verbose; + + /** + * Relaxation parameter. + */ + double relaxation_parameter; + }; + + /** + * Constructor. AdditionalData is a structure that contains additional + * flags for tuning this particular solver. + */ + SolverCG (SolverControl &cn, + const AdditionalData &data = AdditionalData()); + + /** + * Solve the linear system Ax=b using the CG solver of + * Paralution. If the flag @p move_to_accelerator is set to true, the - * solver is built on the accelerator. ++ * solver, the right-hand side, the matrix, and the solution vector are ++ * moved on the accelerator once the solver is built. + */ + template - void solve (const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator=false); ++ void solve (SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator=false); + + private: + /** + * store a copy of the flags for this solver. + */ + const AdditionalData additional_data; + }; + + + + /** + * An implementation of the solver interface using the Paralution CR solver. + * + * @ingroup ParalutionWrappers + * @author Bruno Turcksin, 2014 + */ + class SolverCR : public SolverBase + { + public: + /** + * Standardized data struct to pipe additional data to the solver. + */ + struct AdditionalData + { + /** + * Constructor. By default, set the verbosity of the solver to zero. + */ + AdditionalData (const unsigned int verbose = 0); + + /** + * Verbosity of the solver: 0 = no output, 1 = print information at the + * start and at the end, 3 = print residual at each iteration. + */ + unsigned int verbose; + }; + + /** + * Constructor. AdditionalData is a structure that contains additional + * flags for tuning this particular solver. + */ + SolverCR (SolverControl &cn, + const AdditionalData &data = AdditionalData()); + + /** + * Solve the linear system Ax=b using the CR solver of + * Paralution. If the flag @p move_to_accelerator is set to true, the - * solver is built on the accelerator. ++ * solver, the right-hand side, the matrix, and the solution vector are ++ * moved on the accelerator once the solver is built. + */ + template - void solve (const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator=false); ++ void solve (SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator=false); + + private: + /** + * store a copy of the flags for this solver. + */ + const AdditionalData additional_data; + }; + + + + /** + * An implementation of the solver interface using the Paralution DPCG solver. + * DPCG stands for Deflated Preconditioned Conjugate Gradient. It is a + * two-level preconditioned CG algorithm to iteratively solve and + * ill-conditioned linear system. Deflation tries to remove the bad + * eigenvalues from the spectrum of the preconditioned system. + * + * @ingroup ParalutionWrappers + * @author Bruno Turcksin, 2014 + */ + class SolverDPCG : public SolverBase + { + public: + /** + * Standardized data struct to pipe additional data to the solver. + */ + struct AdditionalData + { + /** + * Constructor. By default, set the verbosity of the solver to zero and + * set the number of deflated vectors to two. + */ + AdditionalData (const unsigned int verbose = 0, + const unsigned int n_deflated_vectors = 2); + + /** + * Verbosity of the solver: 0 = no output, 1 = print information at the + * start and at the end, 3 = print residual at each iteration. + */ + unsigned int verbose; + + /** + * Number of deflated vectors. + */ + unsigned int n_deflated_vectors; + }; + + /** + * Constructor. AdditionalData is a structure that contains additional + * flags for tuning this particular solver. + */ + SolverDPCG (SolverControl &cn, + const AdditionalData &data = AdditionalData()); + + /** + * Solve the linear system Ax=b using the DPCG solver of + * Paralution. If the flag @p move_to_accelerator is set to true, the - * solver is built on the accelerator. ++ * solver, the right-hand side, the matrix, and the solution vector are ++ * moved on the accelerator once the solver is built. + */ + template - void solve (const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator=false); ++ void solve (SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator=false); + + private: + /** + * store a copy of the flags for this solver. + */ + const AdditionalData additional_data; + }; + + + + /** + * An implementation of the solver interface using the Paralution BiCGStab + * solver. + * + * @ingroup ParalutionWrappers + * @author Bruno Turcksin, 2013 + */ + class SolverBicgstab : public SolverBase + { + public: + /** + * Standardized data struct to pipe additional data to the solver. + */ + struct AdditionalData + { + /** + * Constructor. By default, set the verbosity of the solver to zero. + */ + AdditionalData (const unsigned int verbose = 0); + + /** + * Verbosity of the solver: 0 = no output, 1 = print information at the + * start and at the end, 3 = print residual at each iteration. + */ + unsigned int verbose; + }; + + /** + * Constructor. AdditionalData is a structure that contains additional + * flags for tuning this particular solver. + */ + SolverBicgstab (SolverControl &cn, + const AdditionalData &data = AdditionalData()); + + /** + * Solve the linear system Ax=b using the BiCGStab solver of + * Paralution. If the flag @p move_to_accelerator is set to true, the - * solver is built on the accelerator. ++ * solver, the right-hand side, the matrix, and the solution vector are ++ * moved on the accelerator once the solver is built. + */ + template - void solve (const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator=false); ++ void solve (SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator=false); + + private: + /** + * store a copy of the flags for this solver. + */ + const AdditionalData additional_data; + }; + + + + /** + * An implementation of the solver interface using the Paralution GMRES + * solver. + * + * @ingroup ParalutionWrappers + * @author Bruno Turcksin, 2013 + */ + class SolverGMRES : public SolverBase + { + public: + /** + * Standardized data struct to pipe additional data to the solver. + */ + struct AdditionalData + { + /** + * Constructor. By default, set the verbosity of the solver to zero and + * set the size of the Krylov space to 30, i.e. do a restart every 30 + * iterations. + */ + AdditionalData (const unsigned int verbose = 0, + const unsigned int restart_parameter = 30); + + /** + * Verbosity of the solver: 0 = no output, 1 = print information at the + * start and at the end, 3 = print residual at each iteration. + */ + unsigned int verbose; + + /** + * Size of the Krylov space. + */ + unsigned int restart_parameter; + }; + + /** + * Constructor. AdditionalData is a structure that contains additional + * flags for tuning this particular solver. + */ + SolverGMRES (SolverControl &cn, + const AdditionalData &data = AdditionalData()); + + /** + * Solve the linear system Ax=b using the GMRES solver of + * Paralution. If the flag @p move_to_accelerator is set to true, the - * solver is built on the accelerator. ++ * solver, the right-hand side, the matrix, and the solution vector are ++ * moved on the accelerator once the solver is built. + */ + template - void solve (const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator=false); ++ void solve (SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator=false); + + private: + /** + * store a copy of the flags for this solver. + */ + const AdditionalData additional_data; + }; + + + + /** + * An implementation of the solver interface using the Paralution GMRES + * solver. + * + * @ingroup ParalutionWrappers + * @author Bruno Turcksin, 2014 + */ + class SolverFGMRES : public SolverBase + { + public: + /** + * Standardized data struct to pipe additional data to the solver. + */ + struct AdditionalData + { + /** + * Constructor. By default, set the verbosity of the solver to zero and + * set the size of the Krylov space to 30, i.e. do a restart every 30 + * iterations. + */ + AdditionalData (const unsigned int verbose = 0, + const unsigned int restart_parameter = 30); + + /** + * Verbosity of the solver: 0 = no output, 1 = print information at the + * start and at the end, 3 = print residual at each iteration. + */ + unsigned int verbose; + + /** + * Size of the Krylov space. + */ + unsigned int restart_parameter; + }; + + /** + * Constructor. AdditionalData is a structure that contains additional + * flags for tuning this particular solver. + */ + SolverFGMRES (SolverControl &cn, + const AdditionalData &data = AdditionalData()); + + /** + * Solve the linear system Ax=b using the GMRES solver of + * Paralution. If the flag @p move_to_accelerator is set to true, the - * solver is built on the accelerator. ++ * solver, the right-hand side, the matrix, and the solution vector are ++ * moved on the accelerator once the solver is built. + */ + template - void solve (const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator=false); ++ void solve (SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator=false); + + private: + /** + * store a copy of the flags for this solver. + */ + const AdditionalData additional_data; + }; +} + +DEAL_II_NAMESPACE_CLOSE + +#endif // DEAL_II_WITH_PARALUTION + +/*---------------------------- paralution_solver.h ---------------------------*/ + +#endif +/*---------------------------- paralution_solver.h ---------------------------*/ diff --cc deal.II/source/lac/paralution_precondition.cc index 3f77ec78cf,0000000000..3729452c03 mode 100644,000000..100644 --- a/deal.II/source/lac/paralution_precondition.cc +++ b/deal.II/source/lac/paralution_precondition.cc @@@ -1,250 -1,0 +1,670 @@@ +// --------------------------------------------------------------------- +// $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 + +#ifdef DEAL_II_WITH_PARALUTION + +DEAL_II_NAMESPACE_OPEN + +namespace ParalutionWrappers +{ + template + PreconditionBase::PreconditionBase() + {} + + + + /* -------------------------- PreconditionJacobi -------------------------- */ + + template + PreconditionJacobi::PreconditionJacobi() + { + this->preconditioner.reset(new paralution::Jacobi, + paralution::LocalVector,Number>); + } + + + + /* -------------------------- PreconditionSGS ----------------------------- */ + + template + PreconditionSGS::PreconditionSGS() + { + this->preconditioner.reset(new paralution::SGS, + paralution::LocalVector,Number>); + } + + + + /* -------------------------- PreconditionMultiColoredSGS ----------------- */ + + template + PreconditionMultiColoredSGS::PreconditionMultiColoredSGS() + { + this->preconditioner.reset(new paralution::MultiColoredSGS, + paralution::LocalVector,Number>); + } + + + + /* -------------------------- PreconditionMulticoloredSOR ----------------- */ + + template + PreconditionMultiColoredSOR::AdditionalData:: + AdditionalData(const double omega) + : + omega(omega) + {} + + + + template + PreconditionMultiColoredSOR::PreconditionMultiColoredSOR( + const AdditionalData &additional_data) - : - additional_data(additional_data) + { + this->preconditioner.reset(new paralution::MultiColoredGS, + paralution::LocalVector,Number>); + + initialize(additional_data); + } + + + + template + void PreconditionMultiColoredSOR::initialize(const AdditionalData &additional_data) + { + // Downcast the preconditioner pointer to use SetRelaxation + paralution::MultiColoredGS,paralution:: + LocalVector,Number>* downcasted_ptr = static_cast,paralution::LocalVector, + Number>* >(this->preconditioner.get()); + + downcasted_ptr->SetRelaxation(additional_data.omega); + } + + + + /* -------------------------- PreconditionILU ----------------------------- */ + + template + PreconditionILU::AdditionalData::AdditionalData(const unsigned int levels) + : + levels(levels) + {} + + + + template + PreconditionILU::PreconditionILU(const AdditionalData &additional_data) - : - additional_data(additional_data) + { + this->preconditioner.reset(new paralution::ILU, + paralution::LocalVector,Number>); + + initialize(additional_data); + } + + + + template + void PreconditionILU::initialize(const AdditionalData &additional_data) + { + // Downcast the preconditioner pointer to use Set + paralution::ILU,paralution::LocalVector, + Number>* downcasted_ptr = static_cast,paralution::LocalVector,Number>* >(this->preconditioner.get()); + + downcasted_ptr->Set(additional_data.levels); + } + + + + /* -------------------------- PreconditionILUT ---------------------------- */ + + template + PreconditionILUT::AdditionalData::AdditionalData(const Number threshold) + : + threshold(threshold), + max_row(0) + {} + + + + template + PreconditionILUT::AdditionalData::AdditionalData(const Number threshold, + const unsigned int max_row) + : + threshold(threshold), + max_row(max_row) + {} + + + + template + PreconditionILUT::PreconditionILUT(const AdditionalData &additional_data) - : - additional_data(additional_data) + { + this->preconditioner.reset(new paralution::ILUT, + paralution::LocalVector,Number>); + + initialize(additional_data); + } + + + + template + void PreconditionILUT::initialize(const AdditionalData &additional_data) + { + // Downcast the preconditioner pointer to use Set + paralution::ILUT,paralution::LocalVector, + Number>* downcasted_ptr = static_cast,paralution::LocalVector,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 + PreconditionMultiColoredILU::AdditionalData:: + AdditionalData(const unsigned int levels, const unsigned int power) + : + levels(levels), + power(power) + {} + + + + template + PreconditionMultiColoredILU:: + PreconditionMultiColoredILU(const AdditionalData &additional_data) - : - additional_data(additional_data) + { + this->preconditioner.reset(new paralution::MultiColoredILU, + paralution::LocalVector,Number>); + + initialize(additional_data); + } + + + + template + void PreconditionMultiColoredILU::initialize(const AdditionalData &additional_data) + { + // Downcast the preconditioner pointer to use Set + paralution::MultiColoredILU,paralution::LocalVector, + Number>* downcasted_ptr = static_cast,paralution::LocalVector,Number>* >(this->preconditioner.get()); + + downcasted_ptr->Set(additional_data.levels,additional_data.power); + } ++ ++ ++ ++ /* -------------------------- PreconditionAMG --------------------------- */ ++ ++ template ++ PreconditionAMG::AdditionalData::AdditionalData(const unsigned int verbose, ++ const unsigned int max_iter) ++ : ++ default_parameters(true), ++ verbose(verbose), ++ max_iter(max_iter) ++ {} ++ ++ ++ ++ template ++ PreconditionAMG::AdditionalData::AdditionalData(const unsigned int verbose, ++ const unsigned int max_iter, ++ const mg_cycle cycle, ++ const mg_interpolation interpolation, ++ const mg_preconditioner preconditioner, ++ const mg_solver smoother, ++ const mg_solver coarse_solver, ++ const unsigned int n_unknowns_coarse_level, ++ const double relaxation_parameter) ++ : ++ default_parameters(false), ++ cycle(cycle), ++ interpolation(interpolation), ++ preconditioner(preconditioner), ++ smoother(smoother), ++ coarse_solver(coarse_solver), ++ verbose(verbose), ++ n_unknowns_coarse_level(n_unknowns_coarse_level), ++ max_iter(max_iter), ++ relaxation_parameter(relaxation_parameter) ++ {} ++ ++ ++ ++ template ++ PreconditionAMG::PreconditionAMG(const AdditionalData &additional_data) ++ : ++ n_levels(1), ++ smoothers(NULL), ++ preconditioners(NULL), ++ coarse_solver(NULL) ++ { ++ this->preconditioner.reset(new paralution::AMG, ++ paralution::LocalVector,Number>); ++ ++ initialize(additional_data); ++ } ++ ++ ++ ++ template ++ PreconditionAMG::~PreconditionAMG() ++ { ++ clear(); ++ } ++ ++ ++ ++ template ++ void PreconditionAMG::initialize(const AdditionalData &additional_data) ++ { ++ // Downcast the preconditioner pointer ++ paralution::AMG,paralution::LocalVector, ++ Number>* downcasted_ptr = static_cast,paralution::LocalVector,Number>* >(this->preconditioner.get()); ++ ++ // Set the maximum number of iterations. ++ downcasted_ptr->InitMaxIter(additional_data.max_iter); ++ ++ // Set the verbosity ++ downcasted_ptr->Verbose(additional_data.verbose); ++ ++ if (additional_data.default_parameters==false) ++ { ++ // Free the smoothers, the preconditioners, and the coarse level solver, ++ // if necessary. ++ clear(); ++ ++ // Set the number of unknowns on the coarsest level. ++ downcasted_ptr->SetCoarsestLevel(additional_data.n_unknowns_coarse_level); ++ ++ // Set the interpolation type. ++ switch (additional_data.interpolation) ++ { ++ case aggregation : ++ { ++ downcasted_ptr->SetInterpolation(paralution::Aggregation); ++ break; ++ } ++ case smoothed_aggregation : ++ { ++ downcasted_ptr->SetInterpolation(paralution::SmoothedAggregation); ++ downcasted_ptr->SetInterpRelax(additional_data.relaxation_parameter); ++ break; ++ } ++ default : ++ { ++ AssertThrow(false,ExcMessage("Unknown interpolation type for PreconditionAMG.")); ++ } ++ } ++ ++ // Set the type of cycle ++ switch (additional_data.cycle) ++ { ++ case V_cycle : ++ { ++ downcasted_ptr->SetCycle(paralution::Vcycle); ++ break; ++ } ++ case W_cycle : ++ { ++ downcasted_ptr->SetCycle(paralution::Wcycle); ++ break; ++ } ++ case K_cycle : ++ { ++ downcasted_ptr->SetCycle(paralution::Kcycle); ++ break; ++ } ++ case F_cycle : ++ { ++ downcasted_ptr->SetCycle(paralution::Fcycle); ++ } ++ default : ++ { ++ AssertThrow(false,ExcMessage("Unknown cycle type for PreconditionAMG.")); ++ } ++ } ++ ++ // Use manual smoothers. ++ downcasted_ptr->SetManualSmoothers(true); ++ ++ // Use manual coarse grid solver. ++ downcasted_ptr->SetManualSolver(true); ++ ++ // Build the hierarchy of the grids. ++ downcasted_ptr->BuildHierarchy(); ++ ++ // Get the number of grids/levels. ++ n_levels = downcasted_ptr->GetNumLevels(); ++ ++ // Smoothers for each level. ++ smoothers = new paralution::IterativeLinearSolver, ++ paralution::LocalVector, Number>* [n_levels-1]; ++ switch (additional_data.smoother) ++ { ++ case richardson : ++ { ++ for (unsigned int i=0; i, paralution::LocalVector, ++ Number> *sm = new paralution::FixedPoint, ++ paralution::LocalVector, Number>; ++ smoothers[i] = sm; ++ } ++ break; ++ } ++ case cg : ++ { ++ for (unsigned int i=0; i, paralution::LocalVector, ++ Number> *sm = new paralution::CG, ++ paralution::LocalVector, Number>; ++ smoothers[i] = sm; ++ } ++ break; ++ } ++ case cr : ++ { ++ for (unsigned int i=0; i, paralution::LocalVector, ++ Number> *sm = new paralution::CR, ++ paralution::LocalVector, Number>; ++ smoothers[i] = sm; ++ } ++ break; ++ } ++ case bicgstab : ++ { ++ for (unsigned int i=0; i, paralution::LocalVector, ++ Number> *sm = new paralution::BiCGStab, ++ paralution::LocalVector, Number>; ++ smoothers[i] = sm; ++ } ++ break; ++ } ++ case gmres : ++ { ++ for (unsigned int i=0; i, paralution::LocalVector, ++ Number> *sm = new paralution::GMRES, ++ paralution::LocalVector, Number>; ++ smoothers[i] = sm; ++ } ++ break; ++ } ++ case fgmres : ++ { ++ for (unsigned int i=0; i, paralution::LocalVector, ++ Number> *sm = new paralution::FGMRES, ++ paralution::LocalVector, Number>; ++ smoothers[i] = sm; ++ } ++ break; ++ } ++ default : ++ { ++ AssertThrow(false,ExcMessage("Unknown smoother for PreconditionAMG.")); ++ } ++ } ++ ++ // Preconditioners for each level. ++ preconditioners = new paralution::Preconditioner, ++ paralution::LocalVector, Number>*[n_levels-1]; ++ switch (additional_data.preconditioner) ++ { ++ case jacobi : ++ { ++ for (unsigned int i=0; i, paralution::LocalVector, ++ Number> *precond = new paralution::Jacobi, ++ paralution::LocalVector, Number>; ++ preconditioners[i] = precond; ++ } ++ break; ++ } ++ case sgs : ++ { ++ for (unsigned int i=0; i, paralution::LocalVector, ++ Number> *precond = new paralution::SGS, ++ paralution::LocalVector, Number>; ++ preconditioners[i] = precond; ++ } ++ break; ++ } ++ case multicolored_sgs : ++ { ++ for (unsigned int i=0; i, ++ paralution::LocalVector, Number> *precond = ++ new paralution::MultiColoredSGS, ++ paralution::LocalVector, Number>; ++ preconditioners[i] = precond; ++ } ++ break; ++ } ++ case multicolored_sor : ++ { ++ for (unsigned int i=0; i, ++ paralution::LocalVector, Number> *precond = ++ new paralution::MultiColoredGS, ++ paralution::LocalVector, Number>; ++ preconditioners[i] = precond; ++ } ++ break; ++ } ++ case ilu : ++ { ++ for (unsigned int i=0; i, paralution::LocalVector, ++ Number> *precond = new paralution::ILU, ++ paralution::LocalVector, Number>; ++ preconditioners[i] = precond; ++ } ++ break; ++ } ++ case ilut : ++ { ++ for (unsigned int i=0; i, paralution::LocalVector, ++ Number> *precond = new paralution::ILUT, ++ paralution::LocalVector, Number>; ++ preconditioners[i] = precond; ++ } ++ break; ++ } ++ case multicolored_ilu : ++ { ++ for (unsigned int i=0; i, ++ paralution::LocalVector, Number> *precond = ++ new paralution::MultiColoredILU, ++ paralution::LocalVector, Number>; ++ preconditioners[i] = precond; ++ } ++ break; ++ } ++ default : ++ { ++ AssertThrow(false,ExcMessage("Unknown preconditioner for the smoother for PreconditionAMG.")); ++ } ++ } ++ ++ for (unsigned int i=0; iSetPreconditioner(*preconditioners[i]); ++ smoothers[i]->Verbose(0); ++ } ++ downcasted_ptr->SetSmoother(smoothers); ++ ++ // Coarse solver ++ switch (additional_data.coarse_solver) ++ { ++ case richardson : ++ { ++ paralution::FixedPoint, paralution::LocalVector, ++ Number> *cs = new paralution::FixedPoint, ++ paralution::LocalVector, Number>; ++ coarse_solver = cs; ++ break; ++ } ++ case cg : ++ { ++ paralution::CG, paralution::LocalVector, ++ Number> *cs = new paralution::CG, ++ paralution::LocalVector, Number>; ++ coarse_solver = cs; ++ break; ++ } ++ case cr : ++ { ++ paralution::CR, paralution::LocalVector, ++ Number> *cs = new paralution::CR, ++ paralution::LocalVector, Number>; ++ coarse_solver = cs; ++ break; ++ } ++ case bicgstab : ++ { ++ paralution::BiCGStab, paralution::LocalVector, ++ Number> *cs = new paralution::BiCGStab, ++ paralution::LocalVector, Number>; ++ coarse_solver = cs; ++ break; ++ } ++ case gmres : ++ { ++ paralution::GMRES, paralution::LocalVector, ++ Number> *cs = new paralution::GMRES, ++ paralution::LocalVector, Number>; ++ coarse_solver = cs; ++ break; ++ } ++ case fgmres : ++ { ++ paralution::FGMRES, paralution::LocalVector, ++ Number> *cs = new paralution::FGMRES, ++ paralution::LocalVector, Number>; ++ coarse_solver = cs; ++ break; ++ } ++ default : ++ { ++ AssertThrow(false,ExcMessage("Unknown smoother for PreconditionAMG.")); ++ } ++ } ++ ++ downcasted_ptr->SetSolver(*coarse_solver); ++ } ++ } ++ ++ ++ ++ template ++ void PreconditionAMG::clear() ++ { ++ // Free the coarse solver. ++ if (coarse_solver!=NULL) ++ { ++ delete coarse_solver; ++ coarse_solver = NULL; ++ } ++ ++ // Free the preconditioners ++ for (unsigned int i=0; i; + template class PreconditionBase; + template class PreconditionJacobi; + template class PreconditionJacobi; + template class PreconditionSGS; + template class PreconditionSGS; + template class PreconditionMultiColoredSGS; + template class PreconditionMultiColoredSGS; + template class PreconditionMultiColoredSOR; + template class PreconditionMultiColoredSOR; + template class PreconditionILU; + template class PreconditionILU; + template class PreconditionILUT; + template class PreconditionILUT; + template class PreconditionMultiColoredILU; + template class PreconditionMultiColoredILU; ++ template class PreconditionAMG; ++ template class PreconditionAMG; +} + +DEAL_II_NAMESPACE_CLOSE + +#endif // DEAL_II_WITH_PARALUTION diff --cc deal.II/source/lac/paralution_solver.cc index 22c5278ebc,0000000000..20f15b08c9 mode 100644,000000..100644 --- a/deal.II/source/lac/paralution_solver.cc +++ b/deal.II/source/lac/paralution_solver.cc @@@ -1,423 -1,0 +1,442 @@@ +// --------------------------------------------------------------------- +// $Id: paralution_solver.cc 31349 2013-10-20 19:07:06Z maier $ +// +// Copyright (C) 2013, 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 + +#ifdef DEAL_II_WITH_PARALUTION + +DEAL_II_NAMESPACE_OPEN + +namespace ParalutionWrappers +{ + SolverBase::SolverBase (SolverControl &cn) + : + solver_control (cn) + {} + + + + SolverControl &SolverBase::control() const + { + return solver_control; + } + + + + template + void SolverBase::execute_solve(std_cxx1x::shared_ptr,paralution::LocalVector,Number> > solver, - const SparseMatrix &A, ++ SparseMatrix &A, + Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, ++ Vector &b, ++ PreconditionBase &preconditioner, + bool move_to_accelerator) + { + // Set the preconditioner. + solver->SetPreconditioner(*(preconditioner.preconditioner)); + - // Set the system to solve ++ // 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()); + ++ // Build the solver. ++ solver->Build(); ++ + // Move the solver to the accelerator if necessary. + if (move_to_accelerator==true) - solver->MoveToAccelerator(); ++ { ++ A.move_to_accelerator(); ++ x.move_to_accelerator(); ++ b.move_to_accelerator(); ++ solver->MoveToAccelerator(); ++ } + - solver->Build(); + solver->Solve(b.paralution_vector(),&(x.paralution_vector())); ++ ++ // Let the deal.II SolverControl object know what has happened. If the solve ++ // succeeded, the status of the solver control will turn into ++ // SolverControl::success. solver_control only exists on the host so the solver ++ // needs to be on the most. ++ solver->MoveToHost(); ++ ++ solver_control.check (solver->GetIterationCount(), solver->GetCurrentResidual()); ++ ++ if (solver_control.last_check() != SolverControl::success) ++ AssertThrow(false, SolverControl::NoConvergence (solver_control.last_step(), ++ solver_control.last_value())); + } + + + + /* --------------------- SolverRichardson----------------- */ + + SolverRichardson::AdditionalData::AdditionalData(const unsigned int verbose, + const double relaxation_parameter) + : + verbose(verbose), + relaxation_parameter(relaxation_parameter) + {} + + + + SolverRichardson::SolverRichardson (SolverControl &cn, + const AdditionalData &data) + : + SolverBase (cn), + additional_data (data) + {} + + + + template - void SolverRichardson::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator) ++ void SolverRichardson::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator) + { + std_cxx1x::shared_ptr, + paralution::LocalVector,Number> > solver(new paralution:: + FixedPoint, paralution::LocalVector,Number>); + + // Set the verbosity of the solver. + solver->Verbose(additional_data.verbose); + + // Set the relaxation parameter. + solver->SetRelaxation(additional_data.relaxation_parameter); + + this->execute_solve(solver,A,x,b,preconditioner,move_to_accelerator); + } + + + + /* ---------------------- SolverCG ------------------------- */ + + SolverCG::AdditionalData::AdditionalData(const unsigned int verbose) + : + verbose(verbose) + {} + + + + SolverCG::SolverCG (SolverControl &cn, const AdditionalData &data) + : + SolverBase (cn), + additional_data (data) + {} + + + + template - void SolverCG::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator) ++ void SolverCG::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator) + { + std_cxx1x::shared_ptr, + paralution::LocalVector,Number> > solver(new paralution:: + CG,paralution::LocalVector,Number>); + + // Set the verbosity of the solver. + solver->Verbose(additional_data.verbose); + + this->execute_solve(solver,A,x,b,preconditioner,move_to_accelerator); + } + + + + /* ---------------------- SolverCR ------------------------- */ + + SolverCR::AdditionalData::AdditionalData(const unsigned int verbose) + : + verbose(verbose) + {} + + + + SolverCR::SolverCR (SolverControl &cn, const AdditionalData &data) + : + SolverBase (cn), + additional_data (data) + {} + + + + template - void SolverCR::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator) ++ void SolverCR::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator) + { + std_cxx1x::shared_ptr, + paralution::LocalVector,Number> > solver(new paralution:: + CR,paralution::LocalVector,Number>); + + // Set the verbosity of the solver. + solver->Verbose(additional_data.verbose); + + this->execute_solve(solver,A,x,b,preconditioner,move_to_accelerator); + } + + + + /* ---------------------- SolverDPCG ----------------------- */ + + SolverDPCG::AdditionalData::AdditionalData(const unsigned int verbose, - const const unsigned int n_deflated_vectors) ++ const unsigned int n_deflated_vectors) + : + verbose (verbose), + n_deflated_vectors(n_deflated_vectors) + {} + + + + SolverDPCG::SolverDPCG (SolverControl &cn, const AdditionalData &data) + : + SolverBase (cn), + additional_data (data) + {} + + + + template - void SolverDPCG::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator) ++ void SolverDPCG::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator) + { + std_cxx1x::shared_ptr, + paralution::LocalVector,Number> > solver(new paralution:: + DPCG, paralution::LocalVector,Number>); + + // Set the verbosity of the solver. + solver->Verbose(additional_data.verbose); + + // Set the number of deflated vectors. + solver->SetNVectors(additional_data.n_deflated_vectors); + + this->execute_solve(solver,A,x,b,preconditioner,move_to_accelerator); + } + + + + /* -------------------- SolverBicgstab --------------------- */ + + SolverBicgstab::AdditionalData::AdditionalData(const unsigned int verbose) + : + verbose(verbose) + {} + + + + SolverBicgstab::SolverBicgstab (SolverControl &cn, const AdditionalData &data) + : + SolverBase (cn), + additional_data (data) + {} + + + + template - void SolverBicgstab::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator) ++ void SolverBicgstab::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator) + { + std_cxx1x::shared_ptr, + paralution::LocalVector,Number> > solver(new paralution:: + BiCGStab,paralution::LocalVector,Number>); + + // Set the verbosity of the solver. + solver->Verbose(additional_data.verbose); + + this->execute_solve(solver,A,x,b,preconditioner,move_to_accelerator); + } + + + + /* --------------------- SolverGMRES ----------------------- */ + + SolverGMRES::AdditionalData::AdditionalData(const unsigned int verbose, + const unsigned int restart_parameter) + : + verbose(verbose), + restart_parameter(restart_parameter) + {} + + + + SolverGMRES::SolverGMRES (SolverControl &cn, + const AdditionalData &data) + : + SolverBase (cn), + additional_data (data) + {} + + + + template - void SolverGMRES::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator) ++ void SolverGMRES::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator) + { + std_cxx1x::shared_ptr, + paralution::LocalVector,Number> > solver(new paralution:: + GMRES, paralution::LocalVector,Number>); + + // Set the verbosity of the solver. + solver->Verbose(additional_data.verbose); + + // Set the restart parameter. + solver->SetBasisSize(additional_data.restart_parameter); + + this->execute_solve(solver,A,x,b,preconditioner,move_to_accelerator); + } + + + + /* --------------------- SolverFGMRES ---------------------- */ + + SolverFGMRES::AdditionalData::AdditionalData(const unsigned int verbose, + const unsigned int restart_parameter) + : + verbose(verbose), + restart_parameter(restart_parameter) + {} + + + + SolverFGMRES::SolverFGMRES (SolverControl &cn, + const AdditionalData &data) + : + SolverBase (cn), + additional_data (data) + {} + + + + template - void SolverFGMRES::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator) ++ void SolverFGMRES::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator) + { + std_cxx1x::shared_ptr, + paralution::LocalVector,Number> > solver(new paralution:: + FGMRES, paralution::LocalVector,Number>); + + // Set the verbosity of the solver. + solver->Verbose(additional_data.verbose); + + // Set the restart parameter. + solver->SetBasisSize(additional_data.restart_parameter); + + this->execute_solve(solver,A,x,b,preconditioner,move_to_accelerator); + } +} + + + +// Explicit instantiations +namespace ParalutionWrappers +{ - template void SolverCG::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator); - - template void SolverCG::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator); - - template void SolverCR::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator); - - template void SolverCR::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator); - - template void SolverDPCG::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator); - - template void SolverDPCG::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator); - - template void SolverBicgstab::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator); - - template void SolverBicgstab::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator); - - template void SolverGMRES::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator); - - template void SolverGMRES::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator); - - template void SolverFGMRES::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator); - - template void SolverFGMRES::solve(const SparseMatrix &A, - Vector &x, - const Vector &b, - const PreconditionBase &preconditioner, - bool move_to_accelerator); ++ template void SolverCG::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator); ++ ++ template void SolverCG::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator); ++ ++ template void SolverCR::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator); ++ ++ template void SolverCR::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator); ++ ++ template void SolverDPCG::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator); ++ ++ template void SolverDPCG::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator); ++ ++ template void SolverBicgstab::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator); ++ ++ template void SolverBicgstab::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator); ++ ++ template void SolverGMRES::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator); ++ ++ template void SolverGMRES::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator); ++ ++ template void SolverFGMRES::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator); ++ ++ template void SolverFGMRES::solve(SparseMatrix &A, ++ Vector &x, ++ Vector &b, ++ PreconditionBase &preconditioner, ++ bool move_to_accelerator); +} + +DEAL_II_NAMESPACE_CLOSE + +#endif // DEAL_II_WITH_PARALUTION