25#ifndef __INVERSE_SQRT_HPP__
26#define __INVERSE_SQRT_HPP__
43 auto solver = (A__.comm().size() == 1) ? la::Eigensolver_factory(
"lapack") : la::Eigensolver_factory(
"scalapack");
45 std::unique_ptr<la::dmatrix<T>> Z;
46 std::unique_ptr<la::dmatrix<T>> B;
47 if (A__.comm().size() == 1) {
48 Z = std::make_unique<la::dmatrix<T>>(A__.
num_rows(), A__.num_cols());
49 B = std::make_unique<la::dmatrix<T>>(A__.
num_rows(), A__.num_cols());
51 Z = std::make_unique<la::dmatrix<T>>(A__.
num_rows(), A__.num_cols(), A__.blacs_grid(), A__.
bs_row(), A__.
bs_col());
52 B = std::make_unique<la::dmatrix<T>>(A__.
num_rows(), A__.num_cols(), A__.blacs_grid(), A__.
bs_row(), A__.
bs_col());
54 std::vector<real_type<T>> eval(N__);
56 if (solver->solve(N__, N__, A__, &eval[0], *Z)) {
57 RTE_THROW(
"error in diagonalization");
59 for (
int i = 0; i < Z->num_cols_local(); i++) {
60 int icol = Z->icol(i);
61 RTE_ASSERT(eval[icol] > 0);
62 auto f = 1.0 / std::sqrt(eval[icol]);
63 for (
int j = 0; j < Z->num_rows_local(); j++) {
64 A__(j, i) = (*Z)(j, i) *
static_cast<T
>(f);
68 if (A__.comm().size() == 1) {
71 B->at(sddk::memory_t::host), B->ld());
77 return std::make_tuple(std::move(B), std::move(Z), eval);
int num_rows() const
Return number of rows in the global matrix.
int bs_row() const
Row blocking factor.
int bs_col() const
Column blocking factor.
void gemm(char transa, char transb, ftn_int m, ftn_int n, ftn_int k, T const *alpha, T const *A, ftn_int lda, T const *B, ftn_int ldb, T const *beta, T *C, ftn_int ldc, acc::stream_id sid=acc::stream_id(-1)) const
General matrix-matrix multiplication.
uint32_t ld() const
Return leading dimension size.
Contains definition and implementation of distributed matrix class.
Contains definition of eigensolver factory.
Linear algebra interface.
auto inverse_sqrt(la::dmatrix< T > &A__, int N__)
Compute inverse square root of the matrix.
@ scalapack
CPU ScaLAPACK.
Namespace of the SIRIUS library.
Eror and warning handling during run-time execution.