-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow SIMD, Eigen, and libm functions in scattering analysis
Different implementations exhibit very different performance (factor of 5 observed) depending on the compiler and system environment. Add unit and performance tests.
- Loading branch information
Showing
4 changed files
with
100 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
#include "analysis.h" | ||
#include "io.h" | ||
|
||
#define ANKERL_NANOBENCH_IMPLEMENT | ||
#include "nanobench.h" | ||
|
||
namespace Faunus { | ||
namespace Scatter { | ||
|
||
using doctest::Approx; | ||
|
||
double box = 80; | ||
const std::vector<Point> positions = { | ||
{10, 20, 30}, {-32, 19, 1}, {34, -2, 23}, {0, 0, 1}, {25, 0, -12}, | ||
{-6, -4, -29}, {-12, 23, -3}, {3, 1, -4}, {-31, 29, -20}}; // random position vector | ||
|
||
TEST_CASE_TEMPLATE("[Faunus] StructureFactorPBC", T, StructureFactorPBC<float, SIMD>, | ||
StructureFactorPBC<float, EIGEN>, StructureFactorPBC<float, GENERIC>) { | ||
size_t cnt = 0; | ||
std::vector<float> result = {0.0785, 1.48621, 0.1111, 0.567279, 0.136, 1.39515, | ||
0.1571, 0.730579, 0.2221, 0.701547, 0.2721, 0.692064}; | ||
T scatter(2); | ||
scatter.sample(positions, box); | ||
for (auto [q, S] : scatter.getSampling()) { | ||
CHECK(q == Approx(result[cnt++])); | ||
CHECK(S == Approx(result[cnt++])); | ||
} | ||
CHECK(cnt == result.size()); | ||
} | ||
|
||
#ifdef ANKERL_NANOBENCH_H_INCLUDED | ||
TEST_CASE("Benchmark") { | ||
std::vector<Point> pos(1000); | ||
for (auto &p : pos) | ||
p = Eigen::Vector3d::Random() * box; | ||
ankerl::nanobench::Config bench; | ||
bench.minEpochIterations(100); | ||
bench.run("SIMD", [&] { StructureFactorPBC<double, SIMD>(10).sample(pos, box); }).doNotOptimizeAway(); | ||
bench.run("EIGEN", [&] { StructureFactorPBC<double, EIGEN>(10).sample(pos, box); }).doNotOptimizeAway(); | ||
bench.run("GENERIC", [&] { StructureFactorPBC<double, GENERIC>(10).sample(pos, box); }).doNotOptimizeAway(); | ||
} | ||
#endif | ||
|
||
TEST_CASE("[Faunus] StructureFactorIPBC") { | ||
size_t cnt = 0; | ||
std::vector<double> result = {0.0785, 0.384363, 0.1111, 1.51652, 0.136, 1.18027, | ||
0.1571, 1.40662, 0.2221, 2.06042, 0.2721, 1.53482}; | ||
StructureFactorIPBC scatter(2); | ||
scatter.sample(positions, box); | ||
for (auto [q, S] : scatter.getSampling()) { | ||
CHECK(q == Approx(result[cnt++])); | ||
CHECK(S == Approx(result[cnt++])); | ||
} | ||
CHECK(cnt == result.size()); | ||
} | ||
|
||
} // namespace Scatter | ||
} // namespace Faunus |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters