1#ifndef ABACUS_LR_STATE_OVLP_TEST_H
2#define ABACUS_LR_STATE_OVLP_TEST_H
7#include <gtest/gtest.h>
17std::vector<T> overlap_block(
const std::vector<T>& full,
int bands,
int start,
int count)
19 std::vector<T> block(count * count);
20 for (
int i = 0;
i < count; ++
i)
21 for (
int j = 0; j < count; ++j)
22 block[i * count + j] = full[(
start + i) * bands +
start + j];
29 const int block_size = grid.
nb();
30 target.
set(rows, cols, block_size, grid.
ictxt());
39 std::vector<T> local(layout.
size(),
T(0));
40 const int columns = layout.
ncglb();
41 for (
int col = 0; col < layout.
ncloc(); ++col)
43 const int global_col = layout.
icglb(col);
44 for (
int row = 0; row < layout.
nrloc(); ++row)
46 const int global_row = layout.
irglb(row);
47 local[col * layout.
nrloc() + row] = full[global_row * columns + global_col];
60std::complex<double> conjugate(std::complex<double> value)
62 return std::conj(value);
66std::vector<T> reference_mo(
const std::vector<T>& old,
const std::vector<double>& ao,
67 const std::vector<T>& current,
int naos,
int bands)
69 std::vector<T> result(bands * bands,
T(0));
70 for (
int i = 0;
i < bands; ++
i)
72 for (
int j = 0; j < bands; ++j)
74 for (
int mu = 0; mu < naos; ++mu)
76 for (
int nu = 0; nu < naos; ++nu)
78 result[
i * bands + j] += conjugate(old[i * naos + mu])
79 * ao[mu * naos + nu] * current[j * naos + nu];
88std::vector<T> reference_projection(
const std::vector<T>& previous,
89 const std::vector<T>& overlap,
int no,
int nv)
91 const int bands =
no + nv;
92 std::vector<T> result(no * nv,
T(0));
93 for (
int j = 0; j <
no; ++j)
95 for (
int b = 0; b < nv; ++b)
97 for (
int i = 0;
i <
no; ++
i)
99 for (
int a = 0; a < nv; ++a)
101 result[j * nv + b] += overlap[
i * bands + j] * previous[
i * nv + a]
102 * conjugate(overlap[(no + a) * bands + no + b]);
113 const int columns = layout.
ncglb();
114 const int count = layout.
nrglb() * columns;
115 std::vector<T> result(count,
T(0));
116 EXPECT_EQ(local.size(), layout.
size());
117 for (
int col = 0; col < layout.
ncloc(); ++col)
119 const int global_col = layout.
icglb(col);
120 for (
int row = 0; row < layout.
nrloc(); ++row)
122 const int global_row = layout.
irglb(row);
123 result[global_row * columns + global_col] = local[col * layout.
nrloc() + row];
131std::vector<T> transform_for_test(
const std::vector<T>& old,
const std::vector<double>& ao,
132 const std::vector<T>& current,
int naos,
int bands,
int start,
int count,
int block_size)
136 pc.
init(naos, bands, block_size, MPI_COMM_WORLD,
false);
142 setup(ps, naos, naos, pc);
143 setup(po, count, count, pc);
144 std::vector<T> old_rows(old.size());
145 std::vector<T> current_rows(current.size());
146 for (
int i = 0;
i < naos; ++
i)
148 for (
int band = 0; band < bands; ++band)
150 old_rows[
i * bands + band] = old[band * naos +
i];
151 current_rows[
i * bands + band] = current[band * naos +
i];
154 const std::vector<T> typed_ao(ao.begin(), ao.end());
155 const std::vector<T> local_old = scatter(old_rows, pc);
156 const std::vector<T> local_current = scatter(current_rows, pc);
157 const std::vector<T> local_ao = scatter(typed_ao, ps);
159 return gather(actual, po);
163std::vector<T>
project(
const std::vector<T>& previous,
const std::vector<T>& overlap,
int no,
int nv)
165 const int bands =
no + nv;
168 po.
init(bands, bands, 1, MPI_COMM_WORLD,
false);
173 setup(px, nv, no, po);
174 std::vector<T> previous_rows(previous.size());
175 for (
int i = 0;
i <
no; ++
i)
177 for (
int a = 0; a < nv; ++a)
179 previous_rows[a *
no +
i] = previous[
i * nv + a];
182 const std::vector<T> local_previous = scatter(previous_rows, px);
185 setup(
pi, no, no, po);
186 setup(pv, nv, nv, po);
187 const std::vector<T> occupied = overlap_block(overlap, bands, 0, no);
188 const std::vector<T> virtuals = overlap_block(overlap, bands, no, nv);
189 const std::vector<T> local_occupied = scatter(occupied,
pi);
190 const std::vector<T> local_virtuals = scatter(virtuals, pv);
192 const std::vector<T> rows = gather(actual, px);
193 std::vector<T> result(previous.size());
194 for (
int i = 0;
i <
no; ++
i)
196 for (
int a = 0; a < nv; ++a)
198 result[
i * nv + a] = rows[a *
no +
i];
205void check_mo(
int naos,
int bands,
T phase,
int start,
int count,
int block_size)
207 std::vector<double> ao(naos * naos);
208 std::vector<T> old(naos * bands);
209 std::vector<T> current(naos * bands);
210 for (
int i = 0;
i < naos; ++
i)
212 for (
int j = 0; j < naos; ++j)
214 ao[
i * naos + j] = (2 *
i - j + 1) / 7.0;
216 for (
int band = 0; band < bands; ++band)
218 old[band * naos +
i] = phase * ((
i + band + 1) / 11.0);
219 current[band * naos +
i] =
T((i - 2 * band + 2) / 13.0);
222 const std::vector<T> actual = transform_for_test(old, ao, current, naos, bands,
start, count, block_size);
223 const std::vector<T> full = reference_mo(old, ao, current, naos, bands);
224 const std::vector<T> expected = overlap_block(full, bands,
start, count);
225 ASSERT_EQ(actual.size(), expected.size());
226 for (std::size_t i = 0;
i < actual.size(); ++
i)
228 EXPECT_NEAR(std::abs(actual[i] - expected[i]), 0.0, 1e-13);
232void check_projection(
int no,
int nv,
T phase,
int block_size)
234 const int bands =
no + nv;
237 po.
init(bands, bands, block_size, MPI_COMM_WORLD,
false);
242 setup(px, nv, no, po);
243 std::vector<T> overlap(bands * bands);
244 std::vector<T> previous(no * nv);
245 for (
int i = 0;
i < bands; ++
i)
247 for (
int j = 0; j < bands; ++j)
249 overlap[
i * bands + j] =
T((i - 2 * j + 1) / 17.0) + phase * ((
i + j + 1) / 19.0);
252 for (
int i = 0;
i <
no * nv; ++
i)
254 previous[
i] = phase * ((
i + 1) / 23.0);
257 std::vector<T> previous_rows(previous.size());
258 for (
int i = 0;
i <
no; ++
i)
260 for (
int a = 0; a < nv; ++a)
262 previous_rows[a *
no +
i] = previous[
i * nv + a];
265 const std::vector<T> local_previous = scatter(previous_rows, px);
268 setup(
pi, no, no, po);
269 setup(pv, nv, nv, po);
270 const std::vector<T> occupied = overlap_block(overlap, bands, 0, no);
271 const std::vector<T> virtuals = overlap_block(overlap, bands, no, nv);
272 const std::vector<T> local_occupied = scatter(occupied,
pi);
273 const std::vector<T> local_virtuals = scatter(virtuals, pv);
275 const std::vector<T> expected = reference_projection(previous, overlap, no, nv);
276 std::vector<T> expected_rows(expected.size());
277 for (
int i = 0;
i <
no; ++
i)
279 for (
int a = 0; a < nv; ++a)
281 expected_rows[a *
no +
i] = expected[
i * nv + a];
284 const std::vector<T> local_expected = scatter(expected_rows, px);
285 ASSERT_EQ(actual.size(), local_expected.size());
286 for (std::size_t i = 0;
i < actual.size(); ++
i)
290 const double scaled_tolerance = 1e-12 * std::max(1.0, std::abs(local_expected[i]));
291 const double tolerance = block_size == 1 ? 1e-13 : scaled_tolerance;
292 EXPECT_NEAR(std::abs(actual[i] - local_expected[i]), 0.0, tolerance);
Parallel block-cyclic matrix distribution.
Definition parallel_blkcyc.h:25
int irglb(const int irloc) const
Definition parallel_blkcyc.h:88
int ncloc() const
Definition parallel_blkcyc.h:40
int set(const int nrglb, const int ncglb, const int nb, const int ictxt)
Definition parallel_blkcyc.cpp:230
int ncglb() const
Definition parallel_blkcyc.cpp:86
int nrloc() const
Definition parallel_blkcyc.h:35
int icglb(const int icloc) const
Definition parallel_blkcyc.h:93
int nb() const
Definition parallel_blkcyc.h:53
int ictxt() const
Definition parallel_blkcyc.h:130
std::size_t size() const
Definition parallel_blkcyc.h:48
int nrglb() const
Definition parallel_blkcyc.cpp:75
void set_serial(const int nrglb, const int ncglb)
Definition parallel_blkcyc.cpp:239
int init(const int nrglb, const int ncglb, const int nb, const MPI_Comm comm, const bool swap_grid)
Definition parallel_blkcyc.cpp:217
#define T
Definition exp.cpp:237
std::vector< T > project_reference_dist(const std::vector< T > &previous, const std::vector< T > &occupied_overlap, const std::vector< T > &virtual_overlap, const Parallel_Blkcyclic &pi, const Parallel_Blkcyclic &pv, const Parallel_Blkcyclic &px)
Definition state_ovlp.cpp:232
std::vector< T > mo_overlap_dist(const std::vector< T > &old_coefficients, const std::vector< T > &ao, const std::vector< T > ¤t_coefficients, const Parallel_Blkcyclic &pc, const Parallel_Blkcyclic &ps, const Parallel_Blkcyclic &po, const int first_band)
Definition state_ovlp.cpp:159
int4 i[880]
Definition sincos.cpp:28
void reduce_all(T &object)
reduce in all process
Definition depend_mock.cpp:14
str project
Definition conf.py:22
@ no
Definition operator.h:13
iclock::time_point start
Definition test_partition.cpp:22
const double pi
Definition test_radial.cpp:22