21 #include "CalcSpectrumByLanczos.h" 22 #include "Lanczos_EigenValue.h" 24 #include "wrapperMPI.h" 25 #include "common/setmemory.h" 26 #include "komega/komega.h" 41 double complex *dcSpectrum,
42 double complex *dcomega
47 int one = 1, status[3], idim_max2int, max_step, iter_old;
48 unsigned long int idx;
49 double complex *alphaCG, *betaCG, *res_save, z_seed;
50 double z_seed_r, z_seed_i, alpha_r, alpha_i, beta_r, beta_i, res_r, res_i;
55 comm = MPI_Comm_c2f(MPI_COMM_WORLD);
66 fprintf(
stdoutMPI,
"INFO: File for the restart is not found.\n");
67 fprintf(
stdoutMPI,
" Start from SCRATCH.\n");
69 komega_bicg_init(&idim_max2int, &one, &Nomega, dcSpectrum, dcomega, &max_step, &
eps_Lanczos, &comm);
72 fgetsMPI(ctmp,
sizeof(ctmp) /
sizeof(
char), fp);
73 sscanf(ctmp,
"%d", &iter_old);
75 alphaCG = (
double complex*)malloc((iter_old + X->
Bind.
Def.
Lanczos_max) *
sizeof(
double complex));
76 betaCG = (
double complex*)malloc((iter_old + X->
Bind.
Def.
Lanczos_max) *
sizeof(
double complex));
77 res_save = (
double complex*)malloc((iter_old + X->
Bind.
Def.
Lanczos_max) *
sizeof(
double complex));
80 alphaCG = (
double complex*)malloc(iter_old *
sizeof(
double complex));
81 betaCG = (
double complex*)malloc(iter_old *
sizeof(
double complex));
82 res_save = (
double complex*)malloc(iter_old *
sizeof(
double complex));
84 fgetsMPI(ctmp,
sizeof(ctmp) /
sizeof(
char), fp);
85 sscanf(ctmp,
"%lf %lf\n", &z_seed_r, &z_seed_i);
86 z_seed = z_seed_r + I * z_seed_i;
89 while (
fgetsMPI(ctmp,
sizeof(ctmp) /
sizeof(
char), fp) != NULL) {
90 sscanf(ctmp,
"%lf %lf %lf %lf %lf %lf\n",
91 &alpha_r, &alpha_i, &beta_r, &beta_i, &res_r, &res_i);
92 alphaCG[idx] = alpha_r + I * alpha_i;
93 betaCG[idx] = beta_r + I * beta_i;
94 res_save[idx] = res_r + I * res_i;
102 komega_bicg_restart(&idim_max2int, &one, &Nomega, dcSpectrum, dcomega, &max_step, &
eps_Lanczos, status,
103 &iter_old, &v2[1], &v12[1], &v4[1], &v14[1], alphaCG, betaCG, &z_seed, res_save, &comm);
111 komega_bicg_init(&idim_max2int, &one, &Nomega, dcSpectrum, dcomega, &max_step, &
eps_Lanczos, &comm);
124 unsigned long int stp;
126 double complex *alphaCG, *betaCG, *res_save, z_seed;
128 alphaCG = (
double complex*)malloc(liLanczosStp *
sizeof(
double complex));
129 betaCG = (
double complex*)malloc(liLanczosStp *
sizeof(
double complex));
130 res_save = (
double complex*)malloc(liLanczosStp *
sizeof(
double complex));
132 komega_bicg_getcoef(alphaCG, betaCG, &z_seed, res_save);
136 fprintf(fp,
"%d \n", liLanczosStp);
137 fprintf(fp,
"%.10lf %.10lf\n", creal(z_seed), cimag(z_seed));
138 for (stp = 0; stp < liLanczosStp; stp++) {
139 fprintf(fp,
"%25.16le %25.16le %25.16le %25.16le %25.16le %25.16le\n",
140 creal(alphaCG[stp]), cimag(alphaCG[stp]),
141 creal(betaCG[stp]), cimag(betaCG[stp]),
142 creal(res_save[stp]), cimag(res_save[stp]));
165 long unsigned int u_long_i;
169 #pragma omp parallel default(none) private(idim, u_long_i, mythread, dsfmt) \ 170 shared(v4, iv, X, nthreads, myrank) 176 mythread = omp_get_thread_num();
181 dsfmt_init_gen_rand(&dsfmt, u_long_i);
185 v4[idim] = 2.0*(dsfmt_genrand_close_open(&dsfmt) - 0.5)
186 + 2.0*(dsfmt_genrand_close_open(&dsfmt) - 0.5)*I;
190 #pragma omp parallel for default(none) shared(X,v4,dnorm) private(idim) 191 for (idim = 1; idim <= X->
Check.
idim_max; idim++) v4[idim] /= dnorm;
208 double complex *vrhs,
212 double complex *dcSpectrum,
213 double complex *dcomega
217 unsigned long int idim, i_max;
221 unsigned long int liLanczosStp_vec = 0;
222 double complex *v12, *v14, res_proj;
223 int stp, one = 1, status[3], iomega;
226 fprintf(
stdoutMPI,
"##### Spectrum calculation with BiCG #####\n\n");
232 v12 = (
double complex*)malloc((X->
Bind.
Check.
idim_max + 1) *
sizeof(
double complex));
233 v14 = (
double complex*)malloc((X->
Bind.
Check.
idim_max + 1) *
sizeof(
double complex));
234 resz = (
double*)malloc(Nomega *
sizeof(
double));
241 fprintf(
stdoutMPI,
" Start: Input vectors for recalculation.\n");
246 fprintf(
stdoutMPI,
"INFO: File for the restart is not found.\n");
247 fprintf(
stdoutMPI,
" Start from SCRATCH.\n");
248 #pragma omp parallel for default(none) shared(v2,v4,vrhs,X) private(idim) 250 v2[idim] = vrhs[idim];
251 v4[idim] = vrhs[idim];
256 byte_size = fread(&liLanczosStp_vec,
sizeof(
int), 1, fp);
257 byte_size = fread(&i_max,
sizeof(i_max), 1, fp);
259 fprintf(stderr,
"Error: The size of the input vector is incorrect.\n");
260 printf(
"%s %ld %ld %ld\n", sdt, i_max, X->
Bind.
Check.
idim_max, liLanczosStp_vec);
268 fprintf(
stdoutMPI,
" End: Input vectors for recalculation.\n");
270 if (byte_size == 0) printf(
"byte_size : %d\n", (
int)byte_size);
274 #pragma omp parallel for default(none) shared(v2,v4,vrhs,X) private(idim) 276 v2[idim] = vrhs[idim];
277 v4[idim] = vrhs[idim];
289 fprintf(
stdoutMPI,
" Start: Calculate tridiagonal matrix components.\n");
291 fprintf(
stdoutMPI,
"\n Iteration Status Seed Residual-2-Norm\n");
299 #pragma omp parallel for default(none) shared(X,v12,v14) private(idim) 312 komega_bicg_update(&v12[1], &v2[1], &v14[1], &v4[1], dcSpectrum, &res_proj, status);
318 komega_bicg_getresidual(resz);
320 for (iomega = 0; iomega < Nomega; iomega++) {
321 fprintf(fp,
"%7i %20.10e %20.10e %20.10e %20.10e\n",
322 stp, creal(dcomega[iomega]),
323 creal(dcSpectrum[iomega]), cimag(dcSpectrum[iomega]),
329 fprintf(
stdoutMPI,
" %9d %9d %8d %25.15e\n", abs(status[0]), status[1], status[2], creal(v12[1]));
330 if (status[0] < 0)
break;
337 fprintf(
stdoutMPI,
" End: Calculate tridiagonal matrix components.\n\n");
350 fprintf(
stdoutMPI,
" Start: Output vectors for recalculation.\n");
353 komega_bicg_getvec(&v12[1], &v14[1]);
359 byte_size = fwrite(&status[0],
sizeof(status[0]), 1, fp);
367 fprintf(
stdoutMPI,
" End: Output vectors for recalculation.\n");
371 komega_bicg_finalize();
int childfopenALL(const char *_cPathChild, const char *_cmode, FILE **_fp)
All processes open file in output/ directory.
void exitMPI(int errorcode)
MPI Abortation wrapper.
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...
int OutputTMComponents_BiCG(struct EDMainCalStruct *X, int liLanczosStp)
write , projected residual for restart
unsigned long int idim_max
The dimension of the Hilbert space of this process.
void InitShadowRes(struct BindStruct *X, double complex *v4)
Initialize Shadow Residual as a random vector (Experimental)
int childfopenMPI(const char *_cPathChild, const char *_cmode, FILE **_fp)
Only the root process open file in output/ directory.
const char * cFileNameOutputRestartVec
int nthreads
Number of Threads, defined in InitializeMPI()
int CalcSpectrumByBiCG(struct EDMainCalStruct *X, double complex *vrhs, double complex *v2, double complex *v4, int Nomega, double complex *dcSpectrum, double complex *dcomega)
A main function to calculate spectrum by BiCG method In this function, the library is used...
void ReadTMComponents_BiCG(struct EDMainCalStruct *X, double complex *v2, double complex *v4, double complex *v12, double complex *v14, int Nomega, double complex *dcSpectrum, double complex *dcomega)
Read , projected residual for restart.
const char * c_OutputSpectrumRecalcvecEnd
const char * c_InputSpectrumRecalcvecStart
const char * cFileNameTridiagonalMatrixComponents
const char * c_GetTridiagonalStart
const char * cFileNameTimeKeep
const char * c_InputSpectrumRecalcvecEnd
double complex VecProdMPI(long unsigned int ndim, double complex *v1, double complex *v2)
Compute conjugate scaler product of process-distributed vector .
long int initial_iv
Seed of random number for initial guesss of wavefunctions.
int myrank
Process ID, defined in InitializeMPI()
int iFlgCalcSpec
Input parameter CalcSpec in teh CalcMod file.
const char * c_GetTridiagonalEnd
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...
const char * c_OutputSpectrumRecalcvecStart
struct CheckList Check
Size of the Hilbert space.
char * CDataFileHead
Read from Calcmod in readdef.h. Header of output file such as Green's function.
struct BindStruct Bind
Binded struct.
int TimeKeeper(struct BindStruct *X, const char *cFileName, const char *cTimeKeeper_Message, const char *cWriteType)
Functions for writing a time log.
unsigned int Lanczos_max
Maximum number of iterations.
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()