version 0.1
[LbmBenchmarkKernelsPublic.git] / src / BenchKernelD3Q19ListAaCommon.h
CommitLineData
10988083
MW
1// --------------------------------------------------------------------------
2//
3// Copyright
4// Markus Wittmann, 2016-2017
5// RRZE, University of Erlangen-Nuremberg, Germany
6// markus.wittmann -at- fau.de or hpc -at- rrze.fau.de
7//
8// Viktor Haag, 2016
9// LSS, University of Erlangen-Nuremberg, Germany
10//
11// This file is part of the Lattice Boltzmann Benchmark Kernels (LbmBenchKernels).
12//
13// LbmBenchKernels is free software: you can redistribute it and/or modify
14// it under the terms of the GNU General Public License as published by
15// the Free Software Foundation, either version 3 of the License, or
16// (at your option) any later version.
17//
18// LbmBenchKernels is distributed in the hope that it will be useful,
19// but WITHOUT ANY WARRANTY; without even the implied warranty of
20// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21// GNU General Public License for more details.
22//
23// You should have received a copy of the GNU General Public License
24// along with LbmBenchKernels. If not, see <http://www.gnu.org/licenses/>.
25//
26// --------------------------------------------------------------------------
27#ifndef __BENCH_KERNEL_D3Q19_LIST_AA_COMMON_H__
28#define __BENCH_KERNEL_D3Q19_LIST_AA_COMMON_H__
29
30
31#include "Kernel.h"
32
33#include <inttypes.h>
34
35#define N_D3Q19_IDX 18
36
37typedef struct KernelDataList_
38{
39 KernelData kd;
40 uint32_t * AdjList; // Stores PDF indices, which are the destination for propagation.
41 // Determine the destination for node index n and direction d via:
42 // (n * N_D3Q19_IDX) + d
43 uint32_t * Grid; // Stores the node indices; use L_INDEX_4 macro for access.
44 uint32_t * Coords; // Map node indices to coordiantes; use C_INDEX_* macro for access.
45 int nFluid; // Number of fluid nodes allocated, i.e. length of adjList * N_D3Q19_IDX.
46 int nCells; // Total number of nodes allocated, including nodes for padding!
47 int Iteration; // Current iteration, starts at 0.
48} KernelDataList;
49
50
51// Macro for casting KernelData * to KernelDataList *.
52#define KDL(_x_) ((KernelDataList *)(_x_))
53
54
55
56
57// Build a function name extended by the propagation model name and the data layout.
58// FNANEM(test) will be expanded to test_PushSoA if DATA_LAYOUT_NAME is defined
59// as SoA and PROP_MODEL is defined as Push.
60#define FNAME(functionName) JOIN(JOIN(functionName,_),JOIN(PROP_MODEL_NAME,DATA_LAYOUT_NAME))
61
62#ifndef DATA_LAYOUT_NAME
63 #error DATA_LAYOUT_NAME must be defined
64#endif
65
66#ifndef PROP_MODEL_NAME
67 #error PROP_MODEL_NAME must be defined
68#endif
69
70// -----------------------------------------------------------------------
71// Index function for accesssing PDF array for different data layouts.
72
73#define P_INDEX_3 FNAME(PINDEX3)
74
75static inline int FNAME(PINDEX3)(int nCells, int cellIndex, int d)
76{
77 Assert(nCells > 0);
78 Assert(cellIndex >= 0);
79 Assert(cellIndex < nCells);
80
81 Assert(d >= 0);
82 #ifdef D3Q19
83 Assert(d < N_D3Q19);
84 #else
85 #error Not implemented for this discretization.
86 #endif
87
88#ifdef DATA_LAYOUT_SOA
89 return d * nCells + cellIndex;
90#elif DATA_LAYOUT_AOS
91 return cellIndex * N_D3Q19 + d;
92#else
93 #error P_INDEX_3 function not implemented for chosen data layout.
94#endif
95}
96
97#define P_INDEX_5 FNAME(PINDEX5)
98
99static inline int FNAME(PINDEX5)(KernelDataList * kdl, int x, int y, int z, int d)
100{
101 Assert(kdl != NULL);
102#ifdef DEBUG
103 uint32_t * grid = kdl->Grid;
104 int * dims = kdl->kd.Dims;
105
106 Assert(grid != NULL);
107 Assert(dims != NULL);
108 Assert(dims[0] > 0);
109 Assert(dims[1] > 0);
110 Assert(dims[2] > 0);
111 Assert(x >= 0 && x < dims[0]);
112 Assert(y >= 0 && y < dims[1]);
113 Assert(z >= 0 && z < dims[2]);
114 Assert(d >= 0 && d < N_D3Q19);
115#endif
116
117 return P_INDEX_3(kdl->nCells, kdl->Grid[L_INDEX_4(kdl->kd.Dims, x, y, z)], d);
118}
119
120// -----------------------------------------------------------------------
121// Macros for accessing coord array
122
123#define C_INDEX_X(cellIndex) C_INDEX(cellIndex, 0)
124#define C_INDEX_Y(cellIndex) C_INDEX(cellIndex, 1)
125#define C_INDEX_Z(cellIndex) C_INDEX(cellIndex, 2)
126
127static inline int C_INDEX(int cellIndex, int xyz)
128{
129 Assert(cellIndex >= 0);
130 Assert(xyz >= 0);
131 Assert(xyz < 3);
132
133 return cellIndex * 3 + xyz;
134}
135
136
137#endif // __BENCH_KERNEL_D3Q19_LIST_AA_COMMON_H__
This page took 0.079884 seconds and 5 git commands to generate.