6 #include "qdp-lapack_Complex.h"
7 #include "qdp-lapack_eigbicg.h"
8 #include "qdp-lapack_IncrEigbicg.h"
21 namespace LinOpSysSolverOptEigBiCGEnv
26 Handle<
FermState< LatticeFermion, multi1d<LatticeColorMatrix>, multi1d<LatticeColorMatrix> > >
state,
71 Handle< LinearOperator<T> >
LinOp;
75 template<
typename R,
typename T, PlusMinus isign>
76 void MatrixMatvec(
void *
x,
void *
y,
void *
params){
78 MatVecArg<T> &arg = *((MatVecArg<T> *)
params) ;
81 RComplex<R> *px = (RComplex<R> *)
x;
82 RComplex<R> *py = (RComplex<R> *)
y;
85 LinAlg::CopyToLatFerm<T,R>(arg.XX,px,arg.LinOp->subset());
86 (*arg.LinOp)(arg.YY,arg.XX,
isign) ;
89 LinAlg::CopyFromLatFerm<T,R>(py,arg.YY,arg.LinOp->subset());
93 void IncrEigBiCG(
int n,
int lde,
int nrhs, Complex_C* X, Complex_C* B,
94 int* ncurEvals,
int ldh, Complex_C* evecsl,
95 Complex_C* evecsr, Complex_C* evals,
96 Complex_C* H,
void (*matvec) (
void*,
void*,
void*),
97 void (*mathvec)(
void*,
void*,
void*),
void*
params,
98 float* AnormEst, Complex_C* work, Complex_C* VL,
99 int ldvl,Complex_C* VR,
int ldvr,
100 Complex_C* ework,
int esize,
float tol,
float* restartTol,
101 int maxit,
char SRT_OPT,
float epsi,
int ConvTestOpt,
102 int plvl,
int nev,
int v_max,FILE* outputFile){
103 QDPIO::cout<<
"IncrEigbicg_C will be called"<<std::endl ;
104 return IncrEigbicg_C(
n, lde, nrhs, X, B,
106 evecsl, evecsr, evals, H,
112 maxit, SRT_OPT, epsi,
118 void IncrEigBiCG(
int n,
int lde,
int nrhs, Complex_Z* X, Complex_Z* B,
119 int* ncurEvals,
int ldh, Complex_Z* evecsl,
120 Complex_Z* evecsr, Complex_Z* evals,
121 Complex_Z* H,
void (*matvec) (
void*,
void*,
void*),
122 void (*mathvec)(
void*,
void*,
void*),
void*
params,
123 double *AnormEst, Complex_Z* work, Complex_Z* VL,
124 int ldvl, Complex_Z* VR,
int ldvr, Complex_Z* ework,
125 int esize,
double tol,
double* restartTol,
126 int maxit,
char SRT_OPT,
double epsi,
int ConvTestOpt,
127 int plvl,
int nev,
int v_max,FILE *outputFile){
128 QDPIO::cout<<
"IncrEigbicg_Z will be called"<<std::endl ;
129 return IncrEigbicg_Z(
n, lde, nrhs, X, B,
131 evecsl, evecsr, evals, H,
137 maxit, SRT_OPT, epsi,
149 template<
typename T,
typename F,
typename C>
150 SystemSolverResults_t sysSolver(
T&
psi,
const T&
chi,
151 Handle< LinearOperator<T> >
A,
152 const SysSolverOptEigBiCGParams& invParam)
156 SystemSolverResults_t res;
158 LinAlg::OptEigBiInfo<REAL>& EigBiInfo =
TheNamedObjMap::Instance().getData< LinAlg::OptEigBiInfo<REAL> >(invParam.eigen_id);
160 QDPIO::cout<<
"EigBiInfo.N= "<<EigBiInfo.N<<std::endl ;
161 QDPIO::cout<<
"EigBiInfo.lde= "<<EigBiInfo.lde<<std::endl ;
162 QDPIO::cout<<
"EigBiInfo.ldh= "<<EigBiInfo.evals.size()<<std::endl ;
163 QDPIO::cout<<
"EigBiInfo.ncurEvals= "<<EigBiInfo.ncurEvals<<std::endl ;
164 QDPIO::cout<<
"EigBiInfo.restartTol= "<<EigBiInfo.restartTol<<std::endl ;
166 Subset
s =
A->subset() ;
186 if(
s.hasOrderedRep()){
187 X = (
C *) &
psi.elem(
s.start()).elem(0).elem(0).real();
188 B = (
C *) &
chi.elem(
s.start()).elem(0).elem(0).real();
193 QDPIO::cout<<
"OPPS! I have not implemented OPT_EigBiCG for Linops with non contigius subset\n";
197 C *evecsL = (
C *) &EigBiInfo.evecsL[0] ;
198 C *evecsR = (
C *) &EigBiInfo.evecsR[0] ;
199 C *evals = (
C *) &EigBiInfo.evals[0] ;
200 C *H = (
C *) &EigBiInfo.H[0] ;
203 int esize = invParam.esize*Layout::sitesOnNode()*Nc*Ns ;
205 QDPIO::cout<<
"OPT_EIGBICG_SYSSOLVER= "<<esize<<std::endl ;
207 F resid = (
F) invParam.RsdCG.elem().elem().elem().elem();
208 F AnormEst = invParam.NormAest.elem().elem().elem().elem();
211 if (EigBiInfo.ncurEvals < EigBiInfo.evals.size())
215 restartTol = invParam.restartTol.elem().elem().elem().elem();
219 F epsi = invParam.epsi.elem().elem().elem().elem() ;
221 IncrEigBiCG(EigBiInfo.N, EigBiInfo.lde, 1, X, B,
222 &EigBiInfo.ncurEvals, EigBiInfo.evals.size(),
223 evecsL, evecsR, evals, H,
224 MatrixMatvec<F,T,PLUS>,
225 MatrixMatvec<F,T,MINUS> ,
229 VL, EigBiInfo.lde, VR, EigBiInfo.lde,
233 invParam.sort_option.c_str()[0],
235 invParam.ConvTestOpt,
237 invParam.Neig, invParam.Nmax, stdout);
245 QDPIO::cout<<
"OPT_EIGBiCG_SYSSOLVER: True residual after solution : "<<sqrt(norm2(tt-
chi,
s))<<std::endl ;
246 QDPIO::cout<<
"OPT_EIGBiCG_SYSSOLVER: norm of solution : "<<sqrt(norm2(
psi,
s))<<std::endl ;
247 QDPIO::cout<<
"OPT_EIGBiCG_SYSSOLVER: norm of rhs : "<<sqrt(norm2(
chi,
s))<<std::endl ;
251 if(!
s.hasOrderedRep()){
252 QDPIO::cout<<
"OPPS! I have no implemented OPT_EigBiCG for Linops with non contigius subset\n";
268 SystemSolverResults_t
271 return sysSolver<LatticeFermionF,float,Complex_C>(
psi,
chi,
A, invParam);
279 return sysSolver<LatticeFermionD, double, Complex_Z>(
psi,
chi,
A, invParam);
291 return sysSolver(
psi,
chi,
A, invParam);
296 SystemSolverResults_t
299 return sysSolver(
psi,
chi,
A, invParam);
Support class for fermion actions and linear operators.
Class for counted reference semantics.
Solve a M*psi=chi linear system by biCG with eigenvectors.
SystemSolverResults_t operator()(T &psi, const T &chi) const
Solver the linear system.
SpinMatrix C()
C = Gamma(10)
LinOpSystemSolver< LatticeStaggeredFermion > * createStagFerm(XMLReader &xml_in, const std::string &path, Handle< LinearOperator< LatticeStaggeredFermion > > A)
Callback function.
bool registerAll()
Register all the factories.
LinOpSystemSolver< LatticeFermion > * createFerm(XMLReader &xml_in, const std::string &path, Handle< FermState< LatticeFermion, multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > > state, Handle< LinearOperator< LatticeFermion > > A)
Callback function.
const std::string name("EIG_BiCG_INVERTER")
Name to be used.
static bool registered
Local registration flag.
Asqtad Staggered-Dirac operator.
multi1d< LatticeFermion > chi(Ncb)
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
multi1d< LatticeFermion > s(Ncb)
Params for EigBiCG inverter.
Holds return info from SystemSolver call.
Handle< LinearOperator< T > > LinOp
Solve a M*psi=chi linear system by EigBiCG.
Register linop system solvers that solve M*psi=chi.
Factory for solving M*psi=chi where M is not hermitian or pos. def.
static INTERNAL_PRECISION F