ABACUS develop
Atomic-orbital Based Ab-initio Computation at UStc
Loading...
Searching...
No Matches
sto_tool.h
Go to the documentation of this file.
1#ifndef STO_TOOL_H
2#define STO_TOOL_H
3
4#include <vector>
5
6#include "source_cell/klist.h"
10#include "source_psi/psi.h"
11
20template <typename FPTYPE, typename Device>
22{
24 void operator()(const int& nche_in,
25 const double& try_emin,
26 const double& try_emax,
27 const int& nbands_sto,
28 K_Vectors* p_kv,
29 Stochastic_WF<std::complex<FPTYPE>, Device>* p_stowf,
30 StoHamiltPW<std::complex<FPTYPE>, Device>* p_hamilt_sto);
31};
32
41{
42 parallel_distribution(const int& num_all, const int& np, const int myrank)
43 {
44 int num_per_ = num_all / np;
45 int st_per = num_per_ * myrank;
46 int re = num_all % np;
47 if (myrank < re)
48 {
49 ++num_per_;
50 st_per += myrank;
51 }
52 else
53 {
54 st_per += re;
55 }
56 this->start = st_per;
57 this->num_per = num_per_;
58 }
59 int start = 0;
60 int num_per = 0;
61};
62
63#ifdef __MPI
69{
70 info_gatherv(const int& ngroup_per, const int& np, const int& num_in_group, MPI_Comm comm_world)
71 : nrecv(np), displs(np)
72 {
73 MPI_Allgather(&ngroup_per, 1, MPI_INT, nrecv.data(), 1, MPI_INT, comm_world);
74 displs[0] = 0;
75 for (int i = 1; i < np; ++i)
76 {
77 displs[i] = displs[i - 1] + nrecv[i - 1];
78 }
79 for (int i = 0; i < np; ++i)
80 {
81 nrecv[i] *= num_in_group;
82 displs[i] *= num_in_group;
83 }
84 }
85 std::vector<int> nrecv;
86 std::vector<int> displs;
87};
88#endif
89
96template <typename FPTYPE_IN, typename FPTYPE_OUT, typename Device>
98{
100 = base_device::memory::cast_memory_op<std::complex<FPTYPE_OUT>, std::complex<FPTYPE_IN>, Device, Device>;
101 void operator()(const psi::Psi<std::complex<FPTYPE_IN>, Device>& psi_in,
102 psi::Psi<std::complex<FPTYPE_OUT>, Device>& psi_out)
103 {
104 psi_in.fix_k(0);
105 psi_out.fix_k(0);
106 castmem_complex_op()(psi_out.get_pointer(), psi_in.get_pointer(), psi_in.size());
107 }
108};
109
122template <typename FPTYPE, typename Device>
124{
125 psi::Psi<std::complex<FPTYPE>, Device>* operator()(psi::Psi<std::complex<FPTYPE>, Device>& chi,
126 psi::Psi<std::complex<FPTYPE>, Device>& chi_all,
127 const int& npwx,
128 int* nrecv_sto,
129 int* displs_sto,
130 const int perbands_sto);
131};
132
133#endif
Class for k-points management.
Definition klist.h:20
Definition sto_hamilt_pw.h:8
Definition sto_wf.h:13
Definition psi.h:37
Definition memory_op.h:99
Check if Emin and Emax are converged.
Definition sto_tool.h:22
base_device::memory::synchronize_memory_op< std::complex< FPTYPE >, Device, base_device::DEVICE_CPU > syncmem_complex_h2d_op
Definition sto_tool.h:23
void operator()(const int &nche_in, const double &try_emin, const double &try_emax, const int &nbands_sto, K_Vectors *p_kv, Stochastic_WF< std::complex< FPTYPE >, Device > *p_stowf, StoHamiltPW< std::complex< FPTYPE >, Device > *p_hamilt_sto)
Definition sto_tool.cpp:15
convert psi from double to float
Definition sto_tool.h:98
base_device::memory::cast_memory_op< std::complex< FPTYPE_OUT >, std::complex< FPTYPE_IN >, Device, Device > castmem_complex_op
Definition sto_tool.h:99
void operator()(const psi::Psi< std::complex< FPTYPE_IN >, Device > &psi_in, psi::Psi< std::complex< FPTYPE_OUT >, Device > &psi_out)
Definition sto_tool.h:100
gather chi from all processors
Definition sto_tool.h:124
psi::Psi< std::complex< FPTYPE >, Device > * operator()(psi::Psi< std::complex< FPTYPE >, Device > &chi, psi::Psi< std::complex< FPTYPE >, Device > &chi_all, const int &npwx, int *nrecv_sto, int *displs_sto, const int perbands_sto)
Definition sto_tool.cpp:119
info_gatherv(const int &ngroup_per, const int &np, const int &num_in_group, MPI_Comm comm_world)
Definition sto_tool.h:70
std::vector< int > displs
Definition sto_tool.h:86
std::vector< int > nrecv
Definition sto_tool.h:85
parallel_distribution(const int &num_all, const int &np, const int myrank)
Definition sto_tool.h:42
int start
Definition sto_tool.h:59
int num_per
Definition sto_tool.h:60