-
Notifications
You must be signed in to change notification settings - Fork 0
/
test_fft_correctness_2.cpp
78 lines (60 loc) · 1.9 KB
/
test_fft_correctness_2.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#include <sirius.h>
/* test FFT: tranfrom random function to real space, transfrom back and compare with the original function */
using namespace sirius;
int test_fft_complex(cmd_args& args, device_t fft_pu__)
{
double cutoff = args.value<double>("cutoff", 40);
matrix3d<double> M = {{1, 0, 0}, {0, 1, 0}, {0, 0, 1}};
FFT3D fft(find_translations(cutoff, M), Communicator::world(), fft_pu__);
Gvec gvec(M, cutoff, Communicator::world(), false);
Gvec_partition gvp(gvec, fft.comm(), Communicator::self());
fft.prepare(gvp);
mdarray<double_complex, 1> f(gvp.gvec_count_fft());
for (int ig = 0; ig < gvp.gvec_count_fft(); ig++) {
f[ig] = utils::random<double_complex>();
}
mdarray<double_complex, 1> g(gvp.gvec_count_fft());
fft.transform<1>(f.at(memory_t::host));
fft.transform<-1>(g.at(memory_t::host));
double diff{0};
for (int ig = 0; ig < gvp.gvec_count_fft(); ig++) {
diff += std::pow(std::abs(f[ig] - g[ig]), 2);
}
Communicator::world().allreduce(&diff, 1);
diff = std::sqrt(diff / gvec.num_gvec());
fft.dismiss();
if (diff > 1e-10) {
return 1;
} else {
return 0;
}
}
int run_test(cmd_args& args)
{
int result = test_fft_complex(args, CPU);
#ifdef __GPU
result += test_fft_complex(args, GPU);
#endif
return result;
}
int main(int argn, char **argv)
{
cmd_args args;
args.register_key("--cutoff=", "{double} cutoff radius in G-space");
args.parse_args(argn, argv);
if (args.exist("help")) {
printf("Usage: %s [options]\n", argv[0]);
args.print_help();
return 0;
}
sirius::initialize(true);
printf("running %-30s : ", argv[0]);
int result = run_test(args);
if (result) {
printf("\x1b[31m" "Failed" "\x1b[0m" "\n");
} else {
printf("\x1b[32m" "OK" "\x1b[0m" "\n");
}
sirius::finalize();
return result;
}