SPH
Finders.cpp
Go to the documentation of this file.
1 #include "bench/Session.h"
8 #include "thread/Pool.h"
9 #include "thread/Tbb.h"
10 
11 using namespace Sph;
12 
13 template <typename TFinder>
14 void finderRun(Benchmark::Context& context, TFinder& finder, const Size particleCnt) {
15  HexagonalPacking distribution;
17  Array<Vector> r = distribution.generate(pool, particleCnt, SphericalDomain(Vector(0._f), 1._f));
19  double distSum = 0.;
20  finder.build(pool, r);
21  while (context.running()) {
22  for (Size i = 0; i < r.size(); ++i) {
23  finder.findAll(i, 2._f * r[i][H], neighs);
24  for (NeighbourRecord& n : neighs) {
25  distSum += n.distanceSqr;
26  }
27  }
28  }
29 }
30 
31 BENCHMARK("Finder run KdTree", "[finders]", Benchmark::Context& context) {
32  KdTree<KdNode> tree;
33  finderRun(context, tree, 10000);
34 }
35 
36 BENCHMARK("Finder run UniformGrid", "[finders]", Benchmark::Context& context) {
37  UniformGridFinder finder;
38  finderRun(context, finder, 10000);
39 }
40 
41 BENCHMARK("Finder run BruteForce", "[finders]", Benchmark::Context& context) {
43  finderRun(context, bf, 1000);
44 }
45 
46 
47 /*BENCHMARK("Finder run linkedListRun(benchmark::State& state) {
48  LinkedList linkedList;
49  finderRun(state, linkedList);
50 }
51 BENCHMARK(linkedListRun);*/
52 
53 
54 static void finderBuild(Benchmark::Context& context, IBasicFinder& finder, IScheduler& scheduler) {
55  HexagonalPacking distribution;
56  Array<Vector> r = distribution.generate(scheduler, 1000000, SphericalDomain(Vector(0._f), 1._f));
57  while (context.running()) {
58  finder.build(scheduler, r);
60  }
61 }
62 
63 BENCHMARK("Finder build KdTree Sequential", "[finders]", Benchmark::Context& context) {
64  KdTree<KdNode> tree;
65  finderBuild(context, tree, SEQUENTIAL);
66 }
67 
68 BENCHMARK("Finder build KdTree ThreadPool", "[finders]", Benchmark::Context& context) {
69  KdTree<KdNode> tree;
70  finderBuild(context, tree, *ThreadPool::getGlobalInstance());
71 }
72 
73 #ifdef SPH_USE_TBB
74 BENCHMARK("Finder build KdTree Tbb", "[finders]", Benchmark::Context& context) {
75  KdTree<KdNode> tree;
76  finderBuild(context, tree, *Tbb::getGlobalInstance());
77 }
78 #endif
Object finding nearest neighbours by evaluating all partice pairs.
Filling spatial domain with SPH particles.
Object defining computational domain.
void finderRun(Benchmark::Context &context, TFinder &finder, const Size particleCnt)
Definition: Finders.cpp:14
BENCHMARK("Finder run KdTree", "[finders]", Benchmark::Context &context)
Definition: Finders.cpp:31
uint32_t Size
Integral type used to index arrays (by default).
Definition: Globals.h:16
K-d tree for efficient search of neighbouring particles.
Simple thread pool with fixed number of threads.
SequentialScheduler SEQUENTIAL
Global instance of the sequential scheduler.
Definition: Scheduler.cpp:43
Benchmark.
INLINE void clobberMemory()
Definition: Session.h:190
Implements IScheduler interface using TBB.
Simple algorithm for finding nearest neighbours using spatial partitioning of particles.
BasicVector< Float > Vector
Definition: Vector.h:539
@ H
Definition: Vector.h:25
Generic dynamically allocated resizable storage.
Definition: Array.h:43
INLINE TCounter size() const noexcept
Definition: Array.h:193
Searches for neighbours by 'brute force', comparing every pair of vectors.
Hexagonal close packing.
Definition: Distribution.h:72
virtual Array< Vector > generate(IScheduler &scheduler, const Size n, const IDomain &domain) const override
Generates the requested number of particles in the domain.
Interface of objects finding neighbouring particles.
void build(IScheduler &scheduler, ArrayView< const Vector > points)
Constructs the struct with an array of vectors.
Interface that allows unified implementation of sequential and parallelized versions of algorithms.
Definition: Scheduler.h:27
K-d tree, used for hierarchical clustering of particles and accelerated Kn queries.
Definition: KdTree.h:136
Spherical domain, defined by the center of sphere and its radius.
Definition: Domain.h:102
static SharedPtr< Tbb > getGlobalInstance()
Thread pool capable of executing tasks concurrently.
Definition: Pool.h:70
static SharedPtr< ThreadPool > getGlobalInstance()
Returns the global instance of the thread pool.
Definition: Pool.cpp:211
Finder projecting a uniform grid on the particles.
Definition: UniformGrid.h:14
Definition: MemoryPool.h:5
Holds information about a neighbour particles.