Commit 4533ce20 authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

Fixed preconditioner bug in serial computations.

parent e916a98c
...@@ -44,19 +44,19 @@ namespace AMDiS { ...@@ -44,19 +44,19 @@ namespace AMDiS {
template <typename ITLSolver> template <typename ITLSolver>
class ITL_OEMSolver : public MTL4Solver< MTLTypes::MTLMatrix, MTLTypes::MTLVector, ITL_OEMSolver_runner< ITLSolver, MTLTypes::MTLMatrix, MTLTypes::MTLVector> > { class ITL_OEMSolver : public MTL4Solver< MTLTypes::MTLMatrix, MTLTypes::MTLVector, ITL_OEMSolver_runner< ITLSolver, MTLTypes::MTLMatrix, MTLTypes::MTLVector> > {
protected: protected:
public: public:
/// The constructor reads needed parameters and sets solvers \ref name. /// The constructor reads needed parameters and sets solvers \ref name.
ITL_OEMSolver(std::string name) : ITL_OEMSolver(std::string name) :
MTL4Solver< MTLTypes::MTLMatrix, MTLTypes::MTLVector, ITL_OEMSolver_runner< ITLSolver, MTLTypes::MTLMatrix, MTLTypes::MTLVector > >(name) {} MTL4Solver< MTLTypes::MTLMatrix, MTLTypes::MTLVector, ITL_OEMSolver_runner< ITLSolver, MTLTypes::MTLMatrix, MTLTypes::MTLVector > >(name) {}
int solveSystem(const SolverMatrix<Matrix<DOFMatrix*> >& A, int solveSystem(const SolverMatrix<Matrix<DOFMatrix*> >& A,
SystemVector& x, SystemVector& x,
SystemVector& b, SystemVector& b,
VectorialMapper& m) VectorialMapper& m)
{ {
return MTL4Solver< MTLTypes::MTLMatrix, MTLTypes::MTLVector, ITL_OEMSolver_runner< ITLSolver, MTLTypes::MTLMatrix, MTLTypes::MTLVector > >::solve(A,x,b,m); return MTL4Solver< MTLTypes::MTLMatrix, MTLTypes::MTLVector, ITL_OEMSolver_runner< ITLSolver, MTLTypes::MTLMatrix, MTLTypes::MTLVector > >::solve(A,x,b,m);
} }
...@@ -74,7 +74,7 @@ namespace AMDiS { ...@@ -74,7 +74,7 @@ namespace AMDiS {
return new ITL_OEMSolver<ITLSolver>(this->name); return new ITL_OEMSolver<ITLSolver>(this->name);
} }
}; };
}; };
/** /**
...@@ -91,22 +91,20 @@ namespace AMDiS { ...@@ -91,22 +91,20 @@ namespace AMDiS {
/// The constructor reads needed parameters and sets solvers \ref name. /// The constructor reads needed parameters and sets solvers \ref name.
ITL_OEMSolver_para(std::string name) ITL_OEMSolver_para(std::string name)
: MTL4Solver< MTLMatrix, MTLVector, ITL_OEMSolver_para_runner< ITLSolver, MTLTypes::MTLMatrix, MTLTypes::MTLVector > >(name) : MTL4Solver< MTLMatrix, MTLVector, ITL_OEMSolver_para_runner< ITLSolver, MTLTypes::MTLMatrix, MTLTypes::MTLVector > >(name)
{ {}
}
int solveSystem(const SolverMatrix<Matrix<DOFMatrix*> >& A, int solveSystem(const SolverMatrix<Matrix<DOFMatrix*> >& A,
SystemVector& x, SystemVector& x,
SystemVector& b, SystemVector& b,
VectorialMapper& m) VectorialMapper& m)
{ {
return MTL4Solver< MTLMatrix, MTLVector, ITL_OEMSolver_para_runner< ITLSolver, MTLTypes::MTLMatrix, MTLTypes::MTLVector > >::solve(A,x,b,m); return MTL4Solver< MTLMatrix, MTLVector, ITL_OEMSolver_para_runner< ITLSolver, MTLTypes::MTLMatrix, MTLTypes::MTLVector > >::solve(A,x,b,m);
} }
~ITL_OEMSolver_para() {} ~ITL_OEMSolver_para() {}
/// Set parameter of iterative solver /// Set parameter of iterative solver
class Creator : public OEMSolverCreator class Creator : public OEMSolverCreator
{ {
public: public:
......
...@@ -58,13 +58,13 @@ namespace AMDiS { ...@@ -58,13 +58,13 @@ namespace AMDiS {
BaseITL_runner(oem_), BaseITL_runner(oem_),
ell(1) ell(1)
{ {
ell=oem.getMaxIterations(); ell = oem.getMaxIterations();
Parameters::get(oem.getName() + "->ell", ell); Parameters::get(oem.getName() + "->ell", ell);
} }
void init(const Matrix& A) void init(const Matrix& A)
{ {
BaseITL_runner::setPrecon(preconPair, A); BaseITL_runner::setPrecon(preconPair, A);
} }
int solve(const Matrix& A, Vector& x, Vector& b) int solve(const Matrix& A, Vector& x, Vector& b)
...@@ -84,6 +84,19 @@ namespace AMDiS { ...@@ -84,6 +84,19 @@ namespace AMDiS {
return error; return error;
} }
void exit()
{
if (preconPair.l != NULL) {
delete preconPair.l;
preconPair.l = NULL;
}
if (preconPair.r != NULL) {
delete preconPair.r;
preconPair.r = NULL;
}
}
private: private:
PreconPair< Vector > preconPair; PreconPair< Vector > preconPair;
ITLSolver solver; ITLSolver solver;
...@@ -91,35 +104,47 @@ namespace AMDiS { ...@@ -91,35 +104,47 @@ namespace AMDiS {
}; };
template< typename ITLSolver, typename Matrix, typename Vector > template< typename ITLSolver, typename Matrix, typename Vector >
struct ITL_OEMSolver_runner : BaseITL_runner { struct ITL_OEMSolver_runner : BaseITL_runner {
ITL_OEMSolver_runner(OEMSolver* oem): ITL_OEMSolver_runner(OEMSolver* oem):
BaseITL_runner(oem) BaseITL_runner(oem)
{} {}
void init(const Matrix& A) void init(const Matrix& A)
{ {
BaseITL_runner::setPrecon(preconPair, A); BaseITL_runner::setPrecon(preconPair, A);
} }
int solve(const Matrix& A , Vector& x, Vector& b) int solve(const Matrix& A , Vector& x, Vector& b)
{ {
FUNCNAME("ITL_OEMSolver_runner::solve()"); FUNCNAME("ITL_OEMSolver_runner::solve()");
TEST_EXIT(preconPair.l != NULL)("there is no left preconditioner"); TEST_EXIT(preconPair.l != NULL)("there is no left preconditioner");
TEST_EXIT(preconPair.r != NULL)("there is no right preconditioner"); TEST_EXIT(preconPair.r != NULL)("there is no right preconditioner");
Vector r(A * x - b); Vector r(A * x - b);
itl::cyclic_iteration<typename Matrix::value_type> iter(r, oem.getMaxIterations(), oem.getRelative(), itl::cyclic_iteration<typename Matrix::value_type> iter(r, oem.getMaxIterations(), oem.getRelative(),
oem.getTolerance(), oem.getPrint_cycle()); oem.getTolerance(), oem.getPrint_cycle());
int error = solver(A, x, b, *(preconPair.l), *(preconPair.r), iter); int error = solver(A, x, b, *(preconPair.l), *(preconPair.r), iter);
oem.setErrorCode(error); oem.setErrorCode(error);
oem.setIterations(iter.iterations()); oem.setIterations(iter.iterations());
oem.setResidual(iter.resid()); oem.setResidual(iter.resid());
return error; return error;
} }
private:
void exit()
{
if (preconPair.l != NULL) {
delete preconPair.l;
preconPair.l = NULL;
}
if (preconPair.r != NULL) {
delete preconPair.r;
preconPair.r = NULL;
}
}
private:
ITLSolver solver; ITLSolver solver;
PreconPair< Vector > preconPair; PreconPair< Vector > preconPair;
}; };
......
...@@ -34,10 +34,6 @@ ...@@ -34,10 +34,6 @@
namespace AMDiS { namespace AMDiS {
// ============================================================================
// ===== class ITL_Preconditioner ==============================================
// ============================================================================
/** /**
* \ingroup Solver * \ingroup Solver
...@@ -48,26 +44,25 @@ namespace AMDiS { ...@@ -48,26 +44,25 @@ namespace AMDiS {
class ITL_BasePreconditioner class ITL_BasePreconditioner
{ {
public: public:
virtual ~ITL_BasePreconditioner() {} virtual ~ITL_BasePreconditioner() {}
// Old style AMDiS // Old style AMDiS
// virtual Vec member_solve(const Vec& vin) const =0 ; // virtual Vec member_solve(const Vec& vin) const =0 ;
// virtual Vec member_adjoint_solve(const Vec& vin) const =0 ; // virtual Vec member_adjoint_solve(const Vec& vin) const =0 ;
// New style without copying the result vector // New style without copying the result vector
virtual void solve(const Vec& x, Vec& y) const= 0; virtual void solve(const Vec& x, Vec& y) const= 0;
virtual void adjoint_solve(const Vec& x, Vec& y) const= 0; virtual void adjoint_solve(const Vec& x, Vec& y) const= 0;
}; };
template< typename Vec > template< typename Vec >
inline //Vec inline //Vec
itl::pc::solver<ITL_BasePreconditioner< Vec >, Vec, false> itl::pc::solver<ITL_BasePreconditioner< Vec >, Vec, false>
solve(const ITL_BasePreconditioner< Vec >& P, const Vec& vin) solve(const ITL_BasePreconditioner< Vec >& P, const Vec& vin)
{ {
return itl::pc::solver<ITL_BasePreconditioner< Vec >, Vec, false>(P, vin); return itl::pc::solver<ITL_BasePreconditioner< Vec >, Vec, false>(P, vin);
//return P.member_solve(vin);
} }
template< typename Vec > template< typename Vec >
...@@ -76,7 +71,6 @@ namespace AMDiS { ...@@ -76,7 +71,6 @@ namespace AMDiS {
adjoint_solve(const ITL_BasePreconditioner< Vec >& P, const Vec& vin) adjoint_solve(const ITL_BasePreconditioner< Vec >& P, const Vec& vin)
{ {
return itl::pc::solver<ITL_BasePreconditioner< Vec >, Vec, true>(P, vin); return itl::pc::solver<ITL_BasePreconditioner< Vec >, Vec, true>(P, vin);
//return P.member_adjoint_solve(vin);
} }
/** /**
...@@ -89,31 +83,16 @@ namespace AMDiS { ...@@ -89,31 +83,16 @@ namespace AMDiS {
{ {
public: public:
ITL_Preconditioner(const MTLMatrix& A) : precon(A) {} ITL_Preconditioner(const MTLMatrix& A) : precon(A) {}
#if 0
MTLVector
member_solve(const MTLVector& vin) const
{
return solve(precon, vin);
}
MTLVector
member_adjoint_solve(const MTLVector& vin) const
{
return adjoint_solve(precon, vin);
}
#else
void solve(const MTLVector& vin, MTLVector& vout) const void solve(const MTLVector& vin, MTLVector& vout) const
{ {
precon.solve(vin, vout); precon.solve(vin, vout);
} }
void adjoint_solve(const MTLVector& vin, MTLVector& vout) const void adjoint_solve(const MTLVector& vin, MTLVector& vout) const
{ {
precon.adjoint_solve(vin, vout); precon.adjoint_solve(vin, vout);
} }
#endif
/// Creator class used in the OEMSolverMap. /// Creator class used in the OEMSolverMap.
class Creator : public CreatorInterface< ITL_BasePreconditioner< MTLVector > > class Creator : public CreatorInterface< ITL_BasePreconditioner< MTLVector > >
{ {
...@@ -127,16 +106,13 @@ namespace AMDiS { ...@@ -127,16 +106,13 @@ namespace AMDiS {
return new ITL_Preconditioner<Preconditioner, MTLVector, MTLMatrix>(A); return new ITL_Preconditioner<Preconditioner, MTLVector, MTLMatrix>(A);
} }
}; };
private: private:
Preconditioner precon; Preconditioner precon;
}; };
// ============================================================================
// ===== class DiagonalPreconditioner =========================================
// ============================================================================
/** /**
* \ingroup Solver * \ingroup Solver
* *
...@@ -168,26 +144,22 @@ namespace AMDiS { ...@@ -168,26 +144,22 @@ namespace AMDiS {
}; };
// ============================================================================
// ===== class ILUPreconditioner ==============================================
// ============================================================================
/** /**
* \ingroup Solver * \ingroup Solver
* *
* \brief * \brief
* ILU (Incomplete LU factorization) preconditioner. * ILU (Incomplete LU factorization) preconditioner.
* *
* The preconditioner is used from ITL. It corresponds for instance to "Iterative Methods for * The preconditioner is used from ITL. It corresponds for instance to
* Sparce Linear Systems", second edition, Yousef Saad. The preconditioner is * "Iterative Methods for Sparce Linear Systems", second edition, Yousef Saad.
* described in chapter 10.3 (algorithm 10.4). * The preconditioner is described in chapter 10.3 (algorithm 10.4).
*/ */
class ILUPreconditioner class ILUPreconditioner
: public ITL_Preconditioner< itl::pc::ilu_0<MTLTypes::MTLMatrix>, MTLTypes::MTLVector, MTLTypes::MTLMatrix > : public ITL_Preconditioner< itl::pc::ilu_0<MTLTypes::MTLMatrix>, MTLTypes::MTLVector, MTLTypes::MTLMatrix >
{}; {};
class ICPreconditioner class ICPreconditioner
: public ITL_Preconditioner< itl::pc::ic_0<MTLTypes::MTLMatrix>, MTLTypes::MTLVector, MTLTypes::MTLMatrix > : public ITL_Preconditioner< itl::pc::ic_0<MTLTypes::MTLMatrix>, MTLTypes::MTLVector, MTLTypes::MTLMatrix >
{}; {};
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include <boost/numeric/mtl/utility/is_distributed.hpp> #include <boost/numeric/mtl/utility/is_distributed.hpp>
#if defined(HAVE_PARALLEL_DOMAIN_AMDIS) && defined(HAVE_PARALLEL_MTL4) #if defined(HAVE_PARALLEL_DOMAIN_AMDIS) && defined(HAVE_PARALLEL_MTL4)
# include <boost/numeric/mtl/par/distribution.hpp> #include <boost/numeric/mtl/par/distribution.hpp>
#endif #endif
namespace AMDiS { namespace AMDiS {
...@@ -71,7 +71,7 @@ namespace AMDiS { ...@@ -71,7 +71,7 @@ namespace AMDiS {
FUNCNAME("MTL4Solver::solve()"); FUNCNAME("MTL4Solver::solve()");
Timer t; Timer t;
if(num_rows(matrix) == 0 || !getMultipleRhs() ) { if (num_rows(matrix) == 0 || !getMultipleRhs()) {
init(mapper, mtl::traits::is_distributed<MTLMatrix>()); init(mapper, mtl::traits::is_distributed<MTLMatrix>());
set_to_zero(matrix); set_to_zero(matrix);
...@@ -81,13 +81,13 @@ namespace AMDiS { ...@@ -81,13 +81,13 @@ namespace AMDiS {
} }
MTLVector mtl_x; MTLVector mtl_x;
init(mtl_x,mtl::traits::is_distributed<MTLVector>()); init(mtl_x, mtl::traits::is_distributed<MTLVector>());
set_to_zero(mtl_x); set_to_zero(mtl_x);
VecMap< Vector, Mapper > xVecMap(x, mapper); VecMap< Vector, Mapper > xVecMap(x, mapper);
mtl_x << xVecMap; mtl_x << xVecMap;
MTLVector mtl_b; MTLVector mtl_b;
init(mtl_b,mtl::traits::is_distributed<MTLVector>()); init(mtl_b, mtl::traits::is_distributed<MTLVector>());
set_to_zero(mtl_b); set_to_zero(mtl_b);
VecMap< Vector, Mapper> bVecMap(b, mapper); VecMap< Vector, Mapper> bVecMap(b, mapper);
mtl_b << bVecMap; mtl_b << bVecMap;
...@@ -104,6 +104,9 @@ namespace AMDiS { ...@@ -104,6 +104,9 @@ namespace AMDiS {
MSG("MTL4Solver: ||b-Ax||= %e\n", residual); MSG("MTL4Solver: ||b-Ax||= %e\n", residual);
mtl_x >> xVecMap; mtl_x >> xVecMap;
worker.exit();
return error; return error;
} }
......
...@@ -45,7 +45,6 @@ ...@@ -45,7 +45,6 @@
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS #ifdef HAVE_PARALLEL_DOMAIN_AMDIS
#include "parallel/ParallelMapper.h" #include "parallel/ParallelMapper.h"
#endif #endif
//#include "ITL_Preconditioner.h"
namespace AMDiS { namespace AMDiS {
...@@ -99,7 +98,8 @@ namespace AMDiS { ...@@ -99,7 +98,8 @@ namespace AMDiS {
VectorialMapper&) VectorialMapper&)
{ {
FUNCNAME("OEMSolver::solveSystem()"); FUNCNAME("OEMSolver::solveSystem()");
TEST_EXIT(false)("This linear solver is not suitable for sequentiell problems\n"); TEST_EXIT(false)
("This linear solver is not suitable for sequentiell problems\n");
return -1; return -1;
} }
...@@ -118,7 +118,8 @@ namespace AMDiS { ...@@ -118,7 +118,8 @@ namespace AMDiS {
ParallelMapper&) ParallelMapper&)
{ {
FUNCNAME("OEMSolver::solveSystem()"); FUNCNAME("OEMSolver::solveSystem()");
TEST_EXIT(false)("This linear solver is not suitable for domaindecomposition problems\n"); TEST_EXIT(false)
("This linear solver is not suitable for domaindecomposition problems\n");
return -1; return -1;
} }
#endif #endif
...@@ -269,11 +270,9 @@ namespace AMDiS { ...@@ -269,11 +270,9 @@ namespace AMDiS {
/// Error code in last solver (not set by UmfPack) /// Error code in last solver (not set by UmfPack)
int error; int error;
/** \brief /// If true, the solver has to solve multiple right hand sides with the same
* If true, the solver has to solve multiple right hand sides with the same /// matrix. Some solvers, e.g. direct once, may take advanteges from this knowledge,
* matrix. Some solvers, e.g. direct once, may take advanteges from this knowledge, /// as they can do the factorization of the matrix only once.
* as they can do the factorization of the matrix only once.
*/
bool multipleRhs; bool multipleRhs;
}; };
...@@ -295,10 +294,8 @@ namespace AMDiS { ...@@ -295,10 +294,8 @@ namespace AMDiS {
} }
protected: protected:
/** \brief /// Pointer to the problem the solver will belong to. Needed as parameter
* Pointer to the problem the solver will belong to. Needed as parameter /// when constructing an OEMSolver
* when constructing an OEMSolver
*/
std::string name; std::string name;
}; };
} }
......
...@@ -94,9 +94,11 @@ namespace AMDiS { ...@@ -94,9 +94,11 @@ namespace AMDiS {
TEST_EXIT(residual <= oem.getTolerance())("Tolerance tol = %e could not be reached!\n Set tolerance by '->solver->tolerance:' \n", oem.getTolerance()); TEST_EXIT(residual <= oem.getTolerance())("Tolerance tol = %e could not be reached!\n Set tolerance by '->solver->tolerance:' \n", oem.getTolerance());
} }
return code; return code;
} }
void exit()
{}
~Umfpack_runner() ~Umfpack_runner()
{ {
if (solver != NULL) if (solver != NULL)
...@@ -135,17 +137,15 @@ namespace AMDiS { ...@@ -135,17 +137,15 @@ namespace AMDiS {
/// Constructor /// Constructor
UmfPackSolver(std::string name) UmfPackSolver(std::string name)
: MTL4Solver< MTLMatrix, MTLVector, Umfpack_runner< MTLMatrix > >(name) : MTL4Solver< MTLMatrix, MTLVector, Umfpack_runner< MTLMatrix > >(name)
{ {}
}
int solveSystem(const SolverMatrix<Matrix<DOFMatrix*> >& A, int solveSystem(const SolverMatrix<Matrix<DOFMatrix*> >& A,
SystemVector& x, SystemVector& x,
SystemVector& b, SystemVector& b,
VectorialMapper& m) VectorialMapper& m)
{ {
return solve(A,x,b,m); return solve(A,x,b,m);
} }
private: private:
}; };
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment