blob: 1f1985dc7e873be7ab7fbd31ea70428ec32f4e1b (
plain)
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
|
#pragma once
#include "population.h"
#include "propagation.h"
#include "cuboid.h"
#include "concepts.h"
#include "population.h"
#include <unistd.h>
namespace pattern {
template <concepts::Arithmetic T>
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<T*>(
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);
}
}
};
}
|