HILA
Loading...
Searching...
No Matches
test_gathers.cpp
1//////////////////////////////////////////////////////////////////////////////
2/// Test the standard gather here
3//////////////////////////////////////////////////////////////////////////////
4
5#include "hila.h"
6
7void gather_test() {
8
9 int64_t s = 0;
10 onsites(ALL) {
11 s += 1;
12 }
13
14 if (s != lattice.volume()) {
15 hila::out0 << " Reduction test error! Sum " << s << " should be "
16 << lattice.volume() << '\n';
18 }
19
20
21 foralldir (d) {
22
23 CoordinateVector dif1 = 0, dif2 = 0;
25
26 onsites(ALL) {
27 f1[X] = X.coordinates();
28 f2[X] = (X.coordinates() + d).mod(lattice.size());
29 }
30
31 onsites(ALL) {
32 dif1 += abs(f1[X + d] - f2[X]);
33 dif2 += abs(f1[X] - f2[X - d]);
34 }
35
36 if (dif1.squarenorm() != 0) {
37 hila::out0 << " Std up-gather test error! Node " << hila::myrank()
38 << " direction " << (unsigned)d << " dif1 " << dif1 << '\n';
40 }
41
42 if (dif2.squarenorm() != 0) {
43 hila::out0 << " Std down-gather test error! Node " << hila::myrank()
44 << " direction " << (unsigned)d << " dif2 " << dif2 << '\n';
46 }
47
48#if 0 && defined(SPECIAL_BOUNDARY_CONDITIONS)
49 // test antiperiodic b.c. to one direction
50 if (next_direction(d) == NDIM) {
51 f2.set_boundary_condition(d, hila::bc::ANTIPERIODIC);
52
53 onsites(ALL) {
54 if (X.coordinate(d) == lattice.size(d) - 1)
55 f2[X] = -f1[X];
56 else
57 f2[X] = f1[X];
58 }
59
60 dif1 = 0;
61 onsites(ALL) { dif1 += f1[X] - f2[X - d]; }
62
63 if (dif1 != 0) {
64 hila::out0 << " Antiperiodic up-gather test error! Node " << hila::myrank()
65 << " direction " << (unsigned)d << '\n';
67 }
68 }
69#endif
70 }
71}
72
73void test_std_gathers() {
74 // gather_test<int>();
75 auto t0 = hila::gettime();
76
77 gather_test();
78
79#if defined(CUDA) || defined(HIP)
80 gpuMemPoolPurge();
81#endif
82
83 hila::out0 << "Communication tests done - time " << hila::gettime() - t0 << "s\n";
84
85 print_dashed_line();
86
87 if (hila::myrank() == 0)
88 hila::out.flush();
89}
The field class implements the standard methods for accessing Fields. Hilapp replaces the parity acce...
Definition field.h:61
void set_boundary_condition(Direction dir, hila::bc bc)
Set the boundary condition in a given Direction (periodic or antiperiodic)
Definition field.h:579
hila::arithmetic_type< T > squarenorm() const
Calculate square norm - sum of squared elements.
Definition matrix.h:1117
T abs(const Complex< T > &a)
Return absolute value of Complex number.
Definition cmplx.h:1187
#define foralldir(d)
Macro to loop over (all) Direction(s)
Definition coordinates.h:78
constexpr Parity ALL
bit pattern: 011
int myrank()
rank of this node
Definition com_mpi.cpp:235
std::ostream out
this is our default output file stream
std::ostream out0
This writes output only from main process (node 0)
double gettime()
Definition timing.cpp:163
void terminate(int status)