2222extern " C"
2323{
2424 int ilaenv_ (int * ispec,const char * name,const char * opts,
25- const int * n1,const int * n2,const int * n3,const int * n4);
25+ const int * n1,const int * n2,const int * n3,const int * n4);
26+
27+
2628 // solve the generalized eigenproblem Ax=eBx, where A is Hermitian and complex couble
27- // zhegv_ returns all eigenvalues while zhegvx_ returns selected ones
29+ // zhegv_ & zhegvd_ returns all eigenvalues while zhegvx_ returns selected ones
30+
31+ void zhegvd_ (const int * itype, const char * jobz, const char * uplo, const int * n,
32+ std::complex <double >* a, const int * lda, std::complex <double >* b, const int * ldb,
33+ double * w, std::complex <double >* work, int * lwork, double * rwork, int * lrwork,
34+ int * iwork, int * liwork, int * info);
35+
2836 void zhegv_ (const int * itype,const char * jobz,const char * uplo,const int * n,
2937 std::complex <double >* a,const int * lda,std::complex <double >* b,const int * ldb,
3038 double * w,std::complex <double >* work,int * lwork,double * rwork,int * info);
39+
3140 void zhegvx_ (const int * itype,const char * jobz,const char * range,const char * uplo,
3241 const int * n,std::complex <double > *a,const int * lda,std::complex <double > *b,
3342 const int * ldb,const double * vl,const double * vu,const int * il,
3443 const int * iu,const double * abstol,const int * m,double * w,
3544 std::complex <double > *z,const int *ldz,std::complex <double > *work,const int * lwork,
3645 double * rwork,int * iwork,int * ifail,int * info);
46+
47+ // solve the eigenproblem Ax=ex, where A is Hermitian and complex couble
48+ // zheev_ returns all eigenvalues while zheevx_ returns selected ones
49+ void zheev_ (const char * jobz,const char * uplo,const int * n,std::complex <double > *a,
50+ const int * lda,double * w,std::complex <double >* work,const int * lwork,
51+ double * rwork,int * info);
52+
53+ void zheevx_ (const char * jobz,const char * range,const char * uplo,
54+ const int * n,std::complex <double > *a,const int * lda,
55+ const double * vl,const double * vu,const int * il,
56+ const int * iu,const double * abstol,const int * m,double * w,
57+ std::complex <double > *z,const int *ldz,std::complex <double > *work,const int * lwork,
58+ double * rwork,int * iwork,int * ifail,int * info);
59+
60+
3761 // solve the generalized eigenproblem Ax=eBx, where A is Symmetric and real couble
3862 // dsygv_ returns all eigenvalues while dsygvx_ returns selected ones
3963 void dsygv_ (const int * itype, const char * jobz,const char * uplo, const int * n,
@@ -47,10 +71,8 @@ extern "C"
4771 // solve the eigenproblem Ax=ex, where A is Symmetric and real double
4872 void dsyev_ (const char * jobz,const char * uplo,const int * n,double *a,
4973 const int * lda,double * w,double * work,const int * lwork, int * info);
50- // solve the eigenproblem Ax=ex, where A is Hermitian and complex couble
51- void zheev_ (const char * jobz,const char * uplo,const int * n,std::complex <double > *a,
52- const int * lda,double * w,std::complex <double >* work,const int * lwork,
53- double * rwork,int * info);
74+
75+
5476 // dsytrf_ computes the Bunch-Kaufman factorization of a double precision
5577 // symmetric matrix, while dsytri takes its output to perform martrix inversion
5678 void dsytrf_ (const char * uplo, const int * n, double * a, const int * lda,
@@ -226,7 +248,34 @@ class LapackConnector
226248 return nb;
227249 }
228250
229- // wrap function of fortran lapack routine zhegv.
251+ // wrap function of fortran lapack routine zhegvd.
252+ static inline
253+ void zhegvd (const int itype, const char jobz, const char uplo, const int n,
254+ ModuleBase::ComplexMatrix& a, const int lda,
255+ ModuleBase::ComplexMatrix& b, const int ldb, double * w,
256+ std::complex <double >* work, int lwork, double * rwork, int lrwork,
257+ int * iwork, int liwork, int info)
258+ {
259+ // Transpose the std::complex matrix to the fortran-form real-std::complex array.
260+ std::complex <double >* aux = LapackConnector::transpose (a, n, lda);
261+ std::complex <double >* bux = LapackConnector::transpose (b, n, ldb);
262+
263+ // call the fortran routine
264+ zhegvd_ (&itype, &jobz, &uplo, &n,
265+ aux, &lda, bux, &ldb, w,
266+ work, &lwork, rwork, &lrwork,
267+ iwork, &liwork, &info);
268+
269+ // Transpose the fortran-form real-std::complex array to the std::complex matrix.
270+ LapackConnector::transpose (aux, a, n, lda);
271+ LapackConnector::transpose (bux, b, n, ldb);
272+
273+ // free the memory.
274+ delete[] aux;
275+ delete[] bux;
276+ }
277+
278+ // wrap function of fortran lapack routine zhegv ( ModuleBase::ComplexMatrix version ).
230279 static inline
231280 void zhegv ( const int itype,const char jobz,const char uplo,const int n,ModuleBase::ComplexMatrix& a,
232281 const int lda,ModuleBase::ComplexMatrix& b,const int ldb,double * w,std::complex <double >* work,
@@ -244,20 +293,21 @@ class LapackConnector
244293 delete[] aux;
245294 delete[] bux;
246295 }
247- // wrap function of fortran lapack routine zhegv.
296+
297+ // wrap function of fortran lapack routine zhegv ( pointer version ) .
248298 static inline
249299 void zhegv ( const int itype, const char jobz, const char uplo, const int n, std::complex <double >* a,
250300 const int lda, const std::complex <double >* b, const int ldb, double * w, std::complex <double >* work,
251301 int lwork, double * rwork, int info, int ld_real)
252- { // Transpose the std::complex matrix to the fortran-form real-std::complex array.
302+ {
303+ // Transpose the std::complex matrix to the fortran-form real-std::complex array.
253304 std::complex <double >* aux = LapackConnector::transpose (a, n, lda, ld_real);
254305 std::complex <double >* bux = LapackConnector::transpose (b, n, ldb, ld_real);
255306
256307 // call the fortran routine
257308 zhegv_ (&itype, &jobz, &uplo, &n, aux, &lda, bux, &ldb, w, work, &lwork, rwork, &info);
309+
258310 // Transpose the fortran-form real-std::complex array to the std::complex matrix.
259- // LapackConnector::transpose(aux, a, n, lda);
260- // LapackConnector::transpose(bux, b, n, ldb);
261311 for (int i = 0 ; i < n; ++i)
262312 {
263313 for (int j = 0 ; j < lda; ++j)
@@ -270,7 +320,7 @@ class LapackConnector
270320 delete[] bux;
271321 }
272322
273- // wrap function of fortran lapack routine zheev .
323+ // wrap function of fortran lapack routine zhegvx ( ModuleBase::ComplexMatrix version ) .
274324 static inline
275325 void zhegvx ( const int itype, const char jobz, const char range, const char uplo,
276326 const int n, const ModuleBase::ComplexMatrix& a, const int lda, const ModuleBase::ComplexMatrix& b,
@@ -298,7 +348,8 @@ class LapackConnector
298348 delete[] zux;
299349
300350 }
301- // wrap function of fortran lapack routine zheev.
351+
352+ // wrap function of fortran lapack routine zhegvx ( pointer version ).
302353 static inline
303354 void zhegvx ( const int itype, const char jobz, const char range, const char uplo,
304355 const int n, const std::complex <double >* a, const int lda, const std::complex <double >* b,
@@ -331,6 +382,38 @@ class LapackConnector
331382 delete[] zux;
332383 }
333384
385+ static inline
386+ void zheevx ( const int itype, const char jobz, const char range, const char uplo, const int n,
387+ const std::complex <double >* a, const int lda, const double vl, const double vu, const int il, const int iu,
388+ const double abstol, const int m, double * w, std::complex <double >* z, const int ldz,
389+ std::complex <double >* work, const int lwork, double * rwork, int * iwork, int * ifail, int info, int nbase_x)
390+ {
391+ // Transpose the std::complex matrix to the fortran-form real-std::complex array.
392+ std::complex <double >* aux = LapackConnector::transpose (a, n, lda, nbase_x);
393+ std::complex <double >* zux = new std::complex <double >[n*iu];// mohan modify 2009-08-02
394+
395+ // call the fortran routine
396+ zheevx_ (&jobz, &range, &uplo, &n,
397+ aux, &lda, &vl, &vu, &il, &iu,
398+ &abstol, &m, w, zux, &ldz,
399+ work, &lwork, rwork, iwork, ifail, &info);
400+
401+ // Transpose the fortran-form real-std::complex array to the std::complex matrix
402+ for (int i = 0 ; i < iu; ++i)
403+ {
404+ for (int j = 0 ; j < n; ++j)
405+ {
406+ z[j * nbase_x + i] = zux[i*n+j];
407+ }
408+ }
409+
410+ // free the memory.
411+ delete[] aux;
412+ delete[] zux;
413+ }
414+
415+
416+
334417 // calculate the eigenvalues and eigenfunctions of a real symmetric matrix.
335418 static inline
336419 void dsygv ( const int itype,const char jobz,const char uplo,const int n,ModuleBase::matrix& a,
0 commit comments