11#include <initializer_list>
20template<
unsigned select>
30template<
unsigned dims,
unsigned d>
32init_fill(
const std::vector<long> &stride,
unsigned *adjlist,
unsigned *grid_ptr,
unsigned *low,
unsigned *high,
35 init_fill<dims, d - 1>(stride, adjlist, grid_ptr - stride[d - 1], low, high,
TagSelect<d - 1>::value);
36 init_fill<dims, d - 1>(stride, adjlist + str, grid_ptr, low, high,
TagSelect<d - 1>::value);
37 init_fill<dims, d - 1>(stride, adjlist + str * 2, grid_ptr + stride[d - 1], low, high,
TagSelect<d - 1>::value);
40template<
unsigned dims,
unsigned d>
42init_fill(
const std::vector<long> &stride,
unsigned *adjlist,
unsigned *grid_ptr,
unsigned *low,
unsigned *high,
44 if (grid_ptr >= low && grid_ptr < high)
50template<
unsigned dims,
unsigned d>
55#pragma omp parallel for
56 for (
long s = 0; s < dimlist[dims - d]; ++s)
57 init_iter<dims, d - 1>(dimlist, stride, bInfo, grid_ptr + s * stride[dims - d], low, high,
60 for (
long s = 0; s < dimlist[dims - d]; ++s)
61 init_iter<dims, d - 1>(dimlist, stride, bInfo, grid_ptr + s * stride[dims - d], low, high,
66template<
unsigned dims,
unsigned d>
69 unsigned *low,
unsigned *high,
StopTag t) {
70 init_fill<dims, dims>(stride, bInfo.
adj[*grid_ptr], grid_ptr, low, high,
RunningTag());
73template<
unsigned dims>
76 std::vector<long> stride;
77 for (
const auto a: dimlist) {
78 stride.push_back(size);
81 grid_ptr = (
unsigned *) malloc(size *
sizeof(
unsigned));
82 for (
unsigned pos = 0; pos < size; ++pos)
87 init_iter<dims, dims>(dimlist, stride, bInfo, grid_ptr, grid_ptr, grid_ptr + size,
RunningTag());
92template<
unsigned dims,
unsigned d,
typename F,
typename A>
94 for (
long s = 0; s <
tile[d - 1]; ++s)
98template<
unsigned dims,
unsigned d,
typename F,
typename A>
99inline void fill(
const std::vector<long> &
tile,
const std::vector<long> &stride,
bElem *arr, A &a, F f,
StopTag t) {
103template<
unsigned dims,
unsigned d,
typename T,
typename F>
104inline void iter(
const std::vector<long> &dimlist,
const std::vector<long> &
tile,
105 const std::vector<long> &strideA,
const std::vector<long> &strideB,
106 const std::vector<long> &padding,
const std::vector<long> &ghost,
108 constexpr unsigned dimp = d - 1;
110#pragma omp parallel for
111 for (
long s = ghost[dimp] /
tile[dimp]; s < (dimlist[dimp] + ghost[dimp]) /
tile[dimp]; ++s)
112 iter<dims, d - 1>(dimlist,
tile, strideA, strideB, padding, ghost,
brick,
113 arr + (padding[dimp] + s *
tile[dimp]) * strideA[dimp],
116 for (
long s = ghost[dimp] /
tile[dimp]; s < (dimlist[dimp] + ghost[dimp]) /
tile[dimp]; ++s)
117 iter<dims, d - 1>(dimlist,
tile, strideA, strideB, padding, ghost,
brick,
118 arr + (padding[dimp] + s *
tile[dimp]) * strideA[dimp],
123template<
unsigned dims,
unsigned d,
typename T,
typename F>
124inline void iter(
const std::vector<long> &dimlist,
const std::vector<long> &
tile,
125 const std::vector<long> &strideA,
const std::vector<long> &strideB,
126 const std::vector<long> &padding,
const std::vector<long> &ghost,
139template<
unsigned dims,
typename F,
typename T,
unsigned ... BDims>
141iter_grid(
const std::vector<long> &dimlist,
const std::vector<long> &padding,
const std::vector<long> &ghost,
143 std::vector<long> strideA;
144 std::vector<long> strideB;
145 std::vector<long>
tile = {BDims...};
147 std::reverse(
tile.begin(),
tile.end());
151 for (
long a = 0; a < dimlist.size(); ++a) {
152 strideA.push_back(sizeA);
153 strideB.push_back(sizeB);
154 sizeA *= (dimlist[a] + 2 * (padding[a] + ghost[a]));
155 sizeB *= ((dimlist[a] + 2 * ghost[a]) /
tile[a]);
158 iter<dims, dims>(dimlist,
tile, strideA, strideB, padding, ghost,
brick, arr, grid_ptr, f,
RunningTag());
172template<
unsigned dims,
typename T>
174copyToBrick(
const std::vector<long> &dimlist,
const std::vector<long> &padding,
const std::vector<long> &ghost,
180 iter_grid<dims>(dimlist, padding, ghost, arr, grid_ptr,
brick, f);
194template<
unsigned dims,
typename T>
196 std::vector<long> padding(dimlist.size(), 0);
197 std::vector<long> ghost(dimlist.size(), 0);
199 copyToBrick<dims>(dimlist, padding, ghost, arr, grid_ptr,
brick);
213template<
unsigned dims,
typename T>
214inline void copyFromBrick(
const std::vector<long> &dimlist,
const std::vector<long> &padding,
215 const std::vector<long> &ghost,
bElem *arr,
unsigned *grid_ptr, T &
brick) {
220 iter_grid<dims>(dimlist, padding, ghost, arr, grid_ptr,
brick, f);
void copyToBrick(const std::vector< long > &dimlist, const std::vector< long > &padding, const std::vector< long > &ghost, bElem *arr, unsigned *grid_ptr, T &brick)
Copy values from an array to bricks.
Definition: bricksetup.h:174
void init_fill(const std::vector< long > &stride, unsigned *adjlist, unsigned *grid_ptr, unsigned *low, unsigned *high, RunningTag t)
Definition: bricksetup.h:32
void iter(const std::vector< long > &dimlist, const std::vector< long > &tile, const std::vector< long > &strideA, const std::vector< long > &strideB, const std::vector< long > &padding, const std::vector< long > &ghost, T &brick, bElem *arr, unsigned *grid_ptr, F f, RunningTag t)
Definition: bricksetup.h:104
void iter_grid(const std::vector< long > &dimlist, const std::vector< long > &padding, const std::vector< long > &ghost, bElem *arr, unsigned *grid_ptr, Brick< Dim< BDims... >, T > &brick, F f)
Definition: bricksetup.h:141
void fill(const std::vector< long > &tile, const std::vector< long > &stride, bElem *arr, A a, F f, RunningTag t)
Definition: bricksetup.h:93
BrickInfo< dims > init_grid(unsigned *&grid_ptr, const std::vector< long > &dimlist)
Definition: bricksetup.h:74
void copyFromBrick(const std::vector< long > &dimlist, const std::vector< long > &padding, const std::vector< long > &ghost, bElem *arr, unsigned *grid_ptr, T &brick)
Copy values from bricks to an array.
Definition: bricksetup.h:214
void init_iter(const std::vector< long > &dimlist, const std::vector< long > &stride, BrickInfo< dims > &bInfo, unsigned *grid_ptr, unsigned *low, unsigned *high, RunningTag t)
Definition: bricksetup.h:52
Metadata related to bricks.
Definition: brick.h:97
adjlist adj
Adjacency list.
Definition: brick.h:101
Generic base template, see Brick< Dim< BDims... >, Dim< Folds... > >
Definition: brick.h:340
Empty template to specify an n-D list.
Definition: brick.h:131
Definition: bricksetup.h:15
Definition: bricksetup.h:17
Compute Statically compute exponentials.
Definition: brick.h:35
#define bElem
Basic datatype for all brick elements.
Definition: vecscatter.h:13
#define brick(...)
Inject stencil code for brick datalayout.
Definition: vecscatter.h:62
#define tile(...)
Inject stencil code for tiling here.
Definition: vecscatter.h:27