From a92271176a19e06611099c0eccc4e6a6887f4915 Mon Sep 17 00:00:00 2001 From: Adrian Kummerlaender Date: Mon, 17 May 2021 00:30:13 +0200 Subject: Extract public version of SweepLB --- src/pattern/sss.h | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/pattern/sss.h (limited to 'src/pattern/sss.h') diff --git a/src/pattern/sss.h b/src/pattern/sss.h new file mode 100644 index 0000000..1f1985d --- /dev/null +++ b/src/pattern/sss.h @@ -0,0 +1,63 @@ +#pragma once + +#include "population.h" +#include "propagation.h" + +#include "cuboid.h" +#include "concepts.h" +#include "population.h" + +#include + +namespace pattern { + +template +class SSS { +private: + Cuboid _cuboid; + + T* _base; + T* _buffer[population::q]; + T* _f[population::q]; + +public: + using value_t = T; + + SSS(Cuboid cuboid): + _cuboid(cuboid) + { + const std::size_t pagesize = sysconf(_SC_PAGESIZE); + const std::ptrdiff_t padding = population::max_offset(_cuboid); + _base = static_cast( + std::aligned_alloc(pagesize, population::q * (_cuboid.volume() + 2*padding) * sizeof(T))); + for (unsigned iPop=0; iPop < population::q; ++iPop) { + _buffer[iPop] = _base + iPop * (_cuboid.volume() + 2*padding); + _f[iPop] = _buffer[iPop] + padding; + } + } + + ~SSS() { + delete [] _base; + } + + T* get(unsigned iPop, stage::pre_collision) { + return _f[iPop]; + } + + T* get(unsigned iPop, stage::post_collision) { + return _f[population::opposite(iPop)]; + } + + void stream() { + T* f_old[population::q]; + for (unsigned iPop=0; iPop < population::q; ++iPop) { + f_old[iPop] = _f[iPop]; + } + for (unsigned iPop=0; iPop < population::q; ++iPop) { + _f[iPop] = f_old[population::opposite(iPop)] - population::offset(_cuboid, iPop); + } + } + +}; + +} -- cgit v1.2.3