ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
lr_util.h
Go to the documentation of this file.
1#pragma once
2#include <cstddef>
3#include <vector>
4#include <utility>
8#include "source_psi/psi.h"
9#include <ATen/core/tensor.h>
11
14
15#ifndef TO_COMPLEX_H
16#define TO_COMPLEX_H
17template <typename T> struct ToComplex;
18template <> struct ToComplex<double> { using type = std::complex<double>; };
19template <> struct ToComplex<std::complex<double>> { using type = std::complex<double>; };
20template <> struct ToComplex<float> { using type = std::complex<float>; };
21template <> struct ToComplex<std::complex<float>> { using type = std::complex<float>; };
22#endif
23
24namespace LR_Util
25{
27
31 template <typename TCell>
32 int cal_nelec(const TCell& ucell);
33
36 int cal_nocc(int nelec);
37
45 std::pair<ModuleBase::matrix, std::vector<std::pair<int, int>>>
46 set_ix_map_diagonal(bool mode, int nc, int nv);
47
48 // Operators to calculate xc kernel have been moved into lr_util_xc.hpp.
50
51 //====== newers and deleters========
53 template <typename T>
54 void _deallocate_2order_nested_ptr(T** p2, size_t size);
56 template <typename T>
57 void _allocate_2order_nested_ptr(T**& p2, size_t size1, size_t size2);
58
63
66 template<typename T>
67 void matsym(const T* in, const int n, T* out);
69 template<typename T>
70 void matsym(T* inout, const int n);
71#ifdef __MPI
72 template<typename T>
73 void matsym(const T* in, const int n, const Parallel_2D& pmat, T* out);
74 template<typename T>
75 void matsym(T* inout, const int n, const Parallel_2D& pmat);
76#endif
77
80 template<typename T, typename Device>
81 psi::Psi<T, Device> k1_to_bfirst_wrapper(const psi::Psi<T, Device>& psi_kfirst, int nk_in, int nbasis_in);
83 template<typename T, typename Device>
85
87 // pack the process to setup 2d divion reusing blacs_ctxt of a new 2d-matrix
88 void setup_2d_division(Parallel_2D& pv, int nb, int gr, int gc);
89
90#ifdef __MPI
91 // pack the process to setup 2d divion reusing blacs_ctxt of an existing 2d-matrix
92 void setup_2d_division(Parallel_2D& pv, int nb, int gr, int gc, const int& blacs_ctxt_in);
95 template <typename T>
96 void gather_2d_to_full(const Parallel_2D& pv, const T* submat, T* fullmat, bool col_first, int global_nrow, int global_ncol);
97#endif
98
101 void diag_lapack(const int& n, double* mat, double* eig);
102 void diag_lapack(const int& n, std::complex<double>* mat, double* eig);
104 void diag_lapack_nh(const int& n, double* mat, std::complex<double>* eig);
105 void diag_lapack_nh(const int& n, std::complex<double>* mat, std::complex<double>* eig);
106
108 std::string tolower(const std::string& str);
109 std::string toupper(const std::string& str);
110}
111#include "lr_util.hpp"
This class packs the basic information of 2D-block-cyclic parallel distribution of an arbitrary matri...
Definition parallel_2d.h:12
A class for representing the shape of a tensor.
Definition tensor_shape.h:13
A multi-dimensional array of elements of a single data type.
Definition tensor.h:32
Definition psi.h:37
std::complex< double > complex
Definition diago_cusolver.cpp:13
#define T
Definition exp.cpp:237
Definition lr_util.cpp:6
int cal_nelec(const TCell &ucell)
=====================PHYSICS====================
Definition lr_util.hpp:13
ct::Tensor newTensor(const ct::TensorShape &shape)
Definition lr_util.h:59
void matsym(const T *in, const int n, T *out)
Definition lr_util.hpp:70
void gather_2d_to_full(const Parallel_2D &pv, const T *submat, T *fullmat, bool col_first, int global_nrow, int global_ncol)
gather 2d matrix to full matrix the defination of row and col is consistent with setup_2d_division
Definition lr_util.hpp:148
int cal_nocc(int nelec)
=================PHYSICS====================
Definition lr_util.cpp:8
std::string toupper(const std::string &str)
Definition lr_util.cpp:189
std::string tolower(const std::string &str)
=================string option====================
Definition lr_util.cpp:183
void diag_lapack(const int &n, double *mat, double *eig)
diagonalize a hermitian matrix
Definition lr_util.cpp:118
void diag_lapack_nh(const int &n, double *mat, std::complex< double > *eig)
diagonalize a general matrix
Definition lr_util.cpp:147
psi::Psi< T, Device > bfirst_to_k1_wrapper(const psi::Psi< T, Device > &psi_bfirst)
psi(nb, nk, nbasis) -> psi(nk=1, nbands=nb, nk * nbasis) without memory copy
Definition lr_util.hpp:130
psi::Psi< T, Device > k1_to_bfirst_wrapper(const psi::Psi< T, Device > &psi_kfirst, int nk_in, int nbasis_in)
psi(nk=1, nbands=nb, nk * nbasis) -> psi(nb, nk, nbasis) without memory copy
Definition lr_util.hpp:111
void _allocate_2order_nested_ptr(T **&p2, size_t size1, size_t size2)
new 2d pointer
Definition lr_util.hpp:35
void _deallocate_2order_nested_ptr(T **p2, size_t size)
=================ALGORITHM====================
Definition lr_util.hpp:49
std::pair< ModuleBase::matrix, std::vector< std::pair< int, int > > > set_ix_map_diagonal(bool mode, int nocc, int nvirt)
set the index map: ix to (ic, iv) and vice versa by diagonal traverse the c-v pairs leftdown -> right...
Definition lr_util.cpp:11
void setup_2d_division(Parallel_2D &pv, int nb, int gr, int gc)
=================2D-block Parallel===============
Definition lr_util.cpp:99
DataType
Enumeration of data types for tensors. The DataType enum lists the supported data types for tensors....
Definition tensor_types.h:50
DeviceType
The type of memory used by an allocator.
Definition tensor_types.h:73
std::complex< double > type
Definition lr_util.h:18
std::complex< float > type
Definition lr_util.h:20
std::complex< double > type
Definition lr_util.h:19
std::complex< float > type
Definition lr_util.h:21
Definition lr_util.h:17
Template struct for mapping a DataType to its corresponding enum value.
Definition tensor_types.h:194
Template struct for mapping a Device Type to its corresponding enum value.
Definition tensor_types.h:158