AutoPas  3.0.0
Loading...
Searching...
No Matches
SlicedC02BasedTraversal.h
Go to the documentation of this file.
1
8#pragma once
9
10#include <algorithm>
11
16
17namespace autopas {
18
32template <class ParticleCell, class Functor>
33class SlicedC02BasedTraversal : public SlicedBasedTraversal<ParticleCell, Functor> {
34 public:
39 explicit SlicedC02BasedTraversal(const std::array<unsigned long, 3> &dims, Functor *functor,
40 const double interactionLength, const std::array<double, 3> &cellLength,
41 DataLayoutOption dataLayout, bool useNewton3, bool spaciallyForward)
42 : SlicedBasedTraversal<ParticleCell, Functor>(dims, functor, interactionLength, cellLength, dataLayout,
43 useNewton3, spaciallyForward) {}
44
52 template <typename LoopBody>
53 inline void cSlicedTraversal(LoopBody &&loopBody);
54
59 [[nodiscard]] bool isApplicable() const override {
60 return this->_cellsPerDimension[this->_dimsPerLength[0]] >= this->_overlapLongestAxis;
61 }
62
66 void initTraversal() override {
67 this->loadDataLayout();
68 // split domain across its longest dimension
69 auto minSliceThickness = this->_overlapLongestAxis;
70 this->initSliceThickness(minSliceThickness);
71 }
72};
73
74template <class ParticleCell, class Functor>
75template <typename LoopBody>
77 using std::array;
78
79 auto numSlices = this->_sliceThickness.size();
80 // check if applicable
81
82 std::array<size_t, 2> overLapps23{this->_overlap[this->_dimsPerLength[1]], this->_overlap[this->_dimsPerLength[2]]};
83
84 if (not this->_spaciallyForward) {
85 overLapps23 = {0ul, 0ul};
86 }
87
88 for (size_t offset = 0; offset < 2; offset++) {
89 // although every thread gets exactly one iteration (=slice) this is faster than a normal parallel region
90 AUTOPAS_OPENMP(parallel for schedule(dynamic, 1))
91 for (size_t slice = offset; slice < numSlices; slice += 2) {
92 array<unsigned long, 3> myStartArray{0, 0, 0};
93 for (size_t i = 0; i < slice; ++i) {
94 myStartArray[this->_dimsPerLength[0]] += this->_sliceThickness[i];
95 }
96
97 const auto lastLayer = myStartArray[this->_dimsPerLength[0]] + this->_sliceThickness[slice];
98 for (unsigned long dimSlice = myStartArray[this->_dimsPerLength[0]]; dimSlice < lastLayer; ++dimSlice) {
99 for (unsigned long dimMedium = 0;
100 dimMedium < this->_cellsPerDimension[this->_dimsPerLength[1]] - overLapps23[0]; ++dimMedium) {
101 for (unsigned long dimShort = 0;
102 dimShort < this->_cellsPerDimension[this->_dimsPerLength[2]] - overLapps23[1]; ++dimShort) {
103 array<unsigned long, 3> idArray = {};
104 idArray[this->_dimsPerLength[0]] = dimSlice;
105 idArray[this->_dimsPerLength[1]] = dimMedium;
106 idArray[this->_dimsPerLength[2]] = dimShort;
107 loopBody(idArray[0], idArray[1], idArray[2]);
108 }
109 }
110 }
111 }
112 }
113}
114
115} // namespace autopas
#define AUTOPAS_OPENMP(args)
Empty macro to throw away any arguments.
Definition: WrapOpenMP.h:126
std::array< unsigned long, 3 > _cellsPerDimension
The dimensions of the cellblock.
Definition: CellTraversal.h:55
Functor base class.
Definition: Functor.h:40
Class for Cells of Particles.
Definition: ParticleCell.h:51
This class provides base for locked- and colored sliced traversals.
Definition: SlicedBasedTraversal.h:30
std::array< int, 3 > _dimsPerLength
Store ids of dimensions ordered by number of cells per dimensions.
Definition: SlicedBasedTraversal.h:147
virtual void loadDataLayout()
Load Data Layouts required for this Traversal if cells have been set through setCellsToTraverse().
Definition: SlicedBasedTraversal.h:129
virtual void initSliceThickness(unsigned long minSliceThickness)
Sets up the slice thicknesses to create as many slices as possible while respecting minSliceThickness...
Definition: SlicedBasedTraversal.h:74
unsigned long _overlapLongestAxis
Overlap of interacting cells along the longest axis.
Definition: SlicedBasedTraversal.h:152
This class provides the colored sliced traversal.
Definition: SlicedC02BasedTraversal.h:33
bool isApplicable() const override
Checks if the traversal is applicable to the current state of the domain.
Definition: SlicedC02BasedTraversal.h:59
void initTraversal() override
Load Data Layouts and sets up slice thicknesses.
Definition: SlicedC02BasedTraversal.h:66
void cSlicedTraversal(LoopBody &&loopBody)
The main traversal of the colored sliced traversal.
Definition: SlicedC02BasedTraversal.h:76
SlicedC02BasedTraversal(const std::array< unsigned long, 3 > &dims, Functor *functor, const double interactionLength, const std::array< double, 3 > &cellLength, DataLayoutOption dataLayout, bool useNewton3, bool spaciallyForward)
Constructor of the colored sliced traversal.
Definition: SlicedC02BasedTraversal.h:39
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32