54 printfQuda(
"Deflation space setup completed\n");
56 if (
param.eig_global.run_verify &&
param.eig_global.import_vectors)
verify();
64 if (r_sloppy)
delete r_sloppy;
65 if (Av_sloppy)
delete Av_sloppy;
86 const int n_evs_to_print = param.
cur_dim;
87 if (n_evs_to_print == 0)
errorQuda(
"Incorrect size of current deflation space");
89 std::unique_ptr<
Complex, decltype(pinned_deleter) > projm( pinned_allocator(param.
ld*param.
cur_dim *
sizeof(
Complex)), pinned_deleter);
94 std::unique_ptr<double[] > evals(
new double[param.
ld]);
103 SelfAdjointEigenSolver<MatrixXcd> es_projm( projm_ );
104 evecs_.block(0, 0, param.
cur_dim, param.
cur_dim) = es_projm.eigenvectors();
110 std::vector<ColorSpinorField*> res;
113 for (
int i = 0; i < n_evs_to_print; i++) {
119 double eval = dotnorm.x / dotnorm.z;
121 double relerr =
sqrt(
norm2(*r_sloppy) / dotnorm.z);
122 printfQuda(
"Eigenvalue %d: %1.12e Residual: %1.12e\n", i + 1, eval, relerr);
134 std::unique_ptr<Complex[] > vec(
new Complex[param.
ld]);
136 double check_nrm2 =
norm2(b);
138 printfQuda(
"\nSource norm (gpu): %1.15e, curr deflation space dim = %d\n",
sqrt(check_nrm2), param.
cur_dim);
144 std::vector<ColorSpinorField*> in_;
154 errorQuda(
"MAGMA library was not built");
159 Map<VectorXcd, Unaligned> vec_(vec.get(), param.
cur_dim);
161 VectorXcd vec2_(param.
cur_dim);
162 vec2_ = projm_.fullPivHouseholderQr().solve(vec_);
171 std::vector<ColorSpinorField*> out_;
176 check_nrm2 =
norm2(x);
177 printfQuda(
"\nDeflated guess spinor norm (gpu): %1.15e\n",
sqrt(check_nrm2));
186 if (
n_ev == 0)
return;
188 const int first_idx = param.
cur_dim;
191 warningQuda(
"\nNot enough space to add %d vectors. Keep deflation space unchanged.\n",
n_ev);
197 printfQuda(
"\nConstruct projection matrix..\n");
201 const int cdot_pipeline_length = 4;
203 for (
int i = first_idx; i < (first_idx +
n_ev); i++) {
204 std::unique_ptr<Complex[]> alpha(
new Complex[i]);
211 const int local_length = (i - offset) > cdot_pipeline_length ? cdot_pipeline_length : (i - offset);
213 std::vector<ColorSpinorField *> vj_(param.
RV->
Components().begin() + offset,
214 param.
RV->
Components().begin() + offset + local_length);
215 std::vector<ColorSpinorField *> vi_;
216 vi_.push_back(accum);
219 for (
int j = 0; j < local_length; j++) alpha[j] = -alpha[j];
222 offset += cdot_pipeline_length;
227 if (alpha[0].real() > 1e-16)
230 errorQuda(
"Cannot orthogonalize %dth vector", i);
241 std::vector<ColorSpinorField *> av_;
242 av_.push_back(Av_sloppy);
246 for (
int j = 0; j < i; j++) {
247 param.
matProj[i * param.
ld + j] = alpha[j];
260 if (param.
cur_dim < max_n_ev) {
261 printf(
"\nToo big number of eigenvectors was requested, switched to maximum available number %d\n", param.
cur_dim);
265 std::unique_ptr<double[]> evals(
new double[param.
cur_dim]);
266 std::unique_ptr<
Complex, decltype(pinned_deleter)> projm(
267 pinned_allocator(param.
ld * param.
cur_dim *
sizeof(
Complex)), pinned_deleter);
275 errorQuda(
"MAGMA library was not built");
278 Map<MatrixXcd, Unaligned, DynamicStride> projm_(projm.get(), param.
cur_dim, param.
cur_dim,
280 Map<VectorXd, Unaligned> evals_(evals.get(), param.
cur_dim);
281 SelfAdjointEigenSolver<MatrixXcd> es(projm_);
282 projm_ = es.eigenvectors();
283 evals_ = es.eigenvalues();
290 for (
int i = 0; i < param.
cur_dim; i++) {
291 if (fabs(evals[i]) > 1e-16) {
303 csParam.composite_dim = max_n_ev;
310 bool do_residual_check = (
tol != 0.0);
312 while ((relerr <
tol) && (idx < max_n_ev)) {
314 std::vector<ColorSpinorField *> res;
321 if (do_residual_check) {
325 double eval = dotnorm.x / dotnorm.z;
327 relerr =
sqrt(
norm2(*r_sloppy) / dotnorm.z);
334 printfQuda(
"\nReserved eigenvectors: %d\n", idx);
352 std::vector<ColorSpinorField *> &B = RV->
Components();
354 const int Nvec = B.size();
355 printfQuda(
"Start loading %d vectors from %s\n", Nvec, vec_infile.c_str());
357 void **
V =
new void*[Nvec];
358 for (
int i = 0; i < Nvec; i++) {
365 if (strcmp(vec_infile.c_str(),
"")!=0) {
368 B[0]->Ncolor(), B[0]->Nspin(), Nvec, 0, (
char **)0);
386 std::vector<ColorSpinorField*> &B = RV->
Components();
389 const int Nvec = B.size();
390 printfQuda(
"Start saving %d vectors to %s\n", Nvec, vec_outfile.c_str());
392 void **
V =
static_cast<void**
>(
safe_malloc(Nvec*
sizeof(
void*)));
393 for (
int i=0; i<Nvec; i++) {
403 B[0]->Ncolor(), B[0]->Nspin(), Nvec, 0, (
char **)0);
void magma_Xgesv(void *sol, const int ldn, const int n, void *Mat, const int ldm, const int prec)
void magma_Xheev(void *Mat, const int n, const int ldm, void *evalues, const int prec)
CompositeColorSpinorField & Components()
static ColorSpinorField * Create(const ColorSpinorParam ¶m)
ColorSpinorField & Component(const int idx) const
void operator()(ColorSpinorField &out, ColorSpinorField &in)
Deflation(DeflationParam ¶m, TimeProfile &profile)
void increment(ColorSpinorField &V, int n_ev)
void saveVectors(ColorSpinorField *RV)
Save the eigen space vectors in file.
double flops() const
Return the total flops done on this and all coarser levels.
void reduce(double tol, int max_n_ev)
void loadVectors(ColorSpinorField *RV)
Load the eigen space vectors from file.
QudaPrecision Precision() const
@ QUDA_INC_EIGCG_INVERTER
#define pool_pinned_malloc(size)
#define safe_malloc(size)
#define pool_pinned_free(ptr)
void xpay(ColorSpinorField &x, double a, ColorSpinorField &y)
void ax(double a, ColorSpinorField &x)
void zero(ColorSpinorField &a)
double norm2(const ColorSpinorField &a)
double3 cDotProductNormA(ColorSpinorField &a, ColorSpinorField &b)
void caxpy(const Complex &a, ColorSpinorField &x, ColorSpinorField &y)
void copy(ColorSpinorField &dst, const ColorSpinorField &src)
Complex cDotProduct(ColorSpinorField &, ColorSpinorField &)
__host__ __device__ ValueType conj(ValueType x)
double norm2(const CloverField &a, bool inverse=false)
__device__ __host__ void zero(double &a)
std::complex< double > Complex
__host__ __device__ ValueType sqrt(ValueType x)
Stride< Dynamic, Dynamic > DynamicStride
void read_spinor_field(const char *filename, void *V[], QudaPrecision precision, const int *X, QudaSiteSubset subset, QudaParity parity, int nColor, int nSpin, int Nvec, int argc, char *argv[])
void write_spinor_field(const char *filename, void *V[], QudaPrecision precision, const int *X, QudaSiteSubset subset, QudaParity parity, int nColor, int nSpin, int Nvec, int argc, char *argv[])
QudaPrecision cuda_prec_ritz
QudaExtLibType extlib_type
QudaInvertParam * invert_param
QudaFieldLocation location
QudaInverterType inv_type
QudaEigParam & eig_global
DiracMatrix & matDeflation
QudaVerbosity getVerbosity()