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
7 changes: 4 additions & 3 deletions source/source_hsolver/diago_cusolvermp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ using complex = std::complex<double>;
namespace hsolver
{
template <typename T>
void DiagoCusolverMP<T>::diag(hamilt::Hamilt<T>* phm_in, psi::Psi<T>& psi, Real* eigenvalue_in)
void DiagoCusolverMP<T>::diag(ModuleBase::MatrixBlock<T>& h_mat,
ModuleBase::MatrixBlock<T>& s_mat,
psi::Psi<T>& psi,
Real* eigenvalue_in)
{
ModuleBase::TITLE("DiagoCusolverMP", "diag");
ModuleBase::MatrixBlock<T> h_mat, s_mat;
phm_in->matrix(h_mat, s_mat);

std::vector<Real> eigen(this->nlocal, 0.0);
std::vector<T> eigenvectors(h_mat.row * h_mat.col);
Expand Down
8 changes: 6 additions & 2 deletions source/source_hsolver/diago_cusolvermp.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
#define DIAGO_CUSOLVERMPH

#ifdef __CUSOLVERMP
#include "source_hamilt/hamilt.h"
#include "source_base/macros.h"
#include "source_base/matrix_block.h"
#include "source_basis/module_ao/parallel_orbitals.h"
#include "source_hsolver/kernels/cuda/diag_cusolvermp.cuh"
#include "source_psi/psi.h"
namespace hsolver
{
// DiagoCusolverMP class, for diagonalization using CUSOLVERMP
Expand All @@ -22,7 +23,10 @@ class DiagoCusolverMP
{
}
// the diag function for CUSOLVERMP diagonalization
void diag(hamilt::Hamilt<T>* phm_in, psi::Psi<T>& psi, Real* eigenvalue_in);
void diag(ModuleBase::MatrixBlock<T>& h_mat,
ModuleBase::MatrixBlock<T>& s_mat,
psi::Psi<T>& psi,
Real* eigenvalue_in);

private:
const int nlocal;
Expand Down
15 changes: 4 additions & 11 deletions source/source_hsolver/diago_elpa.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@
#include "source_base/tool_title.h"
#include "source_base/tool_quit.h"

typedef ModuleBase::MatrixBlock<double> matd;
typedef ModuleBase::MatrixBlock<std::complex<double>> matcd;

namespace hsolver {
#ifdef __MPI
template <>
Expand Down Expand Up @@ -65,14 +62,12 @@ MPI_Comm DiagoElpa<std::complex<double>>::setmpicomm() {
#endif
template <>
void DiagoElpa<std::complex<double>>::diag(
hamilt::Hamilt<std::complex<double>>* phm_in,
ModuleBase::MatrixBlock<std::complex<double>>& h_mat,
ModuleBase::MatrixBlock<std::complex<double>>& s_mat,
psi::Psi<std::complex<double>>& psi,
Real* eigenvalue_in) {
ModuleBase::TITLE("DiagoElpa", "diag");
#ifdef __MPI
matcd h_mat, s_mat;
phm_in->matrix(h_mat, s_mat);

std::vector<double> eigen(this->nlocal, 0.0);

bool isReal = false;
Expand Down Expand Up @@ -103,14 +98,12 @@ void DiagoElpa<std::complex<double>>::diag(
}

template <>
void DiagoElpa<double>::diag(hamilt::Hamilt<double>* phm_in,
void DiagoElpa<double>::diag(ModuleBase::MatrixBlock<double>& h_mat,
ModuleBase::MatrixBlock<double>& s_mat,
psi::Psi<double>& psi,
Real* eigenvalue_in) {
ModuleBase::TITLE("DiagoElpa", "diag");
#ifdef __MPI
matd h_mat, s_mat;
phm_in->matrix(h_mat, s_mat);

std::vector<double> eigen(this->nlocal, 0.0);

bool isReal = true;
Expand Down
7 changes: 5 additions & 2 deletions source/source_hsolver/diago_elpa.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include "source_base/macros.h" // GetRealType
#include "source_base/matrix_block.h"
#include "source_hamilt/hamilt.h"
#include "source_basis/module_ao/parallel_orbitals.h"
#include "source_psi/psi.h"

namespace hsolver
{
Expand All @@ -20,7 +20,10 @@ class DiagoElpa
/// @param nbands_in number of lowest eigenpairs to compute
DiagoElpa(const int nlocal_in, const int nbands_in) : nlocal(nlocal_in), nbands(nbands_in) {};

void diag(hamilt::Hamilt<T>* phm_in, psi::Psi<T>& psi, Real* eigenvalue_in);
void diag(ModuleBase::MatrixBlock<T>& h_mat,
ModuleBase::MatrixBlock<T>& s_mat,
psi::Psi<T>& psi,
Real* eigenvalue_in);
#ifdef __MPI
// diagnolization used in parallel-k case
void diag_pool(ModuleBase::MatrixBlock<T>& h_mat, ModuleBase::MatrixBlock<T>& s_mat, psi::Psi<T>& psi, Real* eigenvalue_in, MPI_Comm& comm);
Expand Down
7 changes: 4 additions & 3 deletions source/source_hsolver/diago_elpa_native.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -143,12 +143,13 @@ void DiagoElpaNative<T>::diag_pool(ModuleBase::MatrixBlock<T>& h_mat,
#endif

template <typename T>
void DiagoElpaNative<T>::diag(hamilt::Hamilt<T>* phm_in, psi::Psi<T>& psi, Real* eigenvalue_in)
void DiagoElpaNative<T>::diag(ModuleBase::MatrixBlock<T>& h_mat,
ModuleBase::MatrixBlock<T>& s_mat,
psi::Psi<T>& psi,
Real* eigenvalue_in)
{
ModuleBase::TITLE("DiagoElpaNative", "diag");
#ifdef __MPI
ModuleBase::MatrixBlock<T> h_mat, s_mat;
phm_in->matrix(h_mat, s_mat);
MPI_Comm COMM_DIAG = setmpicomm(); // set mpi_comm needed
diag_pool(h_mat, s_mat, psi, eigenvalue_in, COMM_DIAG);
#else
Expand Down
7 changes: 5 additions & 2 deletions source/source_hsolver/diago_elpa_native.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

#include "source_base/macros.h" // GetRealType
#include "source_base/matrix_block.h"
#include "source_hamilt/hamilt.h"
#include "source_basis/module_ao/parallel_orbitals.h"
#include "source_psi/psi.h"

namespace hsolver
{
Expand All @@ -22,7 +22,10 @@ class DiagoElpaNative
DiagoElpaNative(const int nlocal_in, const int nbands_in, const bool use_gpu_in)
: nlocal(nlocal_in), nbands(nbands_in), use_gpu(use_gpu_in) {};

void diag(hamilt::Hamilt<T>* phm_in, psi::Psi<T>& psi, Real* eigenvalue_in);
void diag(ModuleBase::MatrixBlock<T>& h_mat,
ModuleBase::MatrixBlock<T>& s_mat,
psi::Psi<T>& psi,
Real* eigenvalue_in);
#ifdef __MPI
// diagnolization used in parallel-k case
void diag_pool(ModuleBase::MatrixBlock<T>& h_mat, ModuleBase::MatrixBlock<T>& s_mat, psi::Psi<T>& psi, Real* eigenvalue_in, MPI_Comm& comm);
Expand Down
17 changes: 6 additions & 11 deletions source/source_hsolver/diago_lapack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@

#include <cstring>

typedef ModuleBase::MatrixBlock<double> matd;
typedef ModuleBase::MatrixBlock<std::complex<double>> matcd;

namespace hsolver
{
namespace
Expand All @@ -32,13 +29,12 @@ void check_lapack_layout(const ModuleBase::MatrixBlock<T>& h_mat,
}
} // namespace
template <>
void DiagoLapack<double>::diag(hamilt::Hamilt<double>* phm_in, psi::Psi<double>& psi, Real* eigenvalue_in)
void DiagoLapack<double>::diag(ModuleBase::MatrixBlock<double>& h_mat,
ModuleBase::MatrixBlock<double>& s_mat,
psi::Psi<double>& psi,
Real* eigenvalue_in)
{
ModuleBase::TITLE("DiagoLapack", "diag");
// Prepare H and S matrix
matd h_mat, s_mat;
phm_in->matrix(h_mat, s_mat);

assert(h_mat.col == s_mat.col && h_mat.row == s_mat.row && h_mat.desc == s_mat.desc);
std::vector<double> eigen(this->nlocal, 0.0);
check_lapack_layout(h_mat, s_mat, eigen.size());
Expand All @@ -51,13 +47,12 @@ void DiagoLapack<double>::diag(hamilt::Hamilt<double>* phm_in, psi::Psi<double>&
}

template <>
void DiagoLapack<std::complex<double>>::diag(hamilt::Hamilt<std::complex<double>>* phm_in,
void DiagoLapack<std::complex<double>>::diag(ModuleBase::MatrixBlock<std::complex<double>>& h_mat,
ModuleBase::MatrixBlock<std::complex<double>>& s_mat,
psi::Psi<std::complex<double>>& psi,
Real* eigenvalue_in)
{
ModuleBase::TITLE("DiagoLapack", "diag");
matcd h_mat, s_mat;
phm_in->matrix(h_mat, s_mat);
assert(h_mat.col == s_mat.col && h_mat.row == s_mat.row && h_mat.desc == s_mat.desc);
std::vector<double> eigen(this->nlocal, 0.0);
check_lapack_layout(h_mat, s_mat, eigen.size());
Expand Down
7 changes: 5 additions & 2 deletions source/source_hsolver/diago_lapack.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@

#include "source_base/macros.h" // GetRealType
#include "source_base/matrix_block.h"
#include "source_hamilt/hamilt.h"
#include "source_base/matrix.h"
#include "source_basis/module_ao/parallel_orbitals.h"
#include "source_psi/psi.h"

#include <complex>
#include <utility>
Expand All @@ -31,7 +31,10 @@ class DiagoLapack
/// @param nbands_in number of lowest eigenpairs to compute
DiagoLapack(const int nlocal_in, const int nbands_in) : nlocal(nlocal_in), nbands(nbands_in) {};

void diag(hamilt::Hamilt<T>* phm_in, psi::Psi<T>& psi, Real* eigenvalue_in);
void diag(ModuleBase::MatrixBlock<T>& h_mat,
ModuleBase::MatrixBlock<T>& s_mat,
psi::Psi<T>& psi,
Real* eigenvalue_in);
#ifdef __MPI
// diagnolization used in parallel-k case
void diag_pool(ModuleBase::MatrixBlock<T>& h_mat, ModuleBase::MatrixBlock<T>& s_mat, psi::Psi<T>& psi, Real* eigenvalue_in, MPI_Comm& comm);
Expand Down
13 changes: 6 additions & 7 deletions source/source_hsolver/diago_pexsi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
#include "source_basis/module_ao/parallel_orbitals.h"
#include "module_pexsi/pexsi_solver.h"

typedef ModuleBase::MatrixBlock<double> matd;
typedef ModuleBase::MatrixBlock<std::complex<double>> matcd;

namespace hsolver
{
template <typename T>
Expand Down Expand Up @@ -60,11 +57,12 @@ DiagoPexsi<T>::~DiagoPexsi()
}

template <>
void DiagoPexsi<double>::diag(hamilt::Hamilt<double>* phm_in, psi::Psi<double>& psi, double* eigenvalue_in)
void DiagoPexsi<double>::diag(ModuleBase::MatrixBlock<double>& h_mat,
ModuleBase::MatrixBlock<double>& s_mat,
psi::Psi<double>& psi,
double* eigenvalue_in)
{
ModuleBase::TITLE("DiagoPEXSI", "diag");
matd h_mat, s_mat;
phm_in->matrix(h_mat, s_mat);
int ik = psi.get_current_k();
this->ps->prepare(this->ParaV->blacs_ctxt,
this->ParaV->nb,
Expand All @@ -84,7 +82,8 @@ void DiagoPexsi<double>::diag(hamilt::Hamilt<double>* phm_in, psi::Psi<double>&
}

template <>
void DiagoPexsi<std::complex<double>>::diag(hamilt::Hamilt<std::complex<double>>* phm_in,
void DiagoPexsi<std::complex<double>>::diag(ModuleBase::MatrixBlock<std::complex<double>>& h_mat,
ModuleBase::MatrixBlock<std::complex<double>>& s_mat,
psi::Psi<std::complex<double>>& psi,
double* eigenvalue_in)
{
Expand Down
8 changes: 6 additions & 2 deletions source/source_hsolver/diago_pexsi.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
#include <vector>
#include <memory>
#include "source_base/macros.h" // GetRealType
#include "source_hamilt/hamilt.h"
#include "source_base/matrix_block.h"
#include "source_basis/module_ao/parallel_orbitals.h"
#include "source_psi/psi.h"
#include "module_pexsi/pexsi_solver.h"

namespace hsolver
Expand All @@ -24,7 +25,10 @@ class DiagoPexsi
const int nlocal_in,
const double nelec_in,
const int world_nproc_in);
void diag(hamilt::Hamilt<T>* phm_in, psi::Psi<T>& psi, Real* eigenvalue_in);
void diag(ModuleBase::MatrixBlock<T>& h_mat,
ModuleBase::MatrixBlock<T>& s_mat,
psi::Psi<T>& psi,
Real* eigenvalue_in);
const Parallel_Orbitals* ParaV = nullptr;
std::vector<T*> DM;
std::vector<T*> EDM;
Expand Down
17 changes: 8 additions & 9 deletions source/source_hsolver/diago_scalapack.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
#include <cassert>
#include <cstring>

typedef ModuleBase::MatrixBlock<double> matd;
typedef ModuleBase::MatrixBlock<std::complex<double>> matcd;

namespace hsolver
{
namespace
Expand All @@ -33,23 +30,25 @@ int blacs_grid_size(const int* const desc)
} // namespace

template<>
void DiagoScalapack<double>::diag(hamilt::Hamilt<double>* phm_in, psi::Psi<double>& psi, Real* eigenvalue_in)
void DiagoScalapack<double>::diag(ModuleBase::MatrixBlock<double>& h_mat,
ModuleBase::MatrixBlock<double>& s_mat,
psi::Psi<double>& psi,
Real* eigenvalue_in)
{
ModuleBase::TITLE("DiagoScalapack", "diag");
matd h_mat, s_mat;
phm_in->matrix(h_mat, s_mat);
assert(h_mat.col == s_mat.col && h_mat.row == s_mat.row && h_mat.desc == s_mat.desc);
std::vector<double> eigen(this->nlocal, 0.0);
this->pdsygvx_diag(h_mat.desc, h_mat.col, h_mat.row, h_mat.p, s_mat.p, eigen.data(), psi);
const int inc = 1;
BlasConnector::copy(this->nbands, eigen.data(), inc, eigenvalue_in, inc);
}
template<>
void DiagoScalapack<std::complex<double>>::diag(hamilt::Hamilt<std::complex<double>>* phm_in, psi::Psi<std::complex<double>>& psi, Real* eigenvalue_in)
void DiagoScalapack<std::complex<double>>::diag(ModuleBase::MatrixBlock<std::complex<double>>& h_mat,
ModuleBase::MatrixBlock<std::complex<double>>& s_mat,
psi::Psi<std::complex<double>>& psi,
Real* eigenvalue_in)
{
ModuleBase::TITLE("DiagoScalapack", "diag");
matcd h_mat, s_mat;
phm_in->matrix(h_mat, s_mat);
assert(h_mat.col == s_mat.col && h_mat.row == s_mat.row && h_mat.desc == s_mat.desc);
std::vector<double> eigen(this->nlocal, 0.0);
this->pzhegvx_diag(h_mat.desc, h_mat.col, h_mat.row, h_mat.p, s_mat.p, eigen.data(), psi);
Expand Down
6 changes: 4 additions & 2 deletions source/source_hsolver/diago_scalapack.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

#include "source_base/macros.h" // GetRealType
#include "source_base/matrix_block.h"
#include "source_hamilt/hamilt.h"
#include "source_psi/psi.h"
#include "source_base/complexmatrix.h"
#include "source_base/matrix.h"
Expand All @@ -32,7 +31,10 @@ namespace hsolver
/// @param nbands_in number of lowest eigenpairs to compute
DiagoScalapack(const int nlocal_in, const int nbands_in) : nlocal(nlocal_in), nbands(nbands_in) {};

void diag(hamilt::Hamilt<T>* phm_in, psi::Psi<T>& psi, Real* eigenvalue_in);
void diag(ModuleBase::MatrixBlock<T>& h_mat,
ModuleBase::MatrixBlock<T>& s_mat,
psi::Psi<T>& psi,
Real* eigenvalue_in);
#ifdef __MPI
// diagnolization used in parallel-k case
void diag_pool(ModuleBase::MatrixBlock<T>& h_mat, ModuleBase::MatrixBlock<T>& s_mat, psi::Psi<T>& psi, Real* eigenvalue_in, MPI_Comm& comm);
Expand Down
Loading
Loading