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#include "source_cell/klist.h"
7#include "source_psi/psi.h"
8
17template <typename FPTYPE, typename Device>
19{
21 void operator()(const int& nche_in,
22 const double& try_emin,
23 const double& try_emax,
24 const int& nbands_sto,
25 K_Vectors* p_kv,
26 Stochastic_WF<std::complex<FPTYPE>, Device>* p_stowf,
27 hamilt::HamiltSdftPW<std::complex<FPTYPE>, Device>* p_hamilt_sto);
28};
29
38{
39 parallel_distribution(const int& num_all, const int& np, const int myrank)
40 {
41 int num_per = num_all / np;
42 int st_per = num_per * myrank;
43 int re = num_all % np;
44 if (myrank < re)
45 {
46 ++num_per;
47 st_per += myrank;
48 }
49 else
50 {
51 st_per += re;
52 }
53 this->start = st_per;
54 this->num_per = num_per;
55 }
56 int start;
58};
59
60#ifdef __MPI
66{
67 info_gatherv(const int& ngroup_per, const int& np, const int& num_in_group, MPI_Comm comm_world)
68 {
69 nrecv = new int[np];
70 displs = new int[np];
71 MPI_Allgather(&ngroup_per, 1, MPI_INT, nrecv, 1, MPI_INT, comm_world);
72 displs[0] = 0;
73 for (int i = 1; i < np; ++i)
74 {
75 displs[i] = displs[i - 1] + nrecv[i - 1];
76 }
77 for (int i = 0; i < np; ++i)
78 {
79 nrecv[i] *= num_in_group;
80 displs[i] *= num_in_group;
81 }
82 }
84 {
85 delete[] nrecv;
86 delete[] displs;
87 }
88 int* nrecv = nullptr;
89 int* displs = nullptr;
90};
91#endif
92
99template <typename FPTYPE_IN, typename FPTYPE_OUT, typename Device>
101{
103 = base_device::memory::cast_memory_op<std::complex<FPTYPE_OUT>, std::complex<FPTYPE_IN>, Device, Device>;
104 void operator()(const psi::Psi<std::complex<FPTYPE_IN>, Device>& psi_in,
105 psi::Psi<std::complex<FPTYPE_OUT>, Device>& psi_out)
106 {
107 psi_in.fix_k(0);
108 psi_out.fix_k(0);
109 castmem_complex_op()(psi_out.get_pointer(), psi_in.get_pointer(), psi_in.size());
110 }
111};
112
125template <typename FPTYPE, typename Device>
127{
128 psi::Psi<std::complex<FPTYPE>, Device>* operator()(psi::Psi<std::complex<FPTYPE>, Device>& chi,
129 psi::Psi<std::complex<FPTYPE>, Device>& chi_all,
130 const int& npwx,
131 int* nrecv_sto,
132 int* displs_sto,
133 const int perbands_sto);
134};
135
136#endif
Definition klist.h:13
Definition sto_wf.h:13
Definition hamilt_sdft_pw.h:11
Definition psi.h:37
Definition memory_op.h:61
Check if Emin and Emax are converged.
Definition sto_tool.h:19
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, hamilt::HamiltSdftPW< std::complex< FPTYPE >, Device > *p_hamilt_sto)
Definition sto_tool.cpp:13
convert psi from double to float
Definition sto_tool.h:101
base_device::memory::cast_memory_op< std::complex< FPTYPE_OUT >, std::complex< FPTYPE_IN >, Device, Device > castmem_complex_op
Definition sto_tool.h:103
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:104
gather chi from all processors
Definition sto_tool.h:127
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:117
gather information from all processors
Definition sto_tool.h:66
info_gatherv(const int &ngroup_per, const int &np, const int &num_in_group, MPI_Comm comm_world)
Definition sto_tool.h:67
int * nrecv
Definition sto_tool.h:88
int * displs
Definition sto_tool.h:89
~info_gatherv()
Definition sto_tool.h:83
structure to distribute calculation among processors
Definition sto_tool.h:38
parallel_distribution(const int &num_all, const int &np, const int myrank)
Definition sto_tool.h:39
int start
Definition sto_tool.h:56
int num_per
Definition sto_tool.h:57