From: turcksin Date: Mon, 2 Jun 2014 16:42:19 +0000 (+0000) Subject: Add a test of Paralution and use astyle on modified files. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c743ddef0dd15085e733aaa38be2a9c0e7995d74;p=dealii-svn.git Add a test of Paralution and use astyle on modified files. git-svn-id: https://svn.dealii.org/branches/branch_paralution@33007 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/lac/paralution_precondition.h b/deal.II/include/deal.II/lac/paralution_precondition.h index 5f07ed9128..4523c21b0d 100644 --- a/deal.II/include/deal.II/lac/paralution_precondition.h +++ b/deal.II/include/deal.II/lac/paralution_precondition.h @@ -45,28 +45,28 @@ namespace ParalutionWrappers template class PreconditionBase { - public : - /** - * Standardized data struct to pipe additional flags to the - * preconditioner. - */ - struct AdditionalData - {}; + public : + /** + * Standardized data struct to pipe additional flags to the + * preconditioner. + */ + struct AdditionalData + {}; - /** - * Constructor. Does not do anything. - */ - PreconditionBase (); + /** + * Constructor. Does not do anything. + */ + PreconditionBase (); - friend class SolverBase; + friend class SolverBase; - protected : - /** - * This is a pointer to the preconditioner object that is used when - * applying the preconditioner. - */ - std_cxx1x::shared_ptr, - paralution::LocalVector,Number> > preconditioner; + protected : + /** + * This is a pointer to the preconditioner object that is used when + * applying the preconditioner. + */ + std_cxx1x::shared_ptr, + paralution::LocalVector,Number> > preconditioner; }; @@ -81,18 +81,18 @@ namespace ParalutionWrappers template class PreconditionJacobi : public PreconditionBase { - public : - /** - * Standardized data struct to pipe additional flags to the - * preconditioner. - */ - struct AdditionalData - {}; + public : + /** + * Standardized data struct to pipe additional flags to the + * preconditioner. + */ + struct AdditionalData + {}; - /** - * Constructor. - */ - PreconditionJacobi (); + /** + * Constructor. + */ + PreconditionJacobi (); private : /** @@ -114,18 +114,18 @@ namespace ParalutionWrappers template class PreconditionSGS : public PreconditionBase { - public : - /** - * Standardized data struct to pipe additional flags to the - * preconditioner. - */ - struct AdditionalData - {}; + public : + /** + * Standardized data struct to pipe additional flags to the + * preconditioner. + */ + struct AdditionalData + {}; - /** - * Constructor. - */ - PreconditionSGS (); + /** + * Constructor. + */ + PreconditionSGS (); private : /** @@ -148,18 +148,18 @@ namespace ParalutionWrappers template class PreconditionMultiColoredSGS : public PreconditionBase { - public : - /** - * Standardized data struct to pipe additional flags to the - * preconditioner. - */ - struct AdditionalData - {}; + public : + /** + * Standardized data struct to pipe additional flags to the + * preconditioner. + */ + struct AdditionalData + {}; - /** - * Constructor. - */ - PreconditionMultiColoredSGS (); + /** + * Constructor. + */ + PreconditionMultiColoredSGS (); private : /** @@ -182,39 +182,39 @@ namespace ParalutionWrappers template class PreconditionMultiColoredSOR : public PreconditionBase { - public : + public : + /** + * Standardized data struct to pipe additional flags to the + * preconditioner. + */ + struct AdditionalData + { /** - * 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. + * Constructor. By default, set the damping parameter to one. */ - PreconditionMultiColoredSOR (const AdditionalData &additional_data = AdditionalData()); + AdditionalData (const double omega = 1); /** - * This function changes the value of the additional flags. + * Relaxation parameter. */ - void initialize (const AdditionalData &additional_data = AdditionalData()); + double omega; + }; - private : - /** - * Store a copy of the flags for this particular preconditioner. - */ - AdditionalData additional_data; + /** + * 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; }; @@ -229,39 +229,39 @@ namespace ParalutionWrappers template class PreconditionILU : public PreconditionBase { - public : + public : + /** + * Standardized data struct to pipe additional flags to the + * preconditioner. + */ + struct AdditionalData + { /** - * Standardized data struct to pipe additional flags to the - * preconditioner. + * Constructor. By default, set the fill-in parameter to zero. */ - struct AdditionalData - { - /** - * Constructor. By default, set the fill-in parameter to zero. - */ - AdditionalData (const unsigned int levels = 0); - - /** - * Fill-in parameter. - */ - unsigned int levels; - }; + AdditionalData (const unsigned int levels = 0); /** - * Constructor. Take additional flags if there are any. + * Fill-in parameter. */ - PreconditionILU (const AdditionalData &additional_data = AdditionalData()); + unsigned int levels; + }; - /** - * This function changes the value of the additional flags. - */ - void initialize (const AdditionalData &additional_data = AdditionalData()); + /** + * Constructor. Take additional flags if there are any. + */ + PreconditionILU (const AdditionalData &additional_data = AdditionalData()); - private : - /** - * Store a copy of the flags for this particular preconditioner. - */ - AdditionalData additional_data; + /** + * 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; }; @@ -279,49 +279,49 @@ namespace ParalutionWrappers template class PreconditionILUT : public PreconditionBase { - public : + public : + /** + * Standardized data struct to pipe additional flags to the + * preconditioner. + */ + struct AdditionalData + { /** - * Standardized data struct to pipe additional flags to the - * preconditioner. + * Constructor. By default, set the threshold to zero. */ - 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; - }; + AdditionalData (const Number threshold = 0.); /** - * Constructor. Take additional flags if there are any. + * Constructor. */ - PreconditionILUT (const AdditionalData &additional_data = AdditionalData()); + AdditionalData (const Number threshold, const unsigned int max_row); /** - * This function changes the value of the additional flags. + * Threshold. */ - void initialize (const AdditionalData &additional_data = AdditionalData()); + Number threshold; - private : /** - * Store a copy of the flags for this particular preconditioner. + * Maximum number of elements per row. */ - AdditionalData additional_data; + 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; }; @@ -339,45 +339,45 @@ namespace ParalutionWrappers template class PreconditionMultiColoredILU : public PreconditionBase { - public : + public : + /** + * Standardized data struct to pipe additional flags to the + * preconditioner. + */ + struct AdditionalData + { /** - * Standardized data struct to pipe additional flags to the - * preconditioner. + * Constructor. By default, set the fill-in parameter to zero and the + * power-pattern to one. */ - 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; - }; + AdditionalData (const unsigned int levels = 0, const unsigned int power = 1); /** - * Constructor. Take additional flags if there are any. + * Fill-in parameter. */ - PreconditionMultiColoredILU (const AdditionalData &additional_data = AdditionalData()); + unsigned int levels; /** - * This function changes the value of additional flags. + * Power parameter. */ - void initialize (const AdditionalData &additional_data = AdditionalData()); + unsigned int power; + }; - private : - /** - * Store a copy of the flags for this particular preconditioner. - */ - AdditionalData additional_data; + /** + * 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; }; } diff --git a/deal.II/source/lac/paralution_precondition.cc b/deal.II/source/lac/paralution_precondition.cc index 9502c32452..3f77ec78cf 100644 --- a/deal.II/source/lac/paralution_precondition.cc +++ b/deal.II/source/lac/paralution_precondition.cc @@ -34,7 +34,7 @@ namespace ParalutionWrappers PreconditionJacobi::PreconditionJacobi() { this->preconditioner.reset(new paralution::Jacobi, - paralution::LocalVector,Number>); + paralution::LocalVector,Number>); } @@ -45,7 +45,7 @@ namespace ParalutionWrappers PreconditionSGS::PreconditionSGS() { this->preconditioner.reset(new paralution::SGS, - paralution::LocalVector,Number>); + paralution::LocalVector,Number>); } @@ -56,7 +56,7 @@ namespace ParalutionWrappers PreconditionMultiColoredSGS::PreconditionMultiColoredSGS() { this->preconditioner.reset(new paralution::MultiColoredSGS, - paralution::LocalVector,Number>); + paralution::LocalVector,Number>); } @@ -65,35 +65,38 @@ namespace ParalutionWrappers template PreconditionMultiColoredSOR::AdditionalData:: - AdditionalData(const double omega) - : + AdditionalData(const double omega) + : omega(omega) {} + template PreconditionMultiColoredSOR::PreconditionMultiColoredSOR( - const AdditionalData &additional_data) - : + const AdditionalData &additional_data) + : additional_data(additional_data) { this->preconditioner.reset(new paralution::MultiColoredGS, - paralution::LocalVector,Number>); + 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()); + LocalVector,Number>* downcasted_ptr = static_cast,paralution::LocalVector, + Number>* >(this->preconditioner.get()); downcasted_ptr->SetRelaxation(additional_data.omega); - } + } @@ -101,28 +104,32 @@ namespace ParalutionWrappers 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>); - + 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()); + Number>* downcasted_ptr = static_cast,paralution::LocalVector,Number>* >(this->preconditioner.get()); downcasted_ptr->Set(additional_data.levels); } @@ -133,42 +140,48 @@ namespace ParalutionWrappers template PreconditionILUT::AdditionalData::AdditionalData(const Number threshold) - : + : threshold(threshold), max_row(0) {} + + template PreconditionILUT::AdditionalData::AdditionalData(const Number threshold, - const unsigned int max_row) - : + 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>); + 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()); + 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); + if (additional_data.max_row==0) + downcasted_ptr->Set(additional_data.threshold); + else + downcasted_ptr->Set(additional_data.threshold,additional_data.max_row); } @@ -178,30 +191,34 @@ namespace ParalutionWrappers 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>); + 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()); + Number>* downcasted_ptr = static_cast,paralution::LocalVector,Number>* >(this->preconditioner.get()); downcasted_ptr->Set(additional_data.levels,additional_data.power); } diff --git a/deal.II/source/lac/paralution_solver.cc b/deal.II/source/lac/paralution_solver.cc index 59c999830b..623a6f17d3 100644 --- a/deal.II/source/lac/paralution_solver.cc +++ b/deal.II/source/lac/paralution_solver.cc @@ -52,7 +52,7 @@ namespace ParalutionWrappers // Set absolute tolerance, relative tolerance, divergence tolerance, // maximum number of iterations. solver->Init(solver_control.tolerance(),0.,1.e100, - solver_control.max_steps()); + solver_control.max_steps()); // Move the solver to the accelerator if necessary. if (move_to_accelerator==true) @@ -81,8 +81,8 @@ namespace ParalutionWrappers bool move_to_accelerator) { std_cxx1x::shared_ptr, - paralution::LocalVector,Number> > solver(new paralution:: - CG,paralution::LocalVector,Number>); + paralution::LocalVector,Number> > solver(new paralution:: + CG,paralution::LocalVector,Number>); this->execute_solve(solver,A,x,b,preconditioner,move_to_accelerator); } @@ -106,8 +106,8 @@ namespace ParalutionWrappers bool move_to_accelerator) { std_cxx1x::shared_ptr, - paralution::LocalVector,Number> > solver(new paralution:: - BiCGStab,paralution::LocalVector,Number>); + paralution::LocalVector,Number> > solver(new paralution:: + BiCGStab,paralution::LocalVector,Number>); this->execute_solve(solver,A,x,b,preconditioner,move_to_accelerator); } @@ -116,6 +116,14 @@ namespace ParalutionWrappers /* --------------------- SolverGMRES ----------------------- */ + SolverGMRES::AdditionalData::AdditionalData(const unsigned int restart_parameter) + : + restart_parameter(restart_parameter) + {} + + + + SolverGMRES::SolverGMRES (SolverControl &cn, const AdditionalData &data) : @@ -133,8 +141,8 @@ namespace ParalutionWrappers bool move_to_accelerator) { std_cxx1x::shared_ptr, - paralution::LocalVector,Number> > solver(new paralution:: - GMRES, paralution::LocalVector,Number>); + paralution::LocalVector,Number> > solver(new paralution:: + GMRES, paralution::LocalVector,Number>); // Set the restart parameter. solver->SetBasisSize(additional_data.restart_parameter); diff --git a/tests/lac/paralution_solver_02.cc b/tests/lac/paralution_solver_02.cc new file mode 100644 index 0000000000..7bc614a68e --- /dev/null +++ b/tests/lac/paralution_solver_02.cc @@ -0,0 +1,74 @@ +// --------------------------------------------------------------------- +// $Id: paralution_solver_01.cc 31349 2013-10-20 19:07:06Z maier $ +// +// Copyright (C) 2013 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. +// +// --------------------------------------------------------------------- + + +// Create a test for ParalutionWrappers::SolverGMRES + +#include "../tests.h" +#include "testmatrix.h" +#include +#include +#include +#include +#include +#include +#include +#include + +int main() +{ + paralution::init_paralution(); + + std::ofstream logfile("output"); + deallog << std::fixed; + deallog << std::setprecision(0); + deallog.attach(logfile); + deallog.depth_console(0); + deallog.threshold_double(1.e-10); + + SolverControl control(100,1.e-3); + ParalutionWrappers::SolverGMRES solver(control); + + for (unsigned int size=4; size<=30; size*=3) + { + unsigned int dim = (size-1)*(size-1); + + deallog << "Size "<< size <<" Unknowns "<< dim << std::endl; + + // Make matrix + FDMatrix testproblem(size, size); + SparsityPattern structure(dim, dim, 5); + testproblem.five_point_structure(structure); + structure.compress(); + ParalutionWrappers::SparseMatrix A(structure); + testproblem.five_point(A); + A.convert_to_paralution_csr(); + + //Preconditioner + ParalutionWrappers::PreconditionMultiColoredSOR p(1.); + + ParalutionWrappers::Vector u(dim); + ParalutionWrappers::Vector f(dim); + for (unsigned int i=0; i