18 #include "common/setmemory.h" 23 #include "matrixlapack.h" 24 #include "Lanczos_EigenValue.h" 25 #include "wrapperMPI.h" 57 unsigned long int i_max_tmp;
61 double complex temp1, temp2;
62 double complex cbeta1;
63 double E[5], ebefor, E_target;
70 int int_i, int_j,
mfint[7];
76 unsigned long int liLanczosStp;
78 unsigned long int liLanczosStp_vec=0;
82 fprintf(
stdoutMPI,
" Error: Fail to read initial vectors\n");
87 fprintf(
stdoutMPI,
" Error: Fail to read TMcomponents\n");
90 if(liLanczosStp_vec !=liLanczosStp){
91 fprintf(
stdoutMPI,
" Error: Input files for vector and TMcomponents are incoorect.\n");
92 fprintf(
stdoutMPI,
" Error: Input vector %ld th stps, TMcomponents %ld th stps.\n", liLanczosStp_vec, liLanczosStp);
117 #pragma omp parallel for reduction(+:cbeta1) default(none) private(i) shared(v0, v1) firstprivate(i_max, alpha1) 118 for (i = 1; i <= i_max; i++) {
119 cbeta1 += conj(
v0[i] - alpha1 *
v1[i]) * (
v0[i] - alpha1 *
v1[i]);
122 beta1 = creal(cbeta1);
134 if (i_max_tmp < liLanczosStp) {
135 liLanczosStp = i_max_tmp;
137 if (i_max_tmp < X->Def.LanczosTarget) {
138 liLanczosStp = i_max_tmp;
140 if (i_max_tmp == 1) {
148 fprintf(
stdoutMPI,
" LanczosStep E[1] \n");
149 fprintf(
stdoutMPI,
" stp=%d %.10lf \n", stp, E[1]);
154 #pragma omp parallel for default(none) private(i,temp1, temp2) shared(v0, v1) firstprivate(i_max, alpha1, beta1) 155 for (i = 1; i <= i_max; i++) {
157 temp2 = (
v0[i] - alpha1 *
v1[i]) / beta1;
158 v0[i] = -beta1 * temp1;
170 #pragma omp parallel for reduction(+:cbeta1) default(none) private(i) shared(v0, v1) firstprivate(i_max, alpha1) 171 for (i = 1; i <= i_max; i++) {
172 cbeta1 += conj(
v0[i] - alpha1 *
v1[i]) * (
v0[i] - alpha1 *
v1[i]);
175 beta1 = creal(cbeta1);
182 tmp_mat = d_2d_allocate(stp,stp);
183 tmp_E = d_1d_allocate(stp+1);
185 for (int_i = 0; int_i < stp; int_i++) {
186 for (int_j = 0; int_j < stp; int_j++) {
187 tmp_mat[int_i][int_j] = 0.0;
190 tmp_mat[0][0] =
alpha[1];
191 tmp_mat[0][1] =
beta[1];
192 tmp_mat[1][0] =
beta[1];
193 tmp_mat[1][1] =
alpha[2];
198 E_target = tmp_E[Target];
201 free_d_1d_allocate(tmp_E);
202 free_d_2d_allocate(tmp_mat);
206 fprintf(fp,
"LanczosStep E[1] E[2] E[3] E[4] Target:E[%d] E_Max/Nsite\n", Target + 1);
208 fprintf(
stdoutMPI,
" stp = %d %.10lf %.10lf xxxxxxxxxx xxxxxxxxx %.10lf xxxxxxxxx \n", stp, E[1], E[2],
210 fprintf(fp,
"stp = %d %.10lf %.10lf xxxxxxxxxx xxxxxxxxx %.10lf xxxxxxxxx \n", stp, E[1], E[2], E_target);
212 fprintf(
stdoutMPI,
" stp = %d %.10lf %.10lf xxxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx \n", stp, E[1], E[2]);
213 fprintf(fp,
"stp = %d %.10lf %.10lf xxxxxxxxxx xxxxxxxxx xxxxxxxxx xxxxxxxxx \n", stp, E[1], E[2]);
222 tmp_mat = d_2d_allocate(stp,stp);
223 tmp_E = d_1d_allocate(stp+1);
225 for (int_i = 0; int_i < stp; int_i++) {
226 for (int_j = 0; int_j < stp; int_j++) {
227 tmp_mat[int_i][int_j] = 0.0;
230 tmp_mat[0][0] =
alpha[1];
231 tmp_mat[0][1] =
beta[1];
232 for (int_i = 1; int_i < stp - 1; int_i++) {
233 tmp_mat[int_i][int_i] =
alpha[int_i + 1];
234 tmp_mat[int_i][int_i + 1] =
beta[int_i + 1];
235 tmp_mat[int_i][int_i - 1] =
beta[int_i];
237 tmp_mat[int_i][int_i] =
alpha[int_i + 1];
238 tmp_mat[int_i][int_i - 1] =
beta[int_i];
246 E[0] = tmp_E[stp - 1];
248 E_target = tmp_E[Target];
250 free_d_1d_allocate(tmp_E);
251 free_d_2d_allocate(tmp_mat);
253 fprintf(
stdoutMPI,
" stp = %d %.10lf %.10lf %.10lf %.10lf %.10lf %.10lf\n", stp, E[1], E[2], E[3], E[4],
255 fprintf(fp,
"stp=%d %.10lf %.10lf %.10lf %.10lf %.10lf %.10lf\n", stp, E[1], E[2], E[3], E[4], E_target,
258 fprintf(
stdoutMPI,
" stp = %d %.10lf %.10lf %.10lf %.10lf xxxxxxxxx %.10lf\n", stp, E[1], E[2], E[3], E[4],
260 fprintf(fp,
"stp=%d %.10lf %.10lf %.10lf %.10lf xxxxxxxxx %.10lf\n", stp, E[1], E[2], E[3], E[4],
265 if (fabs((E_target - ebefor) / E_target) <
eps_Lanczos || fabs(
beta[stp]) < pow(10.0, -14)) {
271 tmp_E = d_1d_allocate(stp+1);
279 free_d_1d_allocate(tmp_E);
294 fprintf(
stdoutMPI,
"Lanczos Eigenvalue is not converged in this process (restart mode).\n");
302 fprintf(
stdoutMPI,
"Lanczos Eigenvalue is not converged in this process.\n");
328 double complex *tmp_v1,
329 unsigned long int *liLanczos_step
337 unsigned long int i_max_tmp;
338 double beta1, alpha1;
339 double complex temp1, temp2;
340 double complex cbeta1;
348 if (i_max_tmp < *liLanczos_step || i_max_tmp < X->Def.LanczosTarget) {
349 *liLanczos_step = i_max_tmp;
353 #pragma omp parallel for default(none) private(i) shared(v0, v1, tmp_v1) firstprivate(i_max) 354 for (i = 1; i <= i_max; i++) {
364 fprintf(
stdoutMPI,
" Step / Step_max alpha beta \n");
366 #pragma omp parallel for reduction(+:cbeta1) default(none) private(i) shared(v0, v1) firstprivate(i_max, alpha1) 367 for (i = 1; i <= i_max; i++) {
368 cbeta1 += conj(
v0[i] - alpha1 *
v1[i]) * (
v0[i] - alpha1 *
v1[i]);
371 beta1 = creal(cbeta1);
382 if (fabs(_beta[stp - 1]) < pow(10.0, -14)) {
383 *liLanczos_step = stp - 1;
387 #pragma omp parallel for default(none) private(i, temp1, temp2) shared(v0, v1) firstprivate(i_max, alpha1, beta1) 388 for (i = 1; i <= i_max; i++) {
390 temp2 = (
v0[i] - alpha1 *
v1[i]) / beta1;
391 v0[i] = -beta1 * temp1;
398 _alpha[stp] = alpha1;
401 #pragma omp parallel for reduction(+:cbeta1) default(none) private(i) shared(v0, v1) firstprivate(i_max, alpha1) 402 for (i = 1; i <= i_max; i++) {
403 cbeta1 += conj(
v0[i] - alpha1 *
v1[i]) * (
v0[i] - alpha1 *
v1[i]);
406 beta1 = creal(cbeta1);
410 fprintf(
stdoutMPI,
" stp = %d / %lu %.10lf %.10lf \n", stp, *liLanczos_step, alpha1, beta1);
433 unsigned long int i_max;
435 fprintf(
stdoutMPI,
" Start: Input vectors for recalculation.\n");
441 byte_size = fread(liLanczosStp_vec,
sizeof(*liLanczosStp_vec),1,fp);
442 byte_size = fread(&i_max,
sizeof(
long int), 1, fp);
444 fprintf(stderr,
"Error: A size of Inputvector is incorrect.\n");
447 byte_size = fread(_v0,
sizeof(complex
double), X->
Check.
idim_max + 1, fp);
448 byte_size = fread(_v1,
sizeof(complex
double), X->
Check.
idim_max + 1, fp);
450 fprintf(
stdoutMPI,
" End: Input vectors for recalculation.\n");
452 if (byte_size == 0) printf(
"byte_size: %d \n", (
int)byte_size);
467 double complex* tmp_v0,
468 double complex *tmp_v1,
469 unsigned long int liLanczosStp_vec){
473 fprintf(
stdoutMPI,
" Start: Output vectors for recalculation.\n");
480 fwrite(&liLanczosStp_vec,
sizeof(liLanczosStp_vec),1,fp);
482 fwrite(tmp_v0,
sizeof(complex
double),X->
Check.
idim_max+1, fp);
483 fwrite(tmp_v1,
sizeof(complex
double),X->
Check.
idim_max+1, fp);
486 fprintf(
stdoutMPI,
" End: Output vectors for recalculation.\n");
501 long int i, iv, i_max;
502 unsigned long int i_max_tmp, sum_i_max;
507 double complex cdnorm;
508 long unsigned int u_long_i;
521 fprintf(
stdoutMPI,
" initial_mode=%d normal: iv = %ld i_max=%ld k_exct =%d \n\n",
initial_mode, iv, i_max,
523 #pragma omp parallel for default(none) private(i) shared(tmp_v0, tmp_v1) firstprivate(i_max) 524 for (i = 1; i <= i_max; i++) {
531 for (iproc = 0; iproc <
nproc; iproc++) {
533 if (sum_i_max <= iv && iv < sum_i_max + i_max_tmp) {
535 tmp_v1[iv - sum_i_max + 1] = 1.0;
537 tmp_v1[iv - sum_i_max + 1] += 1.0 * I;
538 tmp_v1[iv - sum_i_max + 1] /= sqrt(2.0);
543 sum_i_max += i_max_tmp;
548 tmp_v1[iv + 1] = 1.0;
550 tmp_v1[iv + 1] += 1.0 * I;
551 tmp_v1[iv + 1] /= sqrt(2.0);
557 fprintf(
stdoutMPI,
" initial_mode=%d (random): iv = %ld i_max=%ld k_exct =%d \n\n",
initial_mode, iv, i_max,
559 #pragma omp parallel default(none) private(i, u_long_i, mythread, dsfmt) \ 560 shared(tmp_v0, tmp_v1, iv, X, nthreads, myrank) firstprivate(i_max) 564 for (i = 1; i <= i_max; i++) {
571 mythread = omp_get_thread_num();
579 u_long_i = 123432 + labs(iv)+ mythread ;
581 dsfmt_init_gen_rand(&dsfmt, u_long_i);
585 for (i = 1; i <= i_max; i++)
586 tmp_v1[i] = 2.0 * (dsfmt_genrand_close_open(&dsfmt) - 0.5) +
587 2.0 * (dsfmt_genrand_close_open(&dsfmt) - 0.5) * I;
590 for (i = 1; i <= i_max; i++)
591 tmp_v1[i] = 2.0 * (dsfmt_genrand_close_open(&dsfmt) - 0.5);
597 #pragma omp parallel for default(none) private(i) shared(tmp_v1, i_max) reduction(+: cdnorm) 598 for (i = 1; i <= i_max; i++) {
599 cdnorm += conj(tmp_v1[i]) * tmp_v1[i];
604 dnorm = creal(cdnorm);
606 #pragma omp parallel for default(none) private(i) shared(tmp_v1) firstprivate(i_max, dnorm) 607 for (i = 1; i <= i_max; i++) {
608 tmp_v1[i] = tmp_v1[i] / dnorm;
627 unsigned long int *_i_max,
633 unsigned long int idx, i, ivec;
634 unsigned long int i_max;
643 fgetsMPI(ctmp,
sizeof(ctmp)/
sizeof(
char), fp);
644 sscanf(ctmp,
"%ld \n", &i_max);
655 vec[0] = (complex
double *) realloc(
vec[0], ivec*(i_max + X->
Def.
Lanczos_max + 1) *
sizeof(complex double));
656 for (i = 0; i < ivec; i++) {
661 alpha=(
double*)realloc(
alpha,
sizeof(
double)*(i_max + 1));
662 beta=(
double*)realloc(
beta,
sizeof(
double)*(i_max + 1));
663 vec[0] = (complex
double *) realloc(
vec[0], ivec*(i_max + 1) *
sizeof(complex double));
664 for (i = 0; i < ivec; i++) {
665 vec[i] =
vec[0] + i*(i_max +1);
673 fgetsMPI(ctmp,
sizeof(ctmp)/
sizeof(
char), fp);
674 sscanf(ctmp,
"%lf \n", &dnorm);
675 while(
fgetsMPI(ctmp,
sizeof(ctmp)/
sizeof(
char), fp) != NULL){
676 sscanf(ctmp,
"%lf %lf \n", &
alpha[idx], &
beta[idx]);
713 fprintf(fp,
"%d \n",liLanczosStp);
714 fprintf(fp,
"%.10lf \n",_dnorm);
715 for( i = 1 ; i <= liLanczosStp; i++){
716 fprintf(fp,
"%.10lf %.10lf \n", _alpha[i], _beta[i]);
int childfopenALL(const char *_cPathChild, const char *_cmode, FILE **_fp)
All processes open file in output/ directory.
struct DefineList Def
Definision of system (Hamiltonian) etc.
int mltply(struct BindStruct *X, double complex *tmp_v0, double complex *tmp_v1)
Parent function of multiplying the wavefunction by the Hamiltonian. . First, the calculation of diago...
void StartTimer(int n)
function for initializing elapse time [start]
double complex SumMPI_dc(double complex norm)
MPI wrapper function to obtain sum of Double complex across processes.
unsigned long int idim_max
The dimension of the Hilbert space of this process.
const char * cLogLanczos_EigenValueNotConverged
double Target_CG_energy
Taget energy of CG-inversed iteration (NOT LOBCG) method.
unsigned long int BcastMPI_li(int root, unsigned long int idim)
MPI wrapper function to broadcast unsigned long integer across processes.
void SetInitialVector(struct BindStruct *X, double complex *tmp_v0, double complex *tmp_v1)
Set initial vector to start the calculation for Lanczos method. .
void StopTimer(int n)
function for calculating elapse time [elapse time=StartTimer-StopTimer]
double complex prdct
The expectation value of the energy.
struct LargeList Large
Variables for Matrix-Vector product.
int Lanczos_GetTridiagonalMatrixComponents(struct BindStruct *X, double *_alpha, double *_beta, double complex *tmp_v1, unsigned long int *liLanczos_step)
Calculate tridiagonal matrix components by Lanczos method.
int childfopenMPI(const char *_cPathChild, const char *_cmode, FILE **_fp)
Only the root process open file in output/ directory.
const char * c_Lanczos_SpectrumStep
const char * cLanczos_EigenValueFinish
struct PhysList Phys
Physical quantities.
const char * cFileNameOutputRestartVec
int DSEVvalue(int xNsize, double **A, double *r)
obtain eigenvalues of real symmetric A
const char * cFileNameLanczosStep
unsigned int nvec
Read from Calcmod in readdef.h.
int nthreads
Number of Threads, defined in InitializeMPI()
long int iv
Used for initializing vector.
int nproc
Number of processors, defined in InitializeMPI()
int OutputLanczosVector(struct BindStruct *X, double complex *tmp_v0, double complex *tmp_v1, unsigned long int liLanczosStp_vec)
Output initial vectors for the restart calculation.
const char * c_OutputSpectrumRecalcvecEnd
int Lanczos_restart
Number of iterations performed in the restart computation.
const char * c_InputSpectrumRecalcvecStart
const char * cLogLanczos_EigenValueStart
const char * cLogLanczos_EigenValueEnd
const char * cLanczos_EigenValueStart
const char * cFileNameTridiagonalMatrixComponents
static unsigned long int mfint[7]
int ReadInitialVector(struct BindStruct *X, double complex *_v0, double complex *_v1, unsigned long int *liLanczosStp_vec)
Read initial vectors for the restart calculation.
unsigned int NsiteMPI
Total number of sites, differ from DefineList::Nsite.
const char * cFileNameTimeKeep
const char * c_InputSpectrumRecalcvecEnd
void vec12(double alpha[], double beta[], unsigned int ndim, double tmp_E[], struct BindStruct *X)
Diagonalize a tri-diagonal matrix and store eigenvectors into vec.
int OutputTMComponents(struct BindStruct *X, double *_alpha, double *_beta, double _dnorm, int liLanczosStp)
Output tridiagonal matrix components obtained by the Lanczos method.
int Lanczos_EigenValue(struct BindStruct *X)
Main function for calculating eigen values by Lanczos method. The energy convergence is judged by the...
const char * cLanczos_EigenValueStep
int LanczosTarget
Which eigenstate is used to check convergence. Read from Calcmod in readdef.h.
long int initial_iv
Seed of random number for initial guesss of wavefunctions.
int myrank
Process ID, defined in InitializeMPI()
int iInitialVecType
Switch for type of inital vectors. 0:complex type, 1: real type. default value is set as 0 in readdef...
char * fgetsMPI(char *InputString, int maxcount, FILE *fp)
MPI file I/O (get a line, fgets) wrapper. Only the root node (myrank = 0) reads and broadcast string...
int ReadTMComponents(struct BindStruct *X, double *_dnorm, unsigned long int *_i_max, int iFlg)
Read tridiagonal matrix components obtained by the Lanczos method. .
const char * c_OutputSpectrumRecalcvecStart
struct CheckList Check
Size of the Hilbert space.
unsigned long int SumMPI_li(unsigned long int idim)
MPI wrapper function to obtain sum of unsigned long integer across processes.
char * CDataFileHead
Read from Calcmod in readdef.h. Header of output file such as Green's function.
int TimeKeeperWithStep(struct BindStruct *X, const char *cFileName, const char *cTimeKeeper_Message, const char *cWriteType, const int istep)
Functions for writing a time log.
int TimeKeeper(struct BindStruct *X, const char *cFileName, const char *cTimeKeeper_Message, const char *cWriteType)
Functions for writing a time log.
double Target_energy
Is it really used ???
unsigned int Lanczos_max
Maximum number of iterations.
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
unsigned int k_exct
Read from Calcmod in readdef.h.