1 // --------------------------------------------------------------------------
4 // Markus Wittmann, 2016-2017
5 // RRZE, University of Erlangen-Nuremberg, Germany
6 // markus.wittmann -at- fau.de or hpc -at- rrze.fau.de
9 // LSS, University of Erlangen-Nuremberg, Germany
11 // This file is part of the Lattice Boltzmann Benchmark Kernels (LbmBenchKernels).
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.
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.
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/>.
26 // --------------------------------------------------------------------------
27 #include "BenchKernelD3Q19ListPullSplitNtCommon.h"
48 #define TMP_INDEX(tmp_index, tmp_dir) nTmpArray * (tmp_dir) + (tmp_index)
50 void FNAME(KernelPullSplitNt1S)(LatticeDesc * ld, KernelData * kernelData, CaseData * cd)
54 Assert(kernelData != NULL);
57 Assert(cd->Omega > 0.0);
58 Assert(cd->Omega < 2.0);
60 KernelData * kd = (KernelData *)kernelData;
61 KernelDataList * kdl = KDL(kernelData);
62 KernelDataListRia * kdlr = KDLR(kernelData);
64 PdfT omega = cd->Omega;
65 const PdfT omegaEven = omega;
67 PdfT magicParam = 1.0 / 12.0;
68 const PdfT omegaOdd = 1.0 / (0.5 + magicParam / (1.0 / omega - 0.5));
71 const PdfT w_0 = 1.0 / 3.0;
72 const PdfT w_1 = 1.0 / 18.0;
73 const PdfT w_2 = 1.0 / 36.0;
75 const PdfT w_1_x3 = w_1 * 3.0; const PdfT w_1_nine_half = w_1 * 9.0 / 2.0;
76 const PdfT w_2_x3 = w_2 * 3.0; const PdfT w_2_nine_half = w_2 * 9.0 / 2.0;
78 const VPDFT vw_1_x3 = VSET(w_1_x3);
79 const VPDFT vw_2_x3 = VSET(w_2_x3);
81 const VPDFT vw_1_nine_half = VSET(w_1_nine_half);
82 const VPDFT vw_2_nine_half = VSET(w_2_nine_half);
84 const VPDFT vomegaEven = VSET(omegaEven);
85 const VPDFT vomegaOdd = VSET(omegaOdd);
87 const VPDFT voneHalf = VSET(0.5);
89 // uint32_t nConsecNodes = kdlr->nConsecNodes;
90 // uint32_t * consecNodes = kdlr->ConsecNodes;
91 // uint32_t consecIndex = 0;
92 // uint32_t consecValue = 0;
94 PdfT * src = kd->Pdfs[0];
95 PdfT * dst = kd->Pdfs[1];
98 int maxIterations = cd->MaxIterations;
100 int nFluid = kdl->nFluid;
101 int nCells = kdl->nCells;
103 int nTmpArray = kdlr->nTmpArray;
105 Assert(nTmpArray % VSIZE == 0);
107 uint32_t * adjList = kdl->AdjList;
111 kd->PdfsActive = src;
112 VtkWrite(ld, kd, cd, -1);
117 kd->PdfsActive = src;
118 KernelStatistics(kd, ld, cd, 0);
122 #pragma omp parallel default(none) \
123 shared(nFluid, nCells, kd, kdl, adjList, src, dst, \
124 cd, maxIterations, ld, tmp, nTmpArray, \
128 uint32_t adjListIndex;
131 VPDFT vux, vuy, vuz, vui;
133 #define X(name, idx, idxinv, x, y, z) PdfT JOIN(pdf_,name);
136 VPDFT vpdf_a, vpdf_b;
138 PdfT evenPart, oddPart, dir_indep_trm, dens;
139 PdfT w_1_indep, w_2_indep;
140 VPDFT vevenPart, voddPart;
141 VPDFT vw_1_indep, vw_2_indep;
146 MemAllocAligned((void **)&tmpArray, sizeof(PdfT) * nTmpArray * N_TMP, VSIZE * sizeof(PdfT));
152 nThreads = omp_get_max_threads();
153 threadId = omp_get_thread_num();
156 int nCellsThread = nFluid / nThreads;
157 int blIndexStart = threadId * nCellsThread;
159 if (threadId < nFluid % nThreads) {
160 blIndexStart += threadId;
164 blIndexStart += nFluid % nThreads;
167 int blIndexStop = blIndexStart + nCellsThread;
169 // We have three loops:
170 // 1. Peeling to ensure alignment for non-temporal stores in loop 2 is correct.
171 // 2. Vectorized handling of nodes.
172 // 3. Remaining nodes, less than vector size.
174 unsigned long addrStart = (unsigned long)&(src[P_INDEX_3(nCells, blIndexStart, 0)]);
175 int nCellsUnaligned = (VSIZE - (int)((addrStart / sizeof(PdfT)) % VSIZE)) % VSIZE;
177 int nCellsVectorized = nCellsThread - nCellsUnaligned;
178 nCellsVectorized = nCellsVectorized - (nCellsVectorized % VSIZE);
180 int blIndexVec = blIndexStart + nCellsUnaligned;
181 int blIndexRemaining = blIndexStart + nCellsUnaligned + nCellsVectorized;
183 // printf("%d [%d, %d, %d, %d[\n", threadId, blIndexStart, blIndexVec, blIndexRemaining, blIndexStop);
185 for(int iter = 0; iter < maxIterations; ++iter) {
188 #define INDEX_START blIndexStart
189 #define INDEX_STOP blIndexVec
190 #include "BenchKernelD3Q19ListPullSplitNt1SScalar.h"
192 #define INDEX_START blIndexVec
193 #define INDEX_STOP blIndexRemaining
194 #include "BenchKernelD3Q19ListPullSplitNt1SIntrinsics.h"
196 #define INDEX_START blIndexRemaining
197 #define INDEX_STOP blIndexStop
198 #include "BenchKernelD3Q19ListPullSplitNt1SScalar.h"
200 #define INDEX_START blIndexStart
201 #define INDEX_STOP blIndexStop
202 #include "BenchKernelD3Q19ListPullSplitNt1SScalar.h"
209 kd->PdfsActive = dst;
210 KernelAddBodyForce(kd, ld, cd);
214 if (cd->VtkOutput && (iter % cd->VtkModulus) == 0) {
215 kd->PdfsActive = dst;
216 VtkWrite(ld, kd, cd, iter);
221 kd->PdfsActive = dst;
222 KernelStatistics(kd, ld, cd, iter);
233 } // for (int iter = 0; ...
235 MemFree((void **)&tmpArray);
240 kd->PdfsActive = src;
241 VtkWrite(ld, kd, cd, maxIterations);
246 kd->PdfsActive = src;
247 KernelStatistics(kd, ld, cd, maxIterations);
253 void FNAME(KernelPullSplitNt2S)(LatticeDesc * ld, KernelData * kernelData, CaseData * cd)
257 Assert(kernelData != NULL);
260 Assert(cd->Omega > 0.0);
261 Assert(cd->Omega < 2.0);
263 KernelData * kd = (KernelData *)kernelData;
264 KernelDataList * kdl = KDL(kernelData);
265 KernelDataListRia * kdlr = KDLR(kernelData);
267 PdfT omega = cd->Omega;
268 const PdfT omegaEven = omega;
270 PdfT magicParam = 1.0 / 12.0;
271 const PdfT omegaOdd = 1.0 / (0.5 + magicParam / (1.0 / omega - 0.5));
274 const PdfT w_0 = 1.0 / 3.0;
275 const PdfT w_1 = 1.0 / 18.0;
276 const PdfT w_2 = 1.0 / 36.0;
278 const PdfT w_1_x3 = w_1 * 3.0; const PdfT w_1_nine_half = w_1 * 9.0 / 2.0;
279 const PdfT w_2_x3 = w_2 * 3.0; const PdfT w_2_nine_half = w_2 * 9.0 / 2.0;
281 const VPDFT vw_1_x3 = VSET(w_1_x3);
282 const VPDFT vw_2_x3 = VSET(w_2_x3);
284 const VPDFT vw_1_nine_half = VSET(w_1_nine_half);
285 const VPDFT vw_2_nine_half = VSET(w_2_nine_half);
287 const VPDFT vomegaEven = VSET(omegaEven);
288 const VPDFT vomegaOdd = VSET(omegaOdd);
290 const VPDFT voneHalf = VSET(0.5);
292 // uint32_t nConsecNodes = kdlr->nConsecNodes;
293 // uint32_t * consecNodes = kdlr->ConsecNodes;
294 // uint32_t consecIndex = 0;
295 // uint32_t consecValue = 0;
297 PdfT * src = kd->Pdfs[0];
298 PdfT * dst = kd->Pdfs[1];
301 int maxIterations = cd->MaxIterations;
303 int nFluid = kdl->nFluid;
304 int nCells = kdl->nCells;
306 int nTmpArray = kdlr->nTmpArray;
308 Assert(nTmpArray % VSIZE == 0);
310 uint32_t * adjList = kdl->AdjList;
314 kd->PdfsActive = src;
315 VtkWrite(ld, kd, cd, -1);
320 kd->PdfsActive = src;
321 KernelStatistics(kd, ld, cd, 0);
325 #pragma omp parallel default(none) \
326 shared(nFluid, nCells, kd, kdl, adjList, src, dst, \
327 cd, maxIterations, ld, tmp, nTmpArray, \
331 uint32_t adjListIndex;
334 VPDFT vux, vuy, vuz, vui;
336 #define X(name, idx, idxinv, x, y, z) PdfT JOIN(pdf_,name);
339 VPDFT vpdf_a, vpdf_b;
341 PdfT evenPart, oddPart, dir_indep_trm, dens;
342 PdfT w_1_indep, w_2_indep;
343 VPDFT vevenPart, voddPart;
344 VPDFT vw_1_indep, vw_2_indep;
349 MemAlloc((void **)&tmpArray, sizeof(PdfT) * nTmpArray * N_TMP);
355 nThreads = omp_get_max_threads();
356 threadId = omp_get_thread_num();
359 int nCellsThread = nFluid / nThreads;
360 int blIndexStart = threadId * nCellsThread;
362 if (threadId < nFluid % nThreads) {
363 blIndexStart += threadId;
367 blIndexStart += nFluid % nThreads;
370 int blIndexStop = blIndexStart + nCellsThread;
372 // We have three loops:
373 // 1. Peeling to ensure alignment for non-temporal stores in loop 2 is correct.
374 // 2. Vectorized handling of nodes.
375 // 3. Remaining nodes, less than vector size.
377 unsigned long addrStart = (unsigned long)&(src[P_INDEX_3(nCells, blIndexStart, 0)]);
378 int nCellsUnaligned = (VSIZE - (int)((addrStart / sizeof(PdfT)) % VSIZE)) % VSIZE;
380 int nCellsVectorized = nCellsThread - nCellsUnaligned;
381 nCellsVectorized = nCellsVectorized - (nCellsVectorized % VSIZE);
383 int blIndexVec = blIndexStart + nCellsUnaligned;
384 int blIndexRemaining = blIndexStart + nCellsUnaligned + nCellsVectorized;
386 // printf("%d [%d, %d, %d, %d[\n", threadId, blIndexStart, blIndexVec, blIndexRemaining, blIndexStop);
388 for(int iter = 0; iter < maxIterations; ++iter) {
391 #define INDEX_START blIndexStart
392 #define INDEX_STOP blIndexVec
393 #include "BenchKernelD3Q19ListPullSplitNt2SScalar.h"
395 #define INDEX_START blIndexVec
396 #define INDEX_STOP blIndexRemaining
397 #include "BenchKernelD3Q19ListPullSplitNt2SIntrinsics.h"
399 #define INDEX_START blIndexRemaining
400 #define INDEX_STOP blIndexStop
401 #include "BenchKernelD3Q19ListPullSplitNt2SScalar.h"
403 #define INDEX_START blIndexStart
404 #define INDEX_STOP blIndexStop
405 #include "BenchKernelD3Q19ListPullSplitNt2SScalar.h"
412 kd->PdfsActive = dst;
413 KernelAddBodyForce(kd, ld, cd);
417 if (cd->VtkOutput && (iter % cd->VtkModulus) == 0) {
418 kd->PdfsActive = dst;
419 VtkWrite(ld, kd, cd, iter);
424 kd->PdfsActive = dst;
425 KernelStatistics(kd, ld, cd, iter);
436 } // for (int iter = 0; ...
438 MemFree((void **)&tmpArray);
443 kd->PdfsActive = src;
444 VtkWrite(ld, kd, cd, maxIterations);
449 kd->PdfsActive = src;
450 KernelStatistics(kd, ld, cd, maxIterations);