26void readh(std::ifstream &inf, std::vector<double> &hm)
34 for (
int i = 0; i <
npw; i++)
36 for (
int j = i; j <
npw; j++)
38 inf >> hm[i *
npw + j];
41 hm[j *
npw + i] = hm[i *
npw + j];
47void readh(std::ifstream &inf, std::vector<std::complex<double>> &hm)
55 for (
int i = 0; i <
npw; i++)
57 for (
int j = i; j <
npw; j++)
59 inf >> hm[i *
npw + j];
65 double real = hm[i *
npw + i].real();
66 hm[i *
npw + i] = std::complex<double>{real, 0.0};
70void readh(std::ifstream &inf, std::vector<std::complex<float>> &hm)
78 for (
int i = 0; i <
npw; i++)
80 for (
int j = i; j <
npw; j++)
82 inf >> hm[i *
npw + j];
88 float real = hm[i *
npw + i].real();
89 hm[i *
npw + i] = std::complex<float>{real, 0.0};
95 int nprocs = 1, mypnum = 0;
97 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
98 MPI_Comm_rank(MPI_COMM_WORLD, &mypnum);
105 psi_local[j] =
psi[j];
109 for (
int j = 1; j < nprocs; j++)
111 if (std::is_same<T, double>::value)
121 else if (std::is_same<
T, std::complex<double>>::value)
131 else if (std::is_same<T, float>::value)
141 else if (std::is_same<
T, std::complex<float>>::value)
156 int recv_len = mypnum < (
npw % nprocs) ?
npw / nprocs + 1 :
npw / nprocs;
157 if (std::is_same<T, double>::value)
168 else if (std::is_same<
T, std::complex<double>>::value)
179 else if (std::is_same<T, float>::value)
190 else if (std::is_same<
T, std::complex<float>>::value)
211 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
212 MPI_Comm_rank(MPI_COMM_WORLD, &mypnum);
213 for (
int i = 0; i < nprocs; i++)
215 if (i <
npw % nprocs)
234 MPI_Comm_size(MPI_COMM_WORLD, &nprocs);
235 MPI_Comm_rank(MPI_COMM_WORLD, &mypnum);
237 int npw =
psi.get_nbasis();
238 int nbands =
psi.get_nbands();
239 int nk =
psi.get_nk();
245 for (
int i = 0; i <
npw; i++)
250 for (
int k = 0; k < nk; k++)
263template <
typename T>
class HPsi
317 for (
int i = 0; i <
nband; i++)
319 for (
int j = 0; j <
npw; j++)
337 std::default_random_engine e(1000);
338 std::uniform_int_distribution<unsigned> u(
min,
max);
339 for (
int i = 0; i <
npw; i++)
361 std::default_random_engine e(100);
362 std::uniform_int_distribution<unsigned> u(
min,
max);
371 for (
int i = 0; i <
npw; i++)
373 for (
int j = 0; j <= i; j++)
375 double mincoef = 0.0;
376 double realp = pow(-1.0, u(e) % 2) *
static_cast<double>(u(e)) /
max;
377 if (
int(u(e) % 10) >
int(
sparsity - 1))
397 std::default_random_engine e(100);
398 std::uniform_int_distribution<unsigned> u(
min,
max);
407 for (
int i = 0; i <
npw; i++)
409 for (
int j = 0; j <= i; j++)
411 double mincoef = 0.0;
412 double realp = pow(-1.0, u(e) % 2) *
static_cast<double>(u(e)) /
max;
414 if (
int(u(e) % 10) >
int(
sparsity - 1))
420 hmatrix[i *
npw + j] = std::complex<double>{realp, 0.0};
425 hmatrix[i *
npw + j] = mincoef * std::complex<double>{realp, 0.0};
436 std::default_random_engine e(100);
437 std::uniform_int_distribution<unsigned> u(
min,
max);
446 for (
int i = 0; i <
npw; i++)
448 for (
int j = 0; j <= i; j++)
451 float realp = pow(-1.0, u(e) % 2) *
static_cast<float>(u(e)) /
max;
452 if (
int(u(e) % 10) >
int(
sparsity - 1))
458 hmatrix[i *
npw + j] = std::complex<float>{realp, 0.0};
462 hmatrix[i *
npw + j] = mincoef * std::complex<float>{realp, 0.0};
473 std::default_random_engine e(10);
474 std::uniform_int_distribution<unsigned> u(
min,
max);
475 for (
int i = 0; i <
nband; i++)
477 for (
int j = 0; j <
npw; j++)
479 psimatrix[i *
npw + j] = pow(-1.0, u(e) % 2) *
static_cast<double>(u(e)) /
max;
488 std::default_random_engine e(10);
489 std::uniform_int_distribution<unsigned> u(
min,
max);
490 for (
int i = 0; i <
nband; i++)
492 for (
int j = 0; j <
npw; j++)
494 double realp = pow(-1.0, u(e) % 2) *
static_cast<double>(u(e)) /
max;
497 psimatrix[i *
npw + j] = std::complex<double>{realp, imagp};
506 std::default_random_engine e(10);
507 std::uniform_int_distribution<unsigned> u(
min,
max);
508 for (
int i = 0; i <
nband; i++)
510 for (
int j = 0; j <
npw; j++)
512 float realp = pow(-1.0, u(e) % 2) *
static_cast<float>(u(e)) /
max;
514 psimatrix[i *
npw + j] = std::complex<float>{realp, imagp};
550 const int nvec)
const override
554 MPI_Comm_rank(MPI_COMM_WORLD, &mypnum);
559 std::vector<T> hx_full(npw);
560 for (
int m = 0; m < nvec; m++)
562 for (
int i = 0; i < npw; i++)
565 for (
int j = 0; j < ncol; j++)
579 const int nvec)
const override
581 std::copy(x, x +
static_cast<size_t>(ld) * nvec, sx);
Definition diago_mock.h:264
int npw
Definition diago_mock.h:346
std::vector< T > psimatrix
Definition diago_mock.h:349
Real * precond()
Definition diago_mock.h:306
std::vector< T > hamilt()
Definition diago_mock.h:307
HPsi()
Definition diago_mock.h:292
void create(int nbd, int npw, int sparsity=7)
Definition diago_mock.h:295
int nband
Definition diago_mock.h:347
int sparsity
Definition diago_mock.h:353
std::vector< T > hmatrix
Definition diago_mock.h:348
void genprecondition()
Definition diago_mock.h:334
HPsi(int nband, int npw, int sparsity=7)
Definition diago_mock.h:286
~HPsi()
Definition diago_mock.h:293
int max
Definition diago_mock.h:352
typename GetTypeReal< T >::type Real
Definition diago_mock.h:283
Real * precondition
Definition diago_mock.h:350
int min
Definition diago_mock.h:351
psi::Psi< T > psi()
Definition diago_mock.h:309
Definition diago_mock.h:542
void hpsi(const T *x, T *hx, const int ld, const int nvec) const override
hx[:, 0:nvec) = H * x[:, 0:nvec), both with leading dimension ld
Definition diago_mock.h:546
void update_k(const int ik) override
switch H and S to k point ik; must precede hpsi()/spsi() for that k
Definition diago_mock.h:544
void spsi(const T *x, T *sx, const int ld, const int nvec) const override
sx[:, 0:nvec) = S * x[:, 0:nvec), both with leading dimension ld
Definition diago_mock.h:575
What an iterative eigensolver needs from the generalized eigenproblem H x = e S x: the ability to app...
Definition hs_operator.h:24
void resize(const int nks_in, const int nbands_in, const int nbasis_in)
Definition psi.cpp:249
T * get_pointer() const
Definition psi.cpp:267
void fix_k(const int ik) const
Definition psi.cpp:359
#define T
Definition exp.cpp:237
Definition diago_mock.h:14
std::vector< std::complex< float > > hmatrix_f
Definition diago_mock.h:19
std::vector< std::complex< double > > hmatrix
Definition diago_mock.h:17
int npw
Definition diago_mock.h:23
int h_nc
Definition diago_mock.h:22
void cal_division(int &npw)
Definition diago_mock.h:208
void divide_psi(T *psi, T *psi_local)
Definition diago_mock.h:93
void readh(std::ifstream &inf, std::vector< double > &hm)
Definition diago_mock.h:26
std::vector< double > hmatrix_d
Definition diago_mock.h:15
int * npw_local
Definition diago_mock.h:24
std::vector< std::complex< float > > hmatrix_local_f
Definition diago_mock.h:20
std::vector< double > hmatrix_local_d
Definition diago_mock.h:16
std::vector< double > & hmatrix_local_of< double >()
Definition diago_mock.h:528
std::vector< std::complex< double > > hmatrix_local
Definition diago_mock.h:18
template void divide_psi< double >(double *psi, double *psi_local)
int h_nr
Definition diago_mock.h:21
std::vector< T > & hmatrix_local_of()
the process-local slice of the test matrix for each scalar type
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:227
void reduce_pool(T &object)
Definition depend_mock.cpp:15
Definition diag_lcao.h:14
double conj(double a)
Definition operator_lr_hxc.cpp:15
T type
Definition macros.h:8