10 std::vector<std::complex<double>>
hmatrix;
19 void readh(std::ifstream& inf, std::vector<double>& hm)
27 for (
int i = 0;i <
npw;i++)
29 for (
int j = i;j <
npw;j++)
31 inf >> hm[i *
npw + j];
32 if (i != j) { hm[j *
npw + i] = hm[i *
npw + j]; }
37 void readh(std::ifstream& inf, std::vector<std::complex<double>>& hm)
45 for(
int i=0;i<
npw;i++)
47 for(
int j=i;j<
npw;j++)
49 inf >> hm[i *
npw + j];
50 if (i != j) {hm[j *
npw + i] =
conj(hm[i *
npw + j]);}
52 double real = hm[i *
npw + i].real();
53 hm[i *
npw + i] = std::complex<double> {real,0.0};
57 void readh(std::ifstream &inf, std::vector<std::complex<float>> &hm)
65 for(
int i=0;i<
npw;i++)
67 for(
int j=i;j<
npw;j++)
69 inf >> hm[i *
npw + j];
70 if (i != j) {hm[j *
npw + i] =
conj(hm[i *
npw + j]);}
72 float real = hm[i *
npw + i].real();
73 hm[i *
npw + i] = std::complex<float> {real,0.0};
80 int nprocs=1, mypnum=0;
82 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
83 MPI_Comm_rank(MPI_COMM_WORLD, &mypnum);
92 for(
int j=1;j<nprocs;j++)
94 if (std::is_same<T, double>::value) {
95 MPI_Send(&(
psi[start_point]),
npw_local[j],MPI_DOUBLE,j,0,MPI_COMM_WORLD);
96 }
else if(std::is_same<
T, std::complex<double>>::value) {
97 MPI_Send(&(
psi[start_point]),
npw_local[j],MPI_DOUBLE_COMPLEX,j,0,MPI_COMM_WORLD);
98 }
else if (std::is_same<T, float>::value) {
99 MPI_Send(&(
psi[start_point]),
npw_local[j], MPI_FLOAT, j, 0, MPI_COMM_WORLD);
100 }
else if (std::is_same<
T, std::complex<float>>::value) {
101 MPI_Send(&(
psi[start_point]),
npw_local[j], MPI_C_FLOAT_COMPLEX, j, 0, MPI_COMM_WORLD);
108 int recv_len = mypnum < (
npw%nprocs) ?
npw/nprocs + 1 :
npw/nprocs;
109 if (std::is_same<T, double>::value) {
110 MPI_Recv(psi_local,
npw_local[mypnum],MPI_DOUBLE,0,0,MPI_COMM_WORLD, MPI_STATUS_IGNORE);
111 }
else if(std::is_same<
T, std::complex<double>>::value) {
112 MPI_Recv(psi_local,
npw_local[mypnum], MPI_DOUBLE_COMPLEX, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
113 }
else if (std::is_same<T, float>::value) {
114 MPI_Recv(psi_local,
npw_local[mypnum], MPI_FLOAT, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
115 }
else if (std::is_same<
T, std::complex<float>>::value) {
116 MPI_Recv(psi_local,
npw_local[mypnum], MPI_C_FLOAT_COMPLEX, 0, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE);
122 template void divide_psi<std::complex<double>>(std::complex<double>*
psi, std::complex<double>* psi_local);
123 template void divide_psi<std::complex<float>>(std::complex<float>*
psi, std::complex<float>* psi_local);
128 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
129 MPI_Comm_rank(MPI_COMM_WORLD, &mypnum);
130 for(
int i=0;i<nprocs;i++)
142 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
143 MPI_Comm_rank(MPI_COMM_WORLD, &mypnum);
145 int npw =
psi.get_nbasis();
146 int nbands =
psi.get_nbands();
147 int nk =
psi.get_nk();
153 for(
int i=0;i<
npw;i++)
158 for(
int k=0;k<nk;k++)
216 for(
int i=0;i<
nband;i++)
234 std::default_random_engine e(1000);
235 std::uniform_int_distribution<unsigned> u(
min,
max);
236 for (
int i = 0;i <
npw;i++)
256 hmatrix.resize(npw * npw);
259 std::default_random_engine e(100);
260 std::uniform_int_distribution<unsigned> u(
min,
max);
261 if (sparsity < 0) { sparsity = 0;
263 if (sparsity > 10) { sparsity = 10;
265 for (
int i = 0;i < npw;i++)
267 for (
int j = 0;j <= i;j++)
269 double mincoef = 0.0;
270 double realp = pow(-1.0, u(e) % 2) *
static_cast<double>(u(e)) /
max;
271 if (
int(u(e) % 10) > int(sparsity - 1)) { mincoef = 1.0;
274 hmatrix[i * npw + j] = realp;
276 hmatrix[j * npw + i] = hmatrix[i * npw + j] = mincoef * realp;
284 hmatrix.resize(npw * npw);
287 std::default_random_engine e(100);
288 std::uniform_int_distribution<unsigned> u(
min,
max);
289 if (sparsity < 0) { sparsity = 0;
291 if (sparsity > 10) { sparsity = 10;
293 for (
int i = 0;i < npw;i++)
295 for (
int j = 0;j <= i;j++)
297 double mincoef = 0.0;
298 double realp = pow(-1.0, u(e) % 2) *
static_cast<double>(u(e)) /
max;
300 if (
int(u(e) % 10) > int(sparsity - 1)) { mincoef = 1.0;
304 hmatrix[i * npw + j] = std::complex<double>{ realp,0.0 };
309 hmatrix[i * npw + j] = mincoef * std::complex<double>{ realp, 0.0 };
310 hmatrix[j * npw + i] =
conj(hmatrix[i * npw + j]);
318 hmatrix.resize(npw * npw);
321 std::default_random_engine e(100);
322 std::uniform_int_distribution<unsigned> u(
min,
max);
323 if (sparsity < 0) { sparsity = 0;
325 if (sparsity > 10) { sparsity = 10;
327 for (
int i = 0;i < npw;i++)
329 for (
int j = 0;j <= i;j++)
332 float realp = pow(-1.0, u(e) % 2) *
static_cast<float>(u(e)) /
max;
333 if (
int(u(e) % 10) > int(sparsity - 1)) { mincoef = 1.0;
337 hmatrix[i * npw + j] = std::complex<float>{ realp,0.0 };
341 hmatrix[i * npw + j] = mincoef * std::complex<float>{ realp, 0.0 };
342 hmatrix[j * npw + i] =
conj(hmatrix[i * npw + j]);
352 psimatrix.resize(nband * npw);
353 std::default_random_engine e(10);
354 std::uniform_int_distribution<unsigned> u(
min,
max);
355 for (
int i = 0;i < nband;i++) {
356 for (
int j = 0;j < npw;j++) {
357 psimatrix[i * npw + j] = pow(-1.0, u(e) % 2) *
static_cast<double>(u(e)) /
max;
366 psimatrix.resize(nband * npw);
367 std::default_random_engine e(10);
368 std::uniform_int_distribution<unsigned> u(
min,
max);
369 for (
int i = 0;i < nband;i++)
371 for (
int j = 0;j < npw;j++)
373 double realp = pow(-1.0, u(e) % 2) *
static_cast<double>(u(e)) /
max;
376 psimatrix[i * npw + j] = std::complex<double>{ realp,imagp };
385 psimatrix.resize(nband * npw);
386 std::default_random_engine e(10);
387 std::uniform_int_distribution<unsigned> u(
min,
max);
388 for (
int i = 0;i < nband;i++)
390 for (
int j = 0;j < npw;j++)
392 float realp = pow(-1.0, u(e) % 2) *
static_cast<float>(u(e)) /
max;
394 psimatrix[i * npw + j] = std::complex<float>{ realp,imagp };
410 const int nbands)
const
412 for (
size_t i = 0; i < static_cast<size_t>(nbands * nrow); i++)
420 std::complex<double>* spsi,
423 const int nbands)
const
425 for (
size_t i = 0; i < static_cast<size_t>(nbands * nrow); i++)
433 std::complex<float>* spsi,
436 const int nbands)
const
438 for (
size_t i = 0; i < static_cast<size_t>(nbands * nrow); i++)
452 if(this->
hpsi !=
nullptr)
455 this->
hpsi =
nullptr;
465 const int ngk_ik = 0,
473 const double* tmpsi_in,
476 const bool is_first_node)
const
478 int nprocs = 1, mypnum = 0;
480 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
481 MPI_Comm_rank(MPI_COMM_WORLD, &mypnum);
485 for (
int m = 0; m < nbands; m++)
507 const std::complex<double>* tmpsi_in,
508 std::complex<double>* tmhpsi,
510 const bool is_first_node)
const
512 int nprocs = 1, mypnum = 0;
514 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
515 MPI_Comm_rank(MPI_COMM_WORLD, &mypnum);
518 std::complex<double>* hpsi0 =
new std::complex<double>[
DIAGOTEST::npw];
519 for (
int m = 0; m < nbands; m++)
530 DIAGOTEST::divide_psi<std::complex<double>>(hpsi0, tmhpsi);
541 const std::complex<float>* tmpsi_in,
542 std::complex<float>* tmhpsi,
544 const bool is_first_node)
const
546 int nprocs = 1, mypnum = 0;
548 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
549 MPI_Comm_rank(MPI_COMM_WORLD, &mypnum);
552 std::complex<float>* hpsi0 =
new std::complex<float>[
DIAGOTEST::npw];
553 for (
int m = 0; m < nbands; m++)
564 DIAGOTEST::divide_psi<std::complex<float>>(hpsi0, tmhpsi);
#define min(x, y)
Definition branred.cpp:18
#define max(x, y)
Definition branred.cpp:17
Definition diago_mock.h:173
int npw
Definition diago_mock.h:243
std::vector< T > psimatrix
Definition diago_mock.h:246
Real * precond()
Definition diago_mock.h:208
std::vector< T > hamilt()
Definition diago_mock.h:209
HPsi()
Definition diago_mock.h:196
void create(int nbd, int npw, int sparsity=7)
Definition diago_mock.h:199
int nband
Definition diago_mock.h:244
int sparsity
Definition diago_mock.h:250
std::vector< T > hmatrix
Definition diago_mock.h:245
void genprecondition()
Definition diago_mock.h:231
HPsi(int nband, int npw, int sparsity=7)
Definition diago_mock.h:194
~HPsi()
Definition diago_mock.h:197
int max
Definition diago_mock.h:249
typename GetTypeReal< T >::type Real
Definition diago_mock.h:192
Real * precondition
Definition diago_mock.h:247
int min
Definition diago_mock.h:248
psi::Psi< T > psi()
Definition diago_mock.h:211
Special pw_basis class. It includes different k-points.
Definition pw_basis_k.h:57
Definition diago_mock.h:449
virtual void act(const int nbands, const int nbasis, const int npol, const T *tmpsi_in, T *tmhpsi, const int ngk_ik=0, const bool is_first_node=false) const
~OperatorMock()
Definition diago_mock.h:450
Definition structure_factor.h:11
Definition potential_new.h:48
Definition hamilt_pw.h:18
void updateHk(const int ik) override
for target K point, update consequence of hPsi() and matrix()
Definition hamilt_pw.cpp:148
~HamiltPW()
Definition hamilt_pw.cpp:139
HamiltPW(elecstate::Potential *pot_in, ModulePW::PW_Basis_K *wfc_basis, K_Vectors *p_kv, pseudopot_cell_vnl *nlpp, const UnitCell *ucell)
Definition hamilt_pw.cpp:21
void sPsi(const T *psi_in, T *spsi, const int nrow, const int npw, const int nbands) const override
Definition hamilt_pw.cpp:236
psi::Psi< T, Device > * hpsi
Definition operator.h:112
bool is_first_node
Definition operator.h:109
Definition VNL_in_pw.h:21
void resize(const int nks_in, const int nbands_in, const int nbasis_in)
Definition psi.cpp:254
T * get_pointer() const
Definition psi.cpp:272
void fix_k(const int ik) const
Definition psi.cpp:364
#define T
Definition exp.cpp:237
Definition diago_mock.h:7
std::vector< std::complex< float > > hmatrix_f
Definition diago_mock.h:12
std::vector< std::complex< double > > hmatrix
Definition diago_mock.h:10
int npw
Definition diago_mock.h:16
int h_nc
Definition diago_mock.h:15
void cal_division(int &npw)
Definition diago_mock.h:125
void divide_psi(T *psi, T *psi_local)
Definition diago_mock.h:78
void readh(std::ifstream &inf, std::vector< double > &hm)
Definition diago_mock.h:19
std::vector< double > hmatrix_d
Definition diago_mock.h:8
int * npw_local
Definition diago_mock.h:17
std::vector< std::complex< float > > hmatrix_local_f
Definition diago_mock.h:13
std::vector< double > hmatrix_local_d
Definition diago_mock.h:9
std::vector< std::complex< double > > hmatrix_local
Definition diago_mock.h:11
template void divide_psi< double >(double *psi, double *psi_local)
int h_nr
Definition diago_mock.h:14
void divide_hpsi(psi::Psi< T > &psi, psi::Psi< T > &psi_local, std::vector< T > &hmatrix, std::vector< T > &hmatrix_local)
Definition diago_mock.h:139
void reduce_pool(T &object)
Definition depend_mock.cpp:15
double conj(double a)
Definition operator_lr_hxc.cpp:14
T type
Definition macros.h:8