77extern " C"
88{
99#include " module_base/blacs_connector.h"
10- #include " my_elpa.h"
1110#include " module_base/scalapack_connector.h"
1211}
12+ #include " genelpa/elpa_solver.h"
1313
1414typedef hamilt::MatrixBlock<double > matd;
1515typedef hamilt::MatrixBlock<std::complex <double >> matcd;
1616
1717namespace hsolver
1818{
19- bool DiagoElpa::is_already_decomposed = false ;
20- #ifdef __MPI
21- inline int set_elpahandle (elpa_t &handle,
22- const int *desc,
23- const int local_nrows,
24- const int local_ncols,
25- const int nbands)
26- {
27- int error;
28- int nprows, npcols, myprow, mypcol;
29- Cblacs_gridinfo (desc[1 ], &nprows, &npcols, &myprow, &mypcol);
30- elpa_init (20210430 );
31- handle = elpa_allocate (&error);
32- elpa_set_integer (handle, " na" , desc[2 ], &error);
33- elpa_set_integer (handle, " nev" , nbands, &error);
34-
35- elpa_set_integer (handle, " local_nrows" , local_nrows, &error);
36-
37- elpa_set_integer (handle, " local_ncols" , local_ncols, &error);
38-
39- elpa_set_integer (handle, " nblk" , desc[4 ], &error);
40-
41- elpa_set_integer (handle, " mpi_comm_parent" , MPI_Comm_c2f (MPI_COMM_WORLD), &error);
42-
43- elpa_set_integer (handle, " process_row" , myprow, &error);
44-
45- elpa_set_integer (handle, " process_col" , mypcol, &error);
46-
47- elpa_set_integer (handle, " blacs_context" , desc[1 ], &error);
48-
49- elpa_set_integer (handle, " cannon_for_generalized" , 0 , &error);
50- /* Setup */
51- elpa_setup (handle); /* Set tunables */
52- return 0 ;
53- }
54- #endif
55-
19+ int DiagoElpa::DecomposedState = 0 ;
5620void DiagoElpa::diag (hamilt::Hamilt *phm_in, psi::Psi<std::complex <double >> &psi, double *eigenvalue_in)
5721{
5822 ModuleBase::TITLE (" DiagoElpa" , " diag" );
@@ -62,31 +26,15 @@ void DiagoElpa::diag(hamilt::Hamilt *phm_in, psi::Psi<std::complex<double>> &psi
6226
6327 std::vector<double > eigen (GlobalV::NLOCAL, 0.0 );
6428
65- static elpa_t handle;
66- static bool has_set_elpa_handle = false ;
67- if (!has_set_elpa_handle)
68- {
69- set_elpahandle (handle, h_mat.desc , h_mat.row , h_mat.col , GlobalV::NBANDS);
70- has_set_elpa_handle = true ;
71- }
72-
73- // compare to old code from pplab, there is no need to copy Sloc2 to another memory,
74- // just change Sloc2, which is a temporary matrix
75- // size_t nloc = h_mat.col * h_mat.row,
76- // BlasConnector::copy(nloc, s_mat, inc, Stmp, inc);
77-
29+ bool isReal=false ;
30+ const MPI_Comm COMM_DIAG=MPI_COMM_WORLD; // use all processes
31+ ELPA_Solver es ((const bool )isReal, COMM_DIAG, (const int )GlobalV::NBANDS, (const int )h_mat.row , (const int )h_mat.col , (const int *)h_mat.desc );
32+ this ->DecomposedState =0 ; // for k pointer, the decomposed s_mat can not be reused
7833 ModuleBase::timer::tick (" DiagoElpa" , " elpa_solve" );
79- int elpa_derror;
80- elpa_generalized_eigenvectors_dc (handle,
81- reinterpret_cast <double _Complex *>(h_mat.p ),
82- reinterpret_cast <double _Complex *>(s_mat.p ),
83- eigen.data (),
84- reinterpret_cast <double _Complex *>(psi.get_pointer ()),
85- 0 ,
86- &elpa_derror);
34+ es.generalized_eigenvector (h_mat.p , s_mat.p , this ->DecomposedState , eigen.data (), psi.get_pointer ());
8735 ModuleBase::timer::tick (" DiagoElpa" , " elpa_solve" );
36+ es.exit ();
8837
89- // the eigenvalues.
9038 const int inc = 1 ;
9139 BlasConnector::copy (GlobalV::NBANDS, eigen.data (), inc, eigenvalue_in, inc);
9240#else
@@ -103,43 +51,14 @@ void DiagoElpa::diag(hamilt::Hamilt *phm_in, psi::Psi<double> &psi, double *eige
10351
10452 std::vector<double > eigen (GlobalV::NLOCAL, 0.0 );
10553
106- static elpa_t handle;
107- static bool has_set_elpa_handle = false ;
108- if (!has_set_elpa_handle)
109- {
110- set_elpahandle (handle, h_mat.desc , h_mat.row , h_mat.col , GlobalV::NBANDS);
111- has_set_elpa_handle = true ;
112- }
113-
114- // compare to old code from pplab, there is no need to copy Sloc2 to another memory,
115- // just change Sloc2, which is a temporary matrix
116- // change this judgement to HamiltLCAO
117- /* int is_already_decomposed;
118- if(ifElpaHandle(GlobalC::CHR.get_new_e_iteration(), (GlobalV::CALCULATION=="nscf")))
119- {
120- ModuleBase::timer::tick("DiagoElpa","decompose_S");
121- BlasConnector::copy(pv->nloc, s_mat, inc, Stmp, inc);
122- is_already_decomposed=0;
123- ModuleBase::timer::tick("DiagoElpa","decompose_S");
124- }
125- else
126- {
127- is_already_decomposed=1;
128- }*/
129-
54+ bool isReal=true ;
55+ MPI_Comm COMM_DIAG=MPI_COMM_WORLD; // use all processes
56+ // ELPA_Solver es(isReal, COMM_DIAG, GlobalV::NBANDS, h_mat.row, h_mat.col, h_mat.desc);
57+ ELPA_Solver es ((const bool )isReal, COMM_DIAG, (const int )GlobalV::NBANDS, (const int )h_mat.row , (const int )h_mat.col , (const int *)h_mat.desc );
13058 ModuleBase::timer::tick (" DiagoElpa" , " elpa_solve" );
131- int elpa_error;
132- elpa_generalized_eigenvectors_d (handle,
133- h_mat.p ,
134- s_mat.p ,
135- eigen.data (),
136- psi.get_pointer (),
137- DiagoElpa::is_already_decomposed,
138- &elpa_error);
59+ es.generalized_eigenvector (h_mat.p , s_mat.p , this ->DecomposedState , eigen.data (), psi.get_pointer ());
13960 ModuleBase::timer::tick (" DiagoElpa" , " elpa_solve" );
140-
141- // S matrix has been decomposed
142- DiagoElpa::is_already_decomposed = true ;
61+ es.exit ();
14362
14463 const int inc = 1 ;
14564 ModuleBase::GlobalFunc::OUT (GlobalV::ofs_running, " K-S equation was solved by genelpa2" );
@@ -162,4 +81,4 @@ bool DiagoElpa::ifElpaHandle(const bool &newIteration, const bool &ifNSCF)
16281}
16382#endif
16483
165- } // namespace hsolver
84+ } // namespace hsolver
0 commit comments