77
88#define DETAILINFO true
99#define PASSTHRESHOLD 1e-4
10- #define PRINT_NEW_MATRIX false // print out the H matrix after doing block-cycle distribution
10+ #define PRINT_NEW_MATRIX true // print out the H matrix after doing block-cycle distribution
11+ #define PRINT_HS false
1112
1213/* ***********************************************
1314 * unit test of ELPA
@@ -42,10 +43,10 @@ template <class T> class ElpaPrepare
4243 int n = 10 ; // dimension of H/S matrix
4344 int nblk = 1 ; // dimension of sub-matrix
4445 int sparsity = 100 ; // sparsity of H matrix;
45- T *hmatrix = 0 ;
46- T *smatrix = 0 ;
47- double *e_lapack = 0 ; // eigenvalues solvered by LAPACK
48- double *e_elpa = 0 ;
46+ T *hmatrix = nullptr ;
47+ T *smatrix = nullptr ;
48+ double *e_lapack = nullptr ; // eigenvalues solved by LAPACK
49+ double *e_elpa = nullptr ;
4950 double lapack_time = 0.0 , elpa_time = 0.0 ;
5051 int mypnum = 0 ;
5152
@@ -54,66 +55,54 @@ template <class T> class ElpaPrepare
5455 LCAO_DIAGO_TEST::random_hs<T>(hmatrix, smatrix, n, sparsity);
5556 }
5657
57- inline void readmatrix (std::ifstream &inf, T *&matrix, int &npw)
58- {
59- inf >> npw;
60- matrix = new T[npw * npw];
61- for (int i = 0 ; i < npw; i++)
62- {
63- for (int j = i; j < npw; j++)
64- {
65- inf >> matrix[i * npw + j];
66- if (i != j)
67- {
68- matrix[j * npw + i] = matrix[i * npw + j];
69- }
70- }
71- }
72- }
73-
74- void read_HS ()
58+ bool read_HS ()
7559 {
60+ bool readhfile = false ;
61+ bool readsfile = false ;
7662 if (mypnum == 0 )
7763 {
78- int hdim = 1 ;
79- int sdim = 1 ;
80-
81- std::ifstream ifs;
64+ std::vector<T> htmp,stmp;
8265 if (std::is_same<T, double >::value)
8366 {
84- ifs.open (" H-GammaOnly.dat" );
67+ readhfile = LCAO_DIAGO_TEST::read_hs<std::vector<T>>(std::string (" H-GammaOnly.dat" ),htmp);
68+ readsfile = LCAO_DIAGO_TEST::read_hs<std::vector<T>>(std::string (" S-GammaOnly.dat" ),stmp);
8569 }
8670 else if ((std::is_same<T, std::complex <double >>::value))
87- ifs.open (" H-KPonts.dat" );
88- readmatrix (ifs, hmatrix, hdim);
89- ifs.close ();
90-
91- if (std::is_same<T, double >::value)
9271 {
93- ifs.open (" S-GammaOnly.dat" );
72+ readhfile = LCAO_DIAGO_TEST::read_hs<std::vector<T>>(std::string (" H-KPoints.dat" ),htmp);
73+ readsfile = LCAO_DIAGO_TEST::read_hs<std::vector<T>>(std::string (" S-KPoints.dat" ),stmp);
9474 }
95- else if ((std::is_same<T, std::complex <double >>::value))
96- ifs.open (" S-KPoints.dat" );
97- readmatrix (ifs, smatrix, sdim);
98- ifs.close ();
75+ if (htmp.size () != stmp.size ())
76+ {
77+ printf (" Error: dimensions of H and S are not equal, %d, %d" , htmp.size (), stmp.size ());
78+ readhfile = readsfile = false ;
79+ }
80+
81+ hmatrix = new T[htmp.size ()];
82+ smatrix = new T[stmp.size ()];
9983
100- if (hdim != sdim )
84+ for ( int i= 0 ;i<htmp. size ();i++ )
10185 {
102- printf ( " Error: dimensions of H and S are not equal, %d, %d " , hdim, sdim) ;
103- exit ( 1 ) ;
86+ hmatrix[i] = htmp[i] ;
87+ smatrix[i] = stmp[i] ;
10488 }
105- n = hdim;
89+
90+ n = sqrt (stmp.size ());
10691 nblk = 1 ;
10792 }
10893 MPI_Bcast (&n, 1 , MPI_INT, 0 , MPI_COMM_WORLD);
10994 MPI_Bcast (&nblk, 1 , MPI_INT, 0 , MPI_COMM_WORLD);
95+ MPI_Bcast (&readhfile, 1 , MPI_C_BOOL, 0 , MPI_COMM_WORLD);
96+ MPI_Bcast (&readsfile, 1 , MPI_C_BOOL, 0 , MPI_COMM_WORLD);
11097 e_lapack = new double [n];
11198 e_elpa = new double [n];
11299 for (int i = 0 ; i < n; i++)
113100 {
114101 e_lapack[i] = 0.0 ;
115102 e_elpa[i] = 1.0 ;
116103 }
104+ if (readhfile && readsfile) return true ;
105+ else return false ;
117106 }
118107
119108 void new_matrix ()
@@ -131,6 +120,7 @@ template <class T> class ElpaPrepare
131120
132121 void print_hs ()
133122 {
123+ if (! PRINT_HS) {return ;}
134124 if (mypnum == 0 )
135125 {
136126 std::ofstream fp (" hmatrix.dat" );
@@ -207,16 +197,16 @@ class ElpaComplexDoubleTest : public ::testing::TestWithParam<ElpaPrepare<std::c
207197TEST (VerifyElpaDiaoDouble, ReadHS)
208198{
209199 ElpaPrepare<double > edp;
210- edp.read_HS ();
211- // edp.print_hs();
200+ ASSERT_TRUE ( edp.read_HS () );
201+ edp.print_hs ();
212202 edp.run_diago ();
213203}
214204
215205TEST (VerifyElpaDiaoComplexDouble, ReadHS)
216206{
217207 ElpaPrepare<std::complex <double >> edp;
218- edp.read_HS ();
219- // edp.print_hs();
208+ ASSERT_TRUE ( edp.read_HS () );
209+ edp.print_hs ();
220210 edp.run_diago ();
221211}
222212
0 commit comments