HΦ  3.2.0
lapack_diag.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/>. */
16 #include "lapack_diag.h"
17 #include "matrixlapack.h"
18 #include "FileIO.h"
19 #ifdef _MAGMA
20 #include "matrixlapack_magma.h"
21 #endif
22 #ifdef _SCALAPACK
23 #include "matrixscalapack.h"
24 #endif
25 
36 struct BindStruct *X
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  //printf("Ham %f %f ", creal(Ham[i+1][j+1]), cimag(Ham[i+1][j+1]));
54  Ham[i][j] = Ham[i + 1][j + 1];
55  }
56  }
57  xMsize = i_max;
58  /*for(i=0; i<xMsize; i++){
59  for(j=0; j<xMsize; j++){
60  printf("Ham %f %f ", creal(Ham[i][j]), cimag(Ham[i][j]));
61  }
62  }*/
63  if (X->Def.iNGPU == 0) {
64 #ifdef _SCALAPACK
65  if(nproc >1) {
66  fprintf(stdoutMPI, "Using SCALAPACK\n\n");
67  MPI_Comm_rank(MPI_COMM_WORLD, &rank);
68  MPI_Comm_size(MPI_COMM_WORLD, &size);
69  MPI_Dims_create(size,2,dims);
70  nprow=dims[0]; npcol=dims[1];
71 
72  blacs_pinfo_(&iam, &nprocs);
73  blacs_get_(&i_negone, &i_zero, &ictxt);
74  blacs_gridinit_(&ictxt, "R", &nprow, &npcol);
75  blacs_gridinfo_(&ictxt, &nprow, &npcol, &myrow, &mycol);
76 
77  mb = GetBlockSize(xMsize, size);
78 
79  mp = numroc_(&xMsize, &mb, &myrow, &i_zero, &nprow);
80  nq = numroc_(&xMsize, &mb, &mycol, &i_zero, &npcol);
81  Z_vec = malloc(mp*nq*sizeof(complex double));
82  //printf("xMsize %d\n", xMsize);
83  /*if(rank == 0){
84  for(i=0; i<xMsize; i++){
85  for(j=0; j<xMsize; j++){
86  printf("Ham %f %f ", creal(Ham[i][j]), cimag(Ham[i][j]));
87  }
88  }
89  }*/
90  diag_scalapack_cmp(xMsize, Ham, v0, Z_vec, descZ_vec);
91  //printf("Z %f %f\n", creal(Z_vec[0]), cimag(Z_vec[1]));
92  } else {
93  ZHEEVall(xMsize, Ham, v0, L_vec);
94  }
95 #else
96  ZHEEVall(xMsize, Ham, v0, L_vec);
97 #endif
98  } else {
99 #ifdef _MAGMA
100  if(myrank==0){
101  if(diag_magma_cmp(xMsize, Ham, v0, L_vec, X->Def.iNGPU) != 0) {
102  return -1;
103  }
104  }
105 #else
106  fprintf(stdoutMPI, "Warning: MAGMA is not used in this calculation.");
107  ZHEEVall(xMsize, Ham, v0, L_vec);
108 #endif
109  }
110 
111  /*for (i = 0; i < i_max; i++) {
112  for (j = 0; j < i_max; j++) {
113  fprintf(stdoutMPI, "%f %f \n", creal(L_vec[i][j]), cimag(L_vec[i][j]));
114  }
115  }*/
116 
117  strcpy(sdt, cFileNameEigenvalue_Lanczos);
118  if (childfopenMPI(sdt, "w", &fp) != 0) {
119  return -1;
120  }
121  for (i = 0; i < i_max; i++) {
122  fprintf(fp, " %ld %.10lf \n", i, creal(v0[i]));
123  }
124  fclose(fp);
125 
126 
127  return 0;
128 }
struct DefineList Def
Definision of system (Hamiltonian) etc.
Definition: struct.h:410
unsigned long int idim_max
The dimension of the Hilbert space of this process.
Definition: struct.h:303
int lapack_diag(struct BindStruct *X)
performing full diagonalization using lapack
Definition: lapack_diag.c:35
#define D_FileNameMax
Definition: global.h:23
int childfopenMPI(const char *_cPathChild, const char *_cmode, FILE **_fp)
Only the root process open file in output/ directory.
Definition: FileIO.c:27
int iNGPU
GPU mode ( only for FullDiag )
Definition: struct.h:230
int ZHEEVall(int xNsize, double complex **A, double complex *r, double complex **vec)
obtain eigenvalues and eigenvectors of Hermite matrix A
Definition: matrixlapack.c:374
int nproc
Number of processors, defined in InitializeMPI()
Definition: global.h:162
Bind.
Definition: struct.h:409
double complex ** Ham
Definition: global.h:73
double complex ** L_vec
Definition: global.h:74
struct EDMainCalStruct X
Definition: struct.h:432
const char * cFileNameEigenvalue_Lanczos
Definition: global.c:41
int myrank
Process ID, defined in InitializeMPI()
Definition: global.h:163
double complex * v0
Definition: global.h:34
struct CheckList Check
Size of the Hilbert space.
Definition: struct.h:411
FILE * stdoutMPI
File pointer to the standard output defined in InitializeMPI()
Definition: global.h:165