SOFA API  1a4bb3e7
Open source framework for multi-physics simuation
sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager > Class Template Reference

#include <AsyncSparseLDLSolver.h>

Inheritance diagram for sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >:

Detailed Description

template<class TMatrix, class TVector, class TThreadManager = NoThreadManager>
class sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >

This linear solver is based on SparseLDLSolver, a direct linear solver which factorizes the linear system matrix. Its particularity is its asynchronous factorization.

The synchronous version performs the following operations (synchronously): 1) Build the matrix 2) Factorize the matrix 3) Solve the system based on the factorization

In the asynchronous version, the factorization is performed asynchronously. A consequence is that the solving process uses a factorization which may not be up to date. In practice, the factorization is at least one time step old. Because of this, the solver computes an approximation of the solution, based on an old factorization. It changes the behavior compared to a synchronous version, but it also changes the behavior depending on the duration of the factorization step. It may introduce instabilities.

Protected Attributes

InvertData m_secondInvertData
 
InvertDatam_mainThreadInvertData { nullptr }
 
InvertDatam_asyncThreadInvertData { nullptr }
 
std::future< void > m_asyncResult
 Result of the asynchronous task. More...
 
bool waitForAsyncTask { true }
 
std::atomic< boolnewInvertDataReady { false }
 
bool m_hasUpdatedMatrix { false }
 
- Protected Attributes inherited from sofa::component::linearsolver::direct::SparseLDLSolver< TMatrix, TVector, NoThreadManager >
type::vector< sofa::SignedIndex > Jlocal2global
 
sofa::linearalgebra::FullMatrix< RealJLinvDinv
 
sofa::linearalgebra::FullMatrix< RealJLinv
 
sofa::linearalgebra::CompressedRowSparseMatrix< RealMfiltered
 
- Protected Attributes inherited from sofa::component::linearsolver::direct::SparseLDLSolverImpl< TMatrix, TVector, NoThreadManager >
Data< boold_precomputeSymbolicDecomposition
 If true the solver will reuse the precomputed symbolic decomposition. Otherwise it will recompute it at each step. More...
 
core::objectmodel::lifecycle::DeprecatedData d_applyPermutation
 
Data< int > d_L_nnz
 Number of non-zero values in the lower triangular matrix of the factorization. The lower, the faster the system is solved. More...
 
type::vector< RealTmp
 
type::vector< RealY
 
type::vector< int > Lnz
 
type::vector< int > Flag
 
type::vector< int > Pattern
 
type::vector< int > tran_countvec
 

Public Member Functions

 SOFA_CLASS (SOFA_TEMPLATE3(AsyncSparseLDLSolver, TMatrix, TVector, TThreadManager), SOFA_TEMPLATE3(SparseLDLSolver, TMatrix, TVector, TThreadManager))
 
bool isAsyncSolver () override
 
void init () override
 
void setSystemMBKMatrix (const core::MechanicalParams *mparams) override
 
void solveSystem () override
 
void solve (Matrix &M, Vector &x, Vector &b) override
 
void invert (TMatrix &M) override
 
bool addJMInvJtLocal (TMatrix *M, ResMatrixType *result, const JMatrixType *J, SReal fact) override
 
bool hasUpdatedMatrix () override
 
void updateSystemMatrix () override
 
 ~AsyncSparseLDLSolver () override
 
- Public Member Functions inherited from sofa::component::linearsolver::direct::SparseLDLSolver< TMatrix, TVector, NoThreadManager >
 SOFA_CLASS (SOFA_TEMPLATE3(SparseLDLSolver, TMatrix, TVector, NoThreadManager), SOFA_TEMPLATE3(SparseLDLSolverImpl, TMatrix, TVector, NoThreadManager))
 
void init () override
 
void parse (sofa::core::objectmodel::BaseObjectDescription *arg) override
 
void solve (Matrix &M, Vector &x, Vector &b) override
 
void invert (Matrix &M) override
 
bool doAddJMInvJtLocal (ResMatrixType *result, const JMatrixType *J, SReal fact, InvertData *data)
 
bool addJMInvJtLocal (TMatrix *M, ResMatrixType *result, const JMatrixType *J, SReal fact) override
 
MatrixInvertDatacreateInvertData () override
 
- Public Member Functions inherited from sofa::component::linearsolver::direct::SparseLDLSolverImpl< TMatrix, TVector, NoThreadManager >
 SOFA_CLASS (SOFA_TEMPLATE3(SparseLDLSolverImpl, TMatrix, TVector, NoThreadManager),)
 
- Public Member Functions inherited from sofa::component::linearsolver::ordering::OrderingMethodAccessor< TBase >
 SOFA_CLASS (OrderingMethodAccessor, TBase)
 
 OrderingMethodAccessor ()
 
 ~OrderingMethodAccessor () override=default
 
void init () override
 
void parse (sofa::core::objectmodel::BaseObjectDescription *arg) override
 

Protected Member Functions

bool isAsyncFactorizationFinished () const
 Return true if an asynchronous factorization has been launched and is finished. More...
 
void launchAsyncFactorization ()
 
void asyncFactorization ()
 
void swapInvertData ()
 Copy the invert data from the async thread to the main thread. More...
 
- Protected Member Functions inherited from sofa::component::linearsolver::direct::SparseLDLSolver< TMatrix, TVector, NoThreadManager >
 SparseLDLSolver ()
 
bool factorize (Matrix &M, InvertData *invertData)
 
void showInvalidSystemMessage (const std::string &reason) const
 
- Protected Member Functions inherited from sofa::component::linearsolver::direct::SparseLDLSolverImpl< TMatrix, TVector, NoThreadManager >
 SparseLDLSolverImpl ()
 
void solve_cpu (Real *x, const Real *b, SparseLDLImplInvertData< VecInt, VecReal > *data)
 
void LDL_ordering (int n, int nnz, int *M_colptr, int *M_rowind, Real *M_values, int *perm, int *invperm)
 
void LDL_symbolic (int n, int *M_colptr, int *M_rowind, int *colptr, int *perm, int *invperm, int *Parent)
 
void LDL_numeric (int n, int *M_colptr, int *M_rowind, Real *M_values, int *colptr, int *rowind, Real *values, Real *D, int *perm, int *invperm, int *Parent)
 
void factorize (int n, int *M_colptr, int *M_rowind, Real *M_values, SparseLDLImplInvertData< VecInt, VecReal > *data)
 

Additional Inherited Members

- Public Attributes inherited from sofa::component::linearsolver::direct::SparseLDLSolver< TMatrix, TVector, NoThreadManager >
int numStep
 
- Public Attributes inherited from sofa::component::linearsolver::ordering::OrderingMethodAccessor< TBase >
SingleLink< OrderingMethodAccessor, core::behavior::BaseOrderingMethod, BaseLink::FLAG_STRONGLINKl_orderingMethod
 

Attribute details

◆ m_asyncResult

template<class TMatrix , class TVector , class TThreadManager = NoThreadManager>
std::future<void> sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::m_asyncResult
protected

Result of the asynchronous task.

◆ m_asyncThreadInvertData

template<class TMatrix , class TVector , class TThreadManager = NoThreadManager>
InvertData* sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::m_asyncThreadInvertData { nullptr }
protected

◆ m_hasUpdatedMatrix

template<class TMatrix , class TVector , class TThreadManager = NoThreadManager>
bool sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::m_hasUpdatedMatrix { false }
protected

◆ m_mainThreadInvertData

template<class TMatrix , class TVector , class TThreadManager = NoThreadManager>
InvertData* sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::m_mainThreadInvertData { nullptr }
protected

◆ m_secondInvertData

template<class TMatrix , class TVector , class TThreadManager = NoThreadManager>
InvertData sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::m_secondInvertData
protected

A second instantiation is needed to differentiate the one which is computed asynchronously, and the one which is used to solve the system in the main thread

◆ newInvertDataReady

template<class TMatrix , class TVector , class TThreadManager = NoThreadManager>
std::atomic<bool> sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::newInvertDataReady { false }
protected

◆ waitForAsyncTask

template<class TMatrix , class TVector , class TThreadManager = NoThreadManager>
bool sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::waitForAsyncTask { true }
protected

Constructor details

◆ ~AsyncSparseLDLSolver()

template<class TMatrix , class TVector , class TThreadManager >
sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::~AsyncSparseLDLSolver
override

Function details

◆ addJMInvJtLocal()

template<class TMatrix , class TVector , class TThreadManager >
bool sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::addJMInvJtLocal ( TMatrix *  M,
ResMatrixType result,
const JMatrixType J,
SReal  fact 
)
override

◆ asyncFactorization()

template<class TMatrix , class TVector , class TThreadManager >
void sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::asyncFactorization
protected

◆ hasUpdatedMatrix()

template<class TMatrix , class TVector , class TThreadManager >
bool sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::hasUpdatedMatrix
override

◆ init()

template<class TMatrix , class TVector , class TThreadManager >
void sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::init ( void  )
override

◆ invert()

template<class TMatrix , class TVector , class TThreadManager >
void sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::invert ( TMatrix &  M)
override

◆ isAsyncFactorizationFinished()

template<class TMatrix , class TVector , class TThreadManager >
bool sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::isAsyncFactorizationFinished
protected

Return true if an asynchronous factorization has been launched and is finished.

◆ isAsyncSolver()

template<class TMatrix , class TVector , class TThreadManager = NoThreadManager>
bool sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::isAsyncSolver ( )
inlineoverride

◆ launchAsyncFactorization()

template<class TMatrix , class TVector , class TThreadManager >
void sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::launchAsyncFactorization
protected

◆ setSystemMBKMatrix()

template<class TMatrix , class TVector , class TThreadManager >
void sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::setSystemMBKMatrix ( const core::MechanicalParams mparams)
override

◆ SOFA_CLASS()

template<class TMatrix , class TVector , class TThreadManager = NoThreadManager>
sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::SOFA_CLASS ( SOFA_TEMPLATE3(AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >, TMatrix, TVector, TThreadManager)  ,
SOFA_TEMPLATE3(SparseLDLSolver, TMatrix, TVector, TThreadManager)   
)

◆ solve()

template<class TMatrix , class TVector , class TThreadManager >
void sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::solve ( Matrix M,
Vector x,
Vector b 
)
override

◆ solveSystem()

template<class TMatrix , class TVector , class TThreadManager >
void sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::solveSystem
override

◆ swapInvertData()

template<class TMatrix , class TVector , class TThreadManager >
void sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::swapInvertData
protected

Copy the invert data from the async thread to the main thread.

◆ updateSystemMatrix()

template<class TMatrix , class TVector , class TThreadManager >
void sofa::component::linearsolver::direct::AsyncSparseLDLSolver< TMatrix, TVector, TThreadManager >::updateSystemMatrix
override