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>
10
13
14#ifndef TO_COMPLEX_H
15#define TO_COMPLEX_H
16template <typename T> struct ToComplex;
17template <> struct ToComplex<double> { using type = std::complex<double>; };
18template <> struct ToComplex<std::complex<double>> { using type = std::complex<double>; };
19template <> struct ToComplex<float> { using type = std::complex<float>; };
20template <> struct ToComplex<std::complex<float>> { using type = std::complex<float>; };
21#endif
22
23namespace LR_Util
24{
26
30 template <typename TCell>
31 int cal_nelec(const TCell& ucell);
32
35 int cal_nocc(int nelec);
36
44 std::pair<ModuleBase::matrix, std::vector<std::pair<int, int>>>
45 set_ix_map_diagonal(bool mode, int nc, int nv);
46
47 // Operators to calculate xc kernel have been moved into lr_util_xc.hpp.
49
50 //====== newers and deleters========
52 template <typename T>
53 void _deallocate_2order_nested_ptr(T** p2, size_t size);
55 template <typename T>
56 void _allocate_2order_nested_ptr(T**& p2, size_t size1, size_t size2);
57
62
65 template<typename T>
66 void matsym(const T* in, const int n, T* out);
68 template<typename T>
69 void matsym(T* inout, const int n);
70#ifdef __MPI
71 template<typename T>
72 void matsym(const T* in, const int n, const Parallel_2D& pmat, T* out);
73 template<typename T>
74 void matsym(T* inout, const int n, const Parallel_2D& pmat);
75#endif
76
79 template<typename T, typename Device>
80 psi::Psi<T, Device> k1_to_bfirst_wrapper(const psi::Psi<T, Device>& psi_kfirst, int nk_in, int nbasis_in);
82 template<typename T, typename Device>
84
86 // pack the process to setup 2d divion reusing blacs_ctxt of a new 2d-matrix
87 void setup_2d_division(Parallel_2D& pv, int nb, int gr, int gc);
88
89#ifdef __MPI
90 // pack the process to setup 2d divion reusing blacs_ctxt of an existing 2d-matrix
91 void setup_2d_division(Parallel_2D& pv, int nb, int gr, int gc, const int& blacs_ctxt_in);
94 template <typename T>
95 void gather_2d_to_full(const Parallel_2D& pv, const T* submat, T* fullmat, bool col_first, int global_nrow, int global_ncol);
96#endif
97
100 void diag_lapack(const int& n, double* mat, double* eig);
101 void diag_lapack(const int& n, std::complex<double>* mat, double* eig);
103 void diag_lapack_nh(const int& n, double* mat, std::complex<double>* eig);
104 void diag_lapack_nh(const int& n, std::complex<double>* mat, std::complex<double>* eig);
105
107 std::string tolower(const std::string& str);
108 std::string toupper(const std::string& str);
109}
110#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:15
#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:58
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:17
std::complex< float > type
Definition lr_util.h:19
std::complex< double > type
Definition lr_util.h:18
std::complex< float > type
Definition lr_util.h:20
Definition lr_util.h:16
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