@@ -15,6 +15,24 @@ typedef hamilt::MatrixBlock<std::complex<double>> matcd;
1515
1616namespace hsolver
1717{
18+ namespace
19+ {
20+ template <typename T>
21+ void check_lapack_layout (const hamilt::MatrixBlock<T>& h_mat,
22+ const hamilt::MatrixBlock<T>& s_mat,
23+ const std::size_t n)
24+ {
25+ if (h_mat.row != n || h_mat.col != n || s_mat.row != n || s_mat.col != n)
26+ {
27+ ModuleBase::WARNING_QUIT (
28+ " DiagoLapack" ,
29+ " The LAPACK eigensolver requires replicated " + std::to_string (n) + " x "
30+ + std::to_string (n) + " Hamiltonian and overlap matrices, but received "
31+ + std::to_string (h_mat.row ) + " x " + std::to_string (h_mat.col )
32+ + " local blocks. Please use ScaLAPACK or ELPA for distributed matrices." );
33+ }
34+ }
35+ } // namespace
1836template <>
1937void DiagoLapack<double >::diag(hamilt::Hamilt<double >* phm_in, psi::Psi<double >& psi, Real* eigenvalue_in)
2038{
@@ -24,8 +42,8 @@ void DiagoLapack<double>::diag(hamilt::Hamilt<double>* phm_in, psi::Psi<double>&
2442 phm_in->matrix (h_mat, s_mat);
2543
2644 assert (h_mat.col == s_mat.col && h_mat.row == s_mat.row && h_mat.desc == s_mat.desc );
27-
2845 std::vector<double > eigen (PARAM .globalv .nlocal , 0.0 );
46+ check_lapack_layout (h_mat, s_mat, eigen.size ());
2947
3048 // Diag
3149 this ->dsygvx_diag (h_mat.col , h_mat.row , h_mat.p , s_mat.p , eigen.data (), psi);
@@ -43,8 +61,8 @@ void DiagoLapack<std::complex<double>>::diag(hamilt::Hamilt<std::complex<double>
4361 matcd h_mat, s_mat;
4462 phm_in->matrix (h_mat, s_mat);
4563 assert (h_mat.col == s_mat.col && h_mat.row == s_mat.row && h_mat.desc == s_mat.desc );
46-
4764 std::vector<double > eigen (PARAM .globalv .nlocal , 0.0 );
65+ check_lapack_layout (h_mat, s_mat, eigen.size ());
4866 this ->zhegvx_diag (h_mat.col , h_mat.row , h_mat.p , s_mat.p , eigen.data (), psi);
4967 const int inc = 1 ;
5068 BlasConnector::copy (PARAM .inp .nbands , eigen.data (), inc, eigenvalue_in, inc);
@@ -61,6 +79,7 @@ void DiagoLapack<std::complex<double>>::diag(hamilt::Hamilt<std::complex<double>
6179 ModuleBase::TITLE (" DiagoLapack" , " diag_pool" );
6280 assert (h_mat.col == s_mat.col && h_mat.row == s_mat.row && h_mat.desc == s_mat.desc );
6381 std::vector<double > eigen (PARAM .globalv .nlocal , 0.0 );
82+ check_lapack_layout (h_mat, s_mat, eigen.size ());
6483 this ->dsygvx_diag (h_mat.col , h_mat.row , h_mat.p , s_mat.p , eigen.data (), psi);
6584 const int inc = 1 ;
6685 BlasConnector::copy (PARAM .inp .nbands , eigen.data (), inc, eigenvalue_in, inc);
@@ -75,6 +94,7 @@ void DiagoLapack<std::complex<double>>::diag(hamilt::Hamilt<std::complex<double>
7594 ModuleBase::TITLE (" DiagoLapack" , " diag_pool" );
7695 assert (h_mat.col == s_mat.col && h_mat.row == s_mat.row && h_mat.desc == s_mat.desc );
7796 std::vector<double > eigen (PARAM .globalv .nlocal , 0.0 );
97+ check_lapack_layout (h_mat, s_mat, eigen.size ());
7898 this ->zhegvx_diag (h_mat.col , h_mat.row , h_mat.p , s_mat.p , eigen.data (), psi);
7999 const int inc = 1 ;
80100 BlasConnector::copy (PARAM .inp .nbands , eigen.data (), inc, eigenvalue_in, inc);
0 commit comments