19 #include "CG_EigenVector.h"    22 #include "wrapperMPI.h"    39   long unsigned int u_long_i;
    44   int i_itr,itr,iv,itr_max;
    46   double bnorm,xnorm,rnorm,rnorm2;
    47   double complex 
alpha,
beta,xb,rp,yp,gosa1,tmp_r,gosa2;
    52   i_max=
X->Check.idim_max;
    53   Eig=
X->Phys.Target_CG_energy;
    60   L_size=
sizeof(
double complex)*(i_max+1);
    62   b=(
double complex *)malloc(L_size);
    63   y=(
double complex *)malloc(L_size);
    66     fprintf(fp_0,
"BAD in CG_EigenVector  \n");
    68     fprintf(fp_0,
"allocate succeed !!! \n");
    76   iv = 
X->Def.initial_iv;
    78 #pragma omp parallel default(none) private(i, u_long_i, mythread, dsfmt) \    79   shared(v0, v1, iv, X, nthreads, myrank, b, bnorm) firstprivate(i_max)    85     mythread = omp_get_thread_num();
    90     dsfmt_init_gen_rand(&dsfmt, u_long_i);
    93     for (i = 1; i <= i_max; i++) {
    98 #pragma omp for reduction(+:bnorm)    99     for (i = 1; i <= i_max; i++) {
   100       b[i] += 2.0*(dsfmt_genrand_close_open(&dsfmt) - 0.5)*0.001;
   101       bnorm += conj(b[i])*b[i];
   110 #pragma omp parallel for default(none) private(i) shared(b) firstprivate(i_max,bnorm)   111   for(i=1;i<=i_max;i++){
   116   for(i_itr=0;i_itr<=50;i_itr++){
   120 #pragma omp parallel for reduction(+:bnorm) default(none) private(i) shared(b, v1, vg, v0) firstprivate(i_max)   121     for(i=1;i<=i_max;i++){
   122       bnorm+=conj(b[i])*b[i];
   130       fprintf(fp_0,
"b[%d]=%lf bnorm== %lf \n ",iv,creal(b[iv]),bnorm);
   140     for(itr=1;itr<=itr_max;itr++){
   141 #pragma omp parallel for default(none) private(j) shared(y, vg) firstprivate(i_max, Eig,eps_CG)   142       for(j=1;j<=i_max;j++){  
   151 #pragma omp parallel for reduction(+:rp, yp) default(none) private(i) shared(v1, vg, y) firstprivate(i_max)    152       for(i=1;i<=i_max;i++){
   153         rp+=
v1[i]*conj(
v1[i]);
   154         yp+=y[i]*conj(
vg[i]);
   160 #pragma omp parallel for reduction(+:rnorm) default(none) private(i) shared(v0, v1, vg)firstprivate(i_max, alpha)    161       for(i=1;i<=i_max;i++){
   163         rnorm+=conj(
v1[i])*
v1[i];
   168 #pragma omp parallel for reduction(+:rnorm2, gosa1) default(none) private(i) shared(v1 , y) firstprivate(i_max, alpha) private(tmp_r)    169       for(i=1;i<=i_max;i++){
   171         gosa1+=conj(tmp_r)*
v1[i];
   173         rnorm2+=conj(
v1[i])*
v1[i];
   179 #pragma omp parallel for reduction(+:gosa2) default(none) private(i) shared(v1, vg) firstprivate(i_max)    180       for(i=1;i<=i_max;i++){
   181         gosa2+=
v1[i]*conj(
vg[i]); 
   186 #pragma omp parallel for default(none) shared(v1, vg) firstprivate(i_max, beta)   187       for(i=1;i<=i_max;i++){
   192       fprintf(fp_0,
"i_itr=%d itr=%d %.10lf %.10lf \n ",
   193               i_itr,itr,sqrt(rnorm2),pow(10,-5)*sqrt(bnorm));
   195       if(sqrt(rnorm2)<
eps*sqrt(bnorm)){
   198         fprintf(fp_0,
"CG OK:   t_itr=%d \n ",t_itr);
   206 #pragma omp parallel for reduction(+:xnorm) default(none) private(i) shared(v0) firstprivate(i_max)   207     for(i=1;i<=i_max;i++){
   208       xnorm+=conj(
v0[i])*
v0[i];
   213 #pragma omp parallel for default(none) shared(v0) firstprivate(i_max, xnorm)    214     for(i=1;i<=i_max;i++){
   219 #pragma omp parallel for default(none) reduction(+:xb) private(i) shared(v0, b) firstprivate(i_max)   220     for(i=1;i<=i_max;i++){
   221       xb+=conj(
v0[i])*b[i];
   228     fprintf(fp_0,
"i_itr=%d itr=%d time=%lf  fabs(fabs(xb)-1.0)=%.16lf\n"   229             ,i_itr,itr,difftime(mid,start),fabs(cabs(xb)-1.0));
   232     if(fabs(cabs(xb)-1.0)<
eps){
   234       fprintf(fp_0,
"number of iterations in inv1:i_itr=%d itr=%d t_itr=%d %lf\n ",
   235               i_itr,itr,t_itr,fabs(cabs(xb)-1.0));
   240 #pragma omp parallel for default(none) private(i) shared(b, v0) firstprivate(i_max)   241       for(i=1;i<=i_max;i++){
 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. 
const char * cLogCG_EigenVecEnd
void StopTimer(int n)
function for calculating elapse time [elapse time=StartTimer-StopTimer] 
double SumMPI_d(double norm)
MPI wrapper function to obtain sum of Double across processes. 
int childfopenMPI(const char *_cPathChild, const char *_cmode, FILE **_fp)
Only the root process open file in output/ directory. 
const char * cFileNameTimeEV_CG
int nthreads
Number of Threads, defined in InitializeMPI() 
int CG_EigenVector(struct BindStruct *X)
inversed power method with CG 
const char * cFileNameTimeKeep
const char * cCG_EigenVecStart
const char * cCG_EigenVecFinish
int myrank
Process ID, defined in InitializeMPI() 
const char * cLogCG_EigenVecStart
int TimeKeeper(struct BindStruct *X, const char *cFileName, const char *cTimeKeeper_Message, const char *cWriteType)
Functions for writing a time log. 
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()