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 " << lattice.volume()
16 << '\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() << " direction "
38 << hila::prettyprint(d) << " dif1 " << dif1 << '\n';
40 }
41
42 if (dif2.squarenorm() != 0) {
43 hila::out0 << " Std down-gather test error! Node " << hila::myrank() << " direction "
44 << hila::prettyprint(d) << " dif2 " << dif2 << '\n';
46 }
47
48 onsites(EVEN) {
49 dif1 += abs(f1[X + d] - f2[X]);
50 dif2 += abs(f1[X] - f2[X - d]);
51 }
52
53 if (dif1.squarenorm() != 0) {
54 hila::out0 << " EVEN parity up-gather test error! Node " << hila::myrank()
55 << " direction " << hila::prettyprint(d) << " dif1 " << dif1 << '\n';
57 }
58
59 if (dif2.squarenorm() != 0) {
60 hila::out0 << " EVEN parity down-gather test error! Node " << hila::myrank()
61 << " direction " << hila::prettyprint(d) << " dif2 " << dif2 << '\n';
63 }
64
65
66#if 0 && defined(SPECIAL_BOUNDARY_CONDITIONS)
67 // test antiperiodic b.c. to one direction
68 if (next_direction(d) == NDIM) {
69 f2.set_boundary_condition(d, hila::bc::ANTIPERIODIC);
70
71 onsites(ALL) {
72 if (X.coordinate(d) == lattice.size(d) - 1)
73 f2[X] = -f1[X];
74 else
75 f2[X] = f1[X];
76 }
77
78 dif1 = 0;
79 onsites(ALL) { dif1 += f1[X] - f2[X - d]; }
80
81 if (dif1 != 0) {
82 hila::out0 << " Antiperiodic up-gather test error! Node " << hila::myrank()
83 << " direction " << (unsigned)d << '\n';
85 }
86 }
87#endif
88 }
89}
90
91void test_std_gathers() {
92 // gather_test<int>();
93 auto t0 = hila::gettime();
94
95#ifdef MPI_BENCHMARK_TEST
96 hila::out0 << "MPI_BENCHMARK_TEST defined, not doing communication tests!\n";
97 return;
98#endif
99
100 gather_test();
101
102#if defined(CUDA) || defined(HIP)
103 gpuMemPoolPurge();
104#endif
105
106 if (lattice.is_base()) {
107 hila::out0 << "Communication tests done - time " << hila::gettime() - t0 << "s\n";
108
109 hila::print_dashed_line();
110 }
111
112 if (hila::myrank() == 0)
113 hila::out.flush();
114}
The field class implements the standard methods for accessing Fields. Hilapp replaces the parity acce...
Definition field.h:62
void set_boundary_condition(Direction dir, hila::bc bc)
Set the boundary condition in a given Direction (periodic or antiperiodic)
Definition field.h:579
int size(Direction d) const
lattice.size() -> CoordinateVector or lattice.size(d) -> int returns the dimensions of the lattice,...
Definition lattice.h:433
bool is_base() const
lattice.is_base() is used to check if the current lattice is the original one, i.e....
Definition lattice.h:605
int64_t volume() const
lattice.volume() returns lattice volume Can be used inside onsites()-loops
Definition lattice.h:424
hila::arithmetic_type< T > squarenorm() const
Calculate square norm - sum of squared elements.
Definition matrix.h:1209
T abs(const Complex< T > &a)
Return absolute value of Complex number.
Definition cmplx.h:1266
constexpr Parity EVEN
bit pattern: 001
#define foralldir(d)
Macro to loop over (all) Direction(s)
Definition coordinates.h:80
constexpr Parity ALL
bit pattern: 011
int myrank()
rank of this node
Definition com_mpi.cpp:237
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:167
void terminate(int status)