AutoPas  3.0.0
Loading...
Searching...
No Matches
VVLAsBuildTraversal.h
Go to the documentation of this file.
1
7#pragma once
8
13
14namespace autopas {
23template <class ParticleCell, class Particle_T, class PairwiseFunctor>
24class VVLAsBuildTraversal : public VVLTraversalInterface<VerletNeighborListAsBuild<Particle_T>>,
25 public TraversalInterface {
26 private:
31 void iterateAoS(VerletNeighborListAsBuild<Particle_T> &neighborList);
32
37 void iterateSoA(VerletNeighborListAsBuild<Particle_T> &neighborList);
38
39 public:
46 explicit VVLAsBuildTraversal(PairwiseFunctor &pairwiseFunctor, DataLayoutOption dataLayout, bool useNewton3)
47 : TraversalInterface(dataLayout, useNewton3), _functor(pairwiseFunctor), _soa{nullptr} {}
48
49 void initTraversal() override {
50 auto &neighborList = *(this->_neighborList);
51 if (_dataLayout == DataLayoutOption::soa) {
52 _soa = neighborList.loadSoA(_functor);
53 }
54 }
55
56 void endTraversal() override {
57 auto &neighborList = *(this->_neighborList);
58 if (_dataLayout == DataLayoutOption::soa) {
59 neighborList.extractSoA(_functor);
60 _soa = nullptr;
61 }
62 }
63
64 void traverseParticles() override {
65 auto &neighborList = *(this->_neighborList);
66 switch (this->_dataLayout) {
67 case DataLayoutOption::aos:
68 iterateAoS(neighborList);
69 break;
70 case DataLayoutOption::soa:
71 iterateSoA(neighborList);
72 break;
73 default:
74 autopas::utils::ExceptionHandler::exception("VVLAsBuildTraversal does not know this data layout!");
75 }
76 }
77
82 [[nodiscard]] bool isApplicableToDomain() const override { return true; }
83
84 [[nodiscard]] TraversalOption getTraversalType() const override { return TraversalOption::vvl_as_built; }
85
86 private:
90 PairwiseFunctor &_functor;
95};
96
97template <class ParticleCell, class Particle_T, class PairwiseFunctor>
98void VVLAsBuildTraversal<ParticleCell, Particle_T, PairwiseFunctor>::iterateAoS(
99 VerletNeighborListAsBuild<Particle_T> &neighborList) {
100 const auto &list = neighborList.getAoSNeighborList();
101
102 AUTOPAS_OPENMP(parallel num_threads(list[0].size())) {
103 constexpr int numColors = 8;
104 for (int color = 0; color < numColors; color++) {
105 AUTOPAS_OPENMP(for schedule(static))
106 for (unsigned int thread = 0; thread < list[color].size(); thread++) {
107 const auto &particleToNeighborMap = list[color][thread];
108 for (const auto &[particlePtr, neighborPtrList] : particleToNeighborMap) {
109 for (auto neighborPtr : neighborPtrList) {
110 _functor.AoSFunctor(*particlePtr, *neighborPtr, _useNewton3);
111 }
112 }
113 }
114 }
115 }
116}
117
118template <class ParticleCell, class Particle_T, class PairwiseFunctor>
119void VVLAsBuildTraversal<ParticleCell, Particle_T, PairwiseFunctor>::iterateSoA(
120 VerletNeighborListAsBuild<Particle_T> &neighborList) {
121 const auto &soaNeighborList = neighborList.getSoANeighborList();
122
123 AUTOPAS_OPENMP(parallel num_threads(soaNeighborList[0].size())) {
124 constexpr int numColors = 8;
125 for (int color = 0; color < numColors; color++) {
126 AUTOPAS_OPENMP(for schedule(static))
127 for (unsigned int thread = 0; thread < soaNeighborList[color].size(); thread++) {
128 const auto &threadNeighborList = soaNeighborList[color][thread];
129 for (const auto &[indexFirst, neighbors] : threadNeighborList) {
130 _functor.SoAFunctorVerlet(*_soa, indexFirst, neighbors, _useNewton3);
131 }
132 }
133 }
134 }
135}
136
137} // namespace autopas
#define AUTOPAS_OPENMP(args)
Empty macro to throw away any arguments.
Definition: WrapOpenMP.h:126
PairwiseFunctor class.
Definition: PairwiseFunctor.h:45
Structur of the array class.
Definition: SoA.h:28
This interface serves as a common parent class for all traversals.
Definition: TraversalInterface.h:18
DataLayoutOption _dataLayout
The datalayout used by this traversal.
Definition: TraversalInterface.h:77
Traversal for VarVerletLists with VerletNeighborListAsBuild as neighbor list.
Definition: VVLAsBuildTraversal.h:25
bool isApplicableToDomain() const override
VVL As Build is always applicable to the domain.
Definition: VVLAsBuildTraversal.h:82
void traverseParticles() override
Traverse the particles by pairs, triplets etc.
Definition: VVLAsBuildTraversal.h:64
void initTraversal() override
Initializes the traversal.
Definition: VVLAsBuildTraversal.h:49
VVLAsBuildTraversal(PairwiseFunctor &pairwiseFunctor, DataLayoutOption dataLayout, bool useNewton3)
The Constructor of VVLAsBuildTraversal.
Definition: VVLAsBuildTraversal.h:46
TraversalOption getTraversalType() const override
Return a enum representing the name of the traversal class.
Definition: VVLAsBuildTraversal.h:84
void endTraversal() override
Finalizes the traversal.
Definition: VVLAsBuildTraversal.h:56
Interface for all traversals for VarVerletLists containers.
Definition: VVLTraversalInterface.h:16
VerletNeighborListAsBuild< Particle_T > * _neighborList
The neighbor list to traverse.
Definition: VVLTraversalInterface.h:38
This class implements a neighbor list that remembers which thread added which particle pair and at wh...
Definition: VerletNeighborListAsBuild.h:22
void extractSoA(TFunctor &f)
Extracts the particle information out of the SoA returned by loadSoA() before.
Definition: VerletNeighborListAsBuild.h:226
auto * loadSoA(TFunctor &f)
Loads the particle information in the SoA and returns a pointer to the filled SoA.
Definition: VerletNeighborListAsBuild.h:200
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:64
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:34