HPhi++  3.1.0
lapack_diag.cpp File Reference
#include "lapack_diag.hpp"
#include "matrixlapack.hpp"
#include "FileIO.hpp"

Go to the source code of this file.

Functions

int lapack_diag (struct BindStruct *X)
 performing full diagonalization using lapack More...
 

Function Documentation

◆ lapack_diag()

int lapack_diag ( struct BindStruct X)

performing full diagonalization using lapack

Parameters
[in,out]X
Author
Takahiro Misawa (The University of Tokyo)
Kazuyoshi Yoshimi (The University of Tokyo)
Returns
Parameters
[in,out]X

Definition at line 35 of file lapack_diag.cpp.

References BindStruct::Check, childfopenMPI(), BindStruct::Def, PhysList::energy, CheckList::idim_max, DefineList::iNGPU, myrank, nproc, BindStruct::Phys, stdoutMPI, v0, v1, and ZHEEVall().

Referenced by CalcByFullDiag(), and CalcSpectrumByFullDiag().

37  {
38 
39  FILE *fp;
40  char sdt[D_FileNameMax] = "";
41  long int i, j, i_max, xMsize;
42 #ifdef _SCALAPACK
43  int rank, size, nprocs, nprow, npcol, myrow, mycol, ictxt;
44  int i_negone=-1, i_zero=0, iam;
45  long int mb, nb, mp, nq;
46  int dims[2]={0,0};
47 #endif
48 
49  i_max = X->Check.idim_max;
50 
51  for (i = 0; i < i_max; i++) {
52  for (j = 0; j < i_max; j++) {
53  v0[i][j] = v0[i + 1][j];
54  }
55  }
56  xMsize = i_max;
57  if (X->Def.iNGPU == 0) {
58 #ifdef _SCALAPACK
59  if(nproc >1) {
60  fprintf(stdoutMPI, "Using SCALAPACK\n\n");
61  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
62  MPI_Comm_size(MPI_COMM_WORLD, &size);
63  MPI_Dims_create(size,2,dims);
64  nprow=dims[0]; npcol=dims[1];
65 
66  blacs_pinfo_(&iam, &nprocs);
67  blacs_get_(&i_negone, &i_zero, &ictxt);
68  blacs_gridinit_(&ictxt, "R", &nprow, &npcol);
69  blacs_gridinfo_(&ictxt, &nprow, &npcol, &myrow, &mycol);
70 
71  mb = GetBlockSize(xMsize, size);
72 
73  mp = numroc_(&xMsize, &mb, &myrow, &i_zero, &nprow);
74  nq = numroc_(&xMsize, &mb, &mycol, &i_zero, &npcol);
75  Z_vec = malloc(mp*nq*sizeof(std::complex<double>));
76  //printf("xMsize %d\n", xMsize);
77  /*if(rank == 0){
78  for(i=0; i<xMsize; i++){
79  for(j=0; j<xMsize; j++){
80  printf("Ham %f %f ", real(Ham[i][j]), imag(Ham[i][j]));
81  }
82  }
83  }*/
84  diag_scalapack_cmp(xMsize, Ham, v0, Z_vec, descZ_vec);
85  //printf("Z %f %f\n", real(Z_vec[0]), imag(Z_vec[1]));
86  } else {
87  ZHEEVall(xMsize, Ham, v0, v1);
88  }
89 #else
90  ZHEEVall(xMsize, v0, X->Phys.energy, v1);
91 #endif
92  } else {
93 #ifdef _MAGMA
94  if(myrank==0){
95  if(diag_magma_cmp(xMsize, Ham, v0, v1, X->Def.iNGPU) != 0) {
96  return -1;
97  }
98  }
99 #else
100  fprintf(stdoutMPI, "Warning: MAGMA is not used in this calculation.");
101  ZHEEVall(xMsize, v0, X->Phys.energy, v1);
102 #endif
103  }
104  for (i = 0; i < i_max; i++) {
105  for (j = 0; j < i_max; j++) {
106  v0[i + 1][j] = v1[i][j];
107  }
108  }
109 
110  strcpy(sdt, "Eigenvalue.dat");
111  if (childfopenMPI(sdt, "w", &fp) != 0) {
112  return -1;
113  }
114  for (i = 0; i < i_max; i++) {
115  fprintf(fp, " %ld %.10lf \n", i, X->Phys.energy[i]);
116  }
117  fclose(fp);
118  return 0;
119 }
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.hpp:395
int nproc
Number of processors, defined in InitializeMPI()
Definition: global.cpp:72
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
Definition: global.cpp:75
int ZHEEVall(int xNsize, std::complex< double > **A, double *r, std::complex< double > **vec)
obtain eigenvalues and eigenvectors of Hermite matrix A
std::complex< double > ** v0
Definition: global.cpp:20
int iNGPU
GPU mode ( only for FullDiag )
Definition: struct.hpp:232
struct PhysList Phys
Physical quantities.
Definition: struct.hpp:398
std::complex< double > ** v1
Definition: global.cpp:21
double * energy
Expectation value of the total energy.
Definition: struct.hpp:356
int myrank
Process ID, defined in InitializeMPI()
Definition: global.cpp:73
struct CheckList Check
Size of the Hilbert space.
Definition: struct.hpp:396
long int idim_max
The dimension of the Hilbert space of this process.
Definition: struct.hpp:305
int childfopenMPI(const char *_cPathChild, const char *_cmode, FILE **_fp)
Only the root process open file in output/ directory.
Definition: FileIO.cpp:27