HΦ  3.2.0
vec12.c
Go to the documentation of this file.
1 /* HPhi - Quantum Lattice Model Simulator */
2 /* Copyright (C) 2015 The University of Tokyo */
3 
4 /* This program is free software: you can redistribute it and/or modify */
5 /* it under the terms of the GNU General Public License as published by */
6 /* the Free Software Foundation, either version 3 of the License, or */
7 /* (at your option) any later version. */
8 
9 /* This program is distributed in the hope that it will be useful, */
10 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
11 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
12 /* GNU General Public License for more details. */
13 
14 /* You should have received a copy of the GNU General Public License */
15 /* along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "matrixlapack.h"
21 #include "Common.h"
22 #include "wrapperMPI.h"
23 #include "common/setmemory.h"
24 #include "xsetmem.h"
31 void vec12(
32  double alpha[],
33  double beta[],
34  unsigned int ndim,
35  double tmp_E[],
36  struct BindStruct *X
37 ) {
38  unsigned int j,k,nvec;
39 
40  double **tmpA, **tmpvec;
41  double *tmpr;
42 
43  nvec = X->Def.nvec;
44  tmpA = d_2d_allocate(ndim, ndim);
45  tmpvec = d_2d_allocate(ndim, ndim);
46  tmpr = d_1d_allocate(ndim);
47 
48 #pragma omp parallel for default(none) firstprivate(ndim) private(j,k) shared(tmpA)
49  for(k=0;k<=ndim-1;k++)
50  for(j=0;j<=ndim-1;j++) tmpA[k][j]=0.0;
51 #pragma omp parallel for default(none) firstprivate(ndim, nvec) private(j,k) shared(vec)
52  for(k=1;k<=nvec;k++)
53  for(j=1;j<=ndim;j++) vec[k][j]=0.0;
54 
55 #pragma omp parallel for default(none) firstprivate(ndim, alpha, beta) private(j) shared(tmpA)
56  for(j=0;j<=ndim-2;j++){
57  tmpA[j][j]=alpha[j+1];
58  tmpA[j][j+1]=beta[j+1];
59  tmpA[j+1][j]=beta[j+1];
60  }/*for(j=0;j<=ndim-2;j++)*/
61  tmpA[ndim-1][ndim-1]=alpha[ndim];
62 
63  DSEVvector( ndim, tmpA, tmpr, tmpvec );
64  if(X->Def.iCalcType==Lanczos && X->Def.iFlgCalcSpec == 0)
65  fprintf(stdoutMPI, " Lanczos EigenValue in vec12 = %.10lf \n ",tmpr[0]);
66 
67  if (nvec <= ndim) {
68  if (nvec < X->Def.LanczosTarget) nvec = X->Def.LanczosTarget;
69 
70 #pragma omp parallel for default(none) firstprivate(ndim, nvec) private(j,k) shared(tmpvec, vec, tmp_E, tmpr)
71  for(k=1;k<=nvec;k++){
72  tmp_E[k]=tmpr[k-1];
73  for (j = 1; j <= ndim; j++) vec[k][j] = tmpvec[k - 1][j - 1];
74  }/*for(k=1;k<=nvec;k++)*/
75  }/*if(nvec<=ndim)*/
76  else{
77 #pragma omp parallel for default(none) firstprivate(ndim, nvec) private(j,k) shared(tmpvec, vec, tmp_E, tmpr)
78  for(k=1;k<=ndim;k++){
79  tmp_E[k]=tmpr[k-1];
80  for (j = 1; j <= ndim; j++) vec[k][j] = tmpvec[k - 1][j - 1];
81  }/*for(k=1;k<=ndim;k++)*/
82  }/*if(nvec>ndim)*/
83  free_d_2d_allocate(tmpA);
84  free_d_1d_allocate(tmpr);
85  free_d_2d_allocate(tmpvec);
86 }/*void vec12*/
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.h:410
double complex ** vec
Definition: global.h:45
unsigned int nvec
Read from Calcmod in readdef.h.
Definition: struct.h:46
Bind.
Definition: struct.h:409
double * alpha
Definition: global.h:44
int DSEVvector(int xNsize, double **A, double *r, double **vec)
obtain eigenvalues and eigenvectors of real symmetric A
Definition: matrixlapack.c:209
double * beta
Definition: global.h:44
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.
Definition: vec12.c:31
struct EDMainCalStruct X
Definition: struct.h:432
int LanczosTarget
Which eigenstate is used to check convergence. Read from Calcmod in readdef.h.
Definition: struct.h:50
int iFlgCalcSpec
Input parameter CalcSpec in teh CalcMod file.
Definition: struct.h:216
int iCalcType
Switch for calculation type. 0:Lanczos, 1:TPQCalc, 2:FullDiag.
Definition: struct.h:192
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
Definition: global.h:165