From c8cafa77ca06a7f4c333a780cf543da8886928f3 Mon Sep 17 00:00:00 2001 From: Chulwoo Jung Date: Tue, 4 Apr 2017 15:18:12 -0400 Subject: [PATCH] Checking in the latest Lacnzos --- .../iterative/ImplicitlyRestartedLanczos.h | 255 ++++++++++++------ 1 file changed, 177 insertions(+), 78 deletions(-) diff --git a/lib/algorithms/iterative/ImplicitlyRestartedLanczos.h b/lib/algorithms/iterative/ImplicitlyRestartedLanczos.h index 233eb8f5..aa4dfd19 100644 --- a/lib/algorithms/iterative/ImplicitlyRestartedLanczos.h +++ b/lib/algorithms/iterative/ImplicitlyRestartedLanczos.h @@ -31,11 +31,16 @@ Author: paboyle #include //memset #ifdef USE_LAPACK +#ifdef USE_MKL +#include +#else void LAPACK_dstegr(char *jobz, char *range, int *n, double *d, double *e, double *vl, double *vu, int *il, int *iu, double *abstol, int *m, double *w, double *z, int *ldz, int *isuppz, double *work, int *lwork, int *iwork, int *liwork, int *info); +//#include +#endif #endif #include "DenseMatrix.h" #include "EigenSort.h" @@ -62,12 +67,13 @@ public: int Np; // Np -- Number of spare vecs in kryloc space int Nm; // Nm -- total number of vectors + + RealD OrthoTime; + RealD eresid; SortEigen _sort; -// GridCartesian &_fgrid; - LinearOperatorBase &_Linop; OperatorFunction &_poly; @@ -124,23 +130,23 @@ public: GridBase *grid = evec[0]._grid; Field w(grid); - std::cout << "RitzMatrix "<1 ) { if (abs(in) >1.0e-9 ) { - std::cout<<"oops"<& lmd, DenseVector& lme, int N1, @@ -262,7 +269,7 @@ public: const int size = Nm; // tevals.resize(size); // tevecs.resize(size); - int NN = N1; + LAPACK_INT NN = N1; double evals_tmp[NN]; double evec_tmp[NN][NN]; memset(evec_tmp[0],0,sizeof(double)*NN*NN); @@ -276,19 +283,19 @@ public: if (i==j) evals_tmp[i] = lmd[i]; if (j==(i-1)) EE[j] = lme[j]; } - int evals_found; - int lwork = ( (18*NN) > (1+4*NN+NN*NN)? (18*NN):(1+4*NN+NN*NN)) ; - int liwork = 3+NN*10 ; - int iwork[liwork]; + LAPACK_INT evals_found; + LAPACK_INT lwork = ( (18*NN) > (1+4*NN+NN*NN)? (18*NN):(1+4*NN+NN*NN)) ; + LAPACK_INT liwork = 3+NN*10 ; + LAPACK_INT iwork[liwork]; double work[lwork]; - int isuppz[2*NN]; + LAPACK_INT isuppz[2*NN]; char jobz = 'V'; // calculate evals & evecs char range = 'I'; // calculate all evals // char range = 'A'; // calculate all evals char uplo = 'U'; // refer to upper half of original matrix char compz = 'I'; // Compute eigenvectors of tridiagonal matrix int ifail[NN]; - int info; + long long info; // int total = QMP_get_number_of_nodes(); // int node = QMP_get_node_number(); // GridBase *grid = evec[0]._grid; @@ -296,14 +303,18 @@ public: int node = grid->_processor; int interval = (NN/total)+1; double vl = 0.0, vu = 0.0; - int il = interval*node+1 , iu = interval*(node+1); + LAPACK_INT il = interval*node+1 , iu = interval*(node+1); if (iu > NN) iu=NN; double tol = 0.0; if (1) { memset(evals_tmp,0,sizeof(double)*NN); if ( il <= NN){ printf("total=%d node=%d il=%d iu=%d\n",total,node,il,iu); +#ifdef USE_MKL + dstegr(&jobz, &range, &NN, +#else LAPACK_dstegr(&jobz, &range, &NN, +#endif (double*)DD, (double*)EE, &vl, &vu, &il, &iu, // these four are ignored if second parameteris 'A' &tol, // tolerance @@ -335,6 +346,7 @@ public: lmd [NN-1-i]=evals_tmp[i]; } } +#undef LAPACK_INT #endif @@ -365,12 +377,14 @@ public: // diagonalize_lapack(lmd2,lme2,Nm2,Nm,Qt,grid); #endif - int Niter = 100*N1; + int Niter = 10000*N1; int kmin = 1; int kmax = N2; // (this should be more sophisticated) - for(int iter=0; iterSMALL) std::cout <<"lmd(qr) lmd(lapack) "<< k << ": " << lmd2[k] <<" "<< lmd3[k] <SMALL) std::cout <<"lme(qr)-lme(lapack) "<< k << ": " << lme2[k] - lme[k] <SMALL) std::cout<SMALL) std::cout<SMALL) std::cout <<"Qt(qr)-Qt(lapack) "<< k << ": " << Qt2[k] - Qt[k] <SMALL) std::cout<& evec, int k) { + double t0=-usecond()/1e6; typedef typename Field::scalar_type MyComplex; MyComplex ip; @@ -453,6 +468,8 @@ public: w = w - ip * evec[j]; } normalise(w); + t0+=usecond()/1e6; + OrthoTime +=t0; } void setUnit_Qt(int Nm, DenseVector &Qt) { @@ -486,10 +503,10 @@ until convergence GridBase *grid = evec[0]._grid; assert(grid == src._grid); - std::cout << " -- Nk = " << Nk << " Np = "<< Np << std::endl; - std::cout << " -- Nm = " << Nm << std::endl; - std::cout << " -- size of eval = " << eval.size() << std::endl; - std::cout << " -- size of evec = " << evec.size() << std::endl; + std::cout<oSites();ss++){ + for(int jj=k1-1; jjoSites();ss++){ + for(int jj=0; jj=Nstop ){ goto converged; } } // end of iter loop - std::cout<<"\n NOT converged.\n"; + std::cout< 1) std::cout << "orthagonality refined " << re << " times" < 1) std::cout< &evals, DenseVector > &evecs, DenseVector &bq, Field &bf, int cont) { - std::cout << "ImplicitRestart begin. Eigensort starting\n"; + std::cout< H; Resize(H,Nm,Nm); +#ifndef USE_LAPACK EigenSort(evals, evecs); +#endif ///Assign shifts int K=Nk; @@ -829,15 +924,15 @@ until convergence /// Shifted H defines a new K step Arnoldi factorization RealD beta = H[ff][ff-1]; RealD sig = Q[TM - 1][ff - 1]; - std::cout << "beta = " << beta << " sig = " << real(sig) < q Q times_real(bq, Q, TM); - std::cout << norm2(bq[0]) << " -- after " << ff < " << it << std::endl; + std::cout< " << it << std::endl; int lock_num = lock ? converged : 0; DenseVector tevals(M - lock_num ); DenseMatrix tevecs; Resize(tevecs,M - lock_num,M - lock_num); @@ -886,7 +981,7 @@ until convergence Wilkinson(H, evals, evecs, small); // Check(); - std::cout << "Done "< &tevals, DenseVector > &tevecs, int lock, int converged) { - std::cout << "Converged " << converged << " so far." << std::endl; + std::cout<(AH, tevals, tevecs, small); +#ifndef USE_LAPACK EigenSort(tevals, tevecs); +#endif RealD resid_nrm= norm2(bf); @@ -977,7 +1074,7 @@ until convergence RealD diff = 0; diff = abs( tevecs[i][Nm - 1 - lock_num] ) * resid_nrm; - std::cout << "residual estimate " << SS-1-i << " " << diff << " of (" << tevals[i] << ")" << std::endl; + std::cout< goodval(this->get); +#ifndef USE_LAPACK EigenSort(evals,evecs); +#endif int NM = Nm; @@ -1080,10 +1179,10 @@ say con = 2 **/ template -static void Lock(DenseMatrix &H, // Hess mtx - DenseMatrix &Q, // Lock Transform - T val, // value to be locked - int con, // number already locked +static void Lock(DenseMatrix &H, ///Hess mtx + DenseMatrix &Q, ///Lock Transform + T val, ///value to be locked + int con, ///number already locked RealD small, int dfg, bool herm)