Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 27 additions & 11 deletions docs/advanced/input_files/input-main.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
- [kspacing](#kspacing)
- [min\_dist\_coef](#min_dist_coef)
- [device](#device)
- [nb2d](#nb2d)
- [precision](#precision)
- [Variables related to input files](#variables-related-to-input-files)
- [stru\_file](#stru_file)
Expand All @@ -40,12 +41,12 @@
- [diago\_smooth\_ethr](#diago_smooth_ethr)
- [pw\_diag\_nmax](#pw_diag_nmax)
- [pw\_diag\_ndim](#pw_diag_ndim)
- [diag\_subspace](#diag_subspace)
- [erf\_ecut](#erf_ecut)
- [fft\_mode](#fft_mode)
- [erf\_height](#erf_height)
- [erf\_sigma](#erf_sigma)
- [Numerical atomic orbitals related variables](#numerical-atomic-orbitals-related-variables)
- [nb2d](#nb2d)
- [lmaxmax](#lmaxmax)
- [lcao\_ecut](#lcao_ecut)
- [lcao\_dk](#lcao_dk)
Expand Down Expand Up @@ -667,6 +668,19 @@ If only one value is set (such as `kspacing 0.5`), then kspacing values of a/b/c
- cg/bpcg/dav ks_solver: required by the `single` precision options
- **Default**: double

### nb2d

- **Type**: Integer
- **Description**: When using elpa or scalapack to solver the eigenvalue problem, the data should be distributed by the two-dimensional block-cyclic distribution. This paramter specifies the size of the block. It is valid for:
- [ks_solver](#ks_solver) is genelpa or scalapack_gvx. If nb2d is set to 0, then it will be automatically set in the program according to the size of atomic orbital basis:
- if size <= 500: nb2d = 1
- if 500 < size <= 1000: nb2d = 32
- if size > 1000: nb2d = 64;
- [ks_solver](#ks_solver) is dav_subspace, and [diag_subspace](#diag_subspace) is 1 or 2. It is the block size for the diagonization of subspace. If it is set to 0, then it will be automatically set in the program according to the number of band:
- if number of band > 500: nb2d = 32
- if number of band < 500: nb2d = 16
- **Default**: 0

[back to top](#full-list-of-input-keywords)

## Variables related to input files
Expand Down Expand Up @@ -794,7 +808,18 @@ These variables are used to control the plane wave related parameters.

- **Type**: Integer
- **Description**: Only useful when you use `ks_solver = dav` or `ks_solver = dav_subspace`. It indicates dimension of workspace(number of wavefunction packets, at least 2 needed) for the Davidson method. A larger value may yield a smaller number of iterations in the algorithm but uses more memory and more CPU time in subspace diagonalization.
- **Default**: 4
- **Default**: 4

### diag_subspace

- **Type**: Integer
- **Description**: The method to diagonalize subspace in dav_subspace method. The available options are:
- 0: by LAPACK
- 1: by GenELPA
- 2: by ScaLAPACK
LAPACK only solve in one core, GenELPA and ScaLAPACK can solve in parallel. If the system is small (such as the band number is less than 100), LAPACK is recommended. If the system is large and MPI parallel is used, then GenELPA or ScaLAPACK is recommended, and GenELPA usually has better performance. For GenELPA and ScaLAPACK, the block size can be set by [nb2d](#nb2d).

- **Default**: 0

### erf_ecut

Expand Down Expand Up @@ -837,15 +862,6 @@ These variables are used to control the plane wave related parameters.

These variables are used to control the numerical atomic orbitals related parameters.

### nb2d

- **Type**: Integer
- **Description**: In LCAO calculations, we arrange the total number of processors in an 2D array, so that we can partition the wavefunction matrix (number of bands*total size of atomic orbital basis) and distribute them in this 2D array. When the system is large, we group processors into sizes of nb2d, so that multiple processors take care of one row block (a group of atomic orbitals) in the wavefunction matrix. If set to 0, nb2d will be automatically set in the program according to the size of atomic orbital basis:
- if size <= 500 : nb2d = 1
- if 500 < size <= 1000 : nb2d = 32
- if size > 1000 : nb2d = 64;
- **Default**: 0

### lmaxmax

- **Type**: Integer
Expand Down
3 changes: 3 additions & 0 deletions python/pyabacus/src/hsolver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ list(APPEND _diago
${HSOLVER_PATH}/diago_cg.cpp
${HSOLVER_PATH}/diag_const_nums.cpp
${HSOLVER_PATH}/diago_iter_assist.cpp
${HSOLVER_PATH}/diag_hs_para.cpp
${HSOLVER_PATH}/diago_pxxxgvx.cpp


${HSOLVER_PATH}/kernels/dngvd_op.cpp
${HSOLVER_PATH}/kernels/math_kernel_op.cpp
Expand Down
8 changes: 6 additions & 2 deletions python/pyabacus/src/hsolver/py_diago_dav_subspace.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ class PyDiagoDavSubspace
bool need_subspace,
std::vector<double>& diag_ethr,
bool scf_type,
hsolver::diag_comm_info comm_info
hsolver::diag_comm_info comm_info,
int diag_subspace,
int nb2d
) {
auto hpsi_func = [mm_op] (
std::complex<double> *psi_in,
Expand Down Expand Up @@ -138,7 +140,9 @@ class PyDiagoDavSubspace
tol,
max_iter,
need_subspace,
comm_info
comm_info,
diag_subspace,
nb2d
);

return obj->diag(hpsi_func, psi, nbasis, eigenvalue, diag_ethr, scf_type);
Expand Down
11 changes: 10 additions & 1 deletion python/pyabacus/src/hsolver/py_hsolver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,13 @@ void bind_hsolver(py::module& m)
where the initial precision of eigenvalue calculation can be coarse.
If false, it indicates a non-self-consistent field (non-SCF) calculation,
where high precision in eigenvalue calculation is required from the start.
comm_info : diag_comm_info
The communicator information.
diago_subspace : int
The method to solve the generalized eigenvalue problem.
0: LAPACK, 1: Gen-ELPA, 2: ScaLAPACK
nb2d : int
The block size in 2d block cyclic distribution if use elpa or scalapack.
)pbdoc",
"mm_op"_a,
"precond_vec"_a,
Expand All @@ -76,7 +83,9 @@ void bind_hsolver(py::module& m)
"need_subspace"_a,
"diag_ethr"_a,
"scf_type"_a,
"comm_info"_a)
"comm_info"_a,
"diago_subspace"_a,
"nb2d"_a)
.def("set_psi", &py_hsolver::PyDiagoDavSubspace::set_psi, R"pbdoc(
Set the initial guess of the eigenvectors, i.e. the wave functions.
)pbdoc", "psi_in"_a)
Expand Down
13 changes: 11 additions & 2 deletions python/pyabacus/src/pyabacus/hsolver/_hsolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ def dav_subspace(
max_iter: int = 1000,
need_subspace: bool = False,
diag_ethr: Union[List[float], None] = None,
scf_type: bool = False
scf_type: bool = False,
diag_subspace: int = 0,
nb2d: int = 0
) -> Tuple[NDArray[np.float64], NDArray[np.complex128]]:
""" A function to diagonalize a matrix using the Davidson-Subspace method.

Expand Down Expand Up @@ -67,6 +69,11 @@ def dav_subspace(
If True, the initial precision of eigenvalue calculation can be coarse.
If False, it indicates a non-self-consistent field (non-SCF) calculation,
where high precision in eigenvalue calculation is required from the start.
diag_subspace : int, optional
The method to do the diagonalization, by default 0.
0: LAPACK, 1: Gen-elpa, 2: Scalapack
nb2d : int, optional
The block size for 2D decomposition, by default 0, which will be automatically set.

Returns
-------
Expand Down Expand Up @@ -101,7 +108,9 @@ def dav_subspace(
need_subspace,
diag_ethr,
scf_type,
comm_info
comm_info,
diag_subspace,
nb2d
)

e = _diago_obj_dav_subspace.get_eigenvalue()
Expand Down
2 changes: 2 additions & 0 deletions source/Makefile.Objects
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ OBJS_HSOLVER=diago_cg.o\
math_kernel_op.o\
dngvd_op.o\
diag_const_nums.o\
diag_hs_para.o\
diago_pxxxgvx.o\

OBJS_HSOLVER_LCAO=hsolver_lcao.o\
diago_scalapack.o\
Expand Down
2 changes: 1 addition & 1 deletion source/module_base/blacs_connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ extern "C"
// Informational and Miscellaneous
void Cblacs_gridinfo(int icontxt, int* nprow, int *npcol, int *myprow, int *mypcol);
void Cblacs_gridinit(int* icontxt, char* layout, int nprow, int npcol);
void Cblacs_gridexit(int* icontxt);
void Cblacs_gridexit(int icontxt);
int Cblacs_pnum(int icontxt, int prow, int pcol);
void Cblacs_pcoord(int icontxt, int pnum, int *prow, int *pcol);
void Cblacs_exit(int icontxt);
Expand Down
14 changes: 14 additions & 0 deletions source/module_base/scalapack_connector.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,26 @@ extern "C"
const double* vl, const double* vu, const int* il, const int* iu,
const double* abstol, int* m, int* nz, double* w, const double*orfac, double* Z, const int* iz, const int* jz, const int*descz,
double* work, int* lwork, int*iwork, int*liwork, int* ifail, int*iclustr, double*gap, int* info);

void pzhegvx_(const int* itype, const char* jobz, const char* range, const char* uplo,
const int* n, std::complex<double>* A, const int* ia, const int* ja, const int*desca, std::complex<double>* B, const int* ib, const int* jb, const int*descb,
const double* vl, const double* vu, const int* il, const int* iu,
const double* abstol, int* m, int* nz, double* w, const double*orfac, std::complex<double>* Z, const int* iz, const int* jz, const int*descz,
std::complex<double>* work, int* lwork, double* rwork, int* lrwork, int*iwork, int*liwork, int* ifail, int*iclustr, double*gap, int* info);

void pssygvx_(const int* itype, const char* jobz, const char* range, const char* uplo,
const int* n, float* A, const int* ia, const int* ja, const int*desca, float* B, const int* ib, const int* jb, const int*descb,
const float* vl, const float* vu, const int* il, const int* iu,
const float* abstol, int* m, int* nz, float* w, const float*orfac, float* Z, const int* iz, const int* jz, const int*descz,
float* work, int* lwork, int*iwork, int*liwork, int* ifail, int*iclustr, float*gap, int* info);

void pchegvx_(const int* itype, const char* jobz, const char* range, const char* uplo,
const int* n, std::complex<float>* A, const int* ia, const int* ja, const int*desca, std::complex<float>* B, const int* ib, const int* jb, const int*descb,
const float* vl, const float* vu, const int* il, const int* iu,
const float* abstol, int* m, int* nz, float* w, const float*orfac, std::complex<float>* Z, const int* iz, const int* jz, const int*descz,
std::complex<float>* work, int* lwork, float* rwork, int* lrwork, int*iwork, int*liwork, int* ifail, int*iclustr, float*gap, int* info);


void pzgetri_(
const int *n,
const std::complex<double> *A, const int *ia, const int *ja, const int *desca,
Expand Down
3 changes: 3 additions & 0 deletions source/module_hsolver/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ list(APPEND objects
hsolver_pw_sdft.cpp
diago_iter_assist.cpp
hsolver.cpp
diago_pxxxgvx.cpp
diag_hs_para.cpp

)

if(ENABLE_LCAO)
Expand Down
Loading
Loading