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
78 [[nodiscard]] bool isApplicable() const override {
79 return _dataLayout == DataLayoutOption::soa || _dataLayout == DataLayoutOption::aos;
80 }
81
82 [[nodiscard]] TraversalOption getTraversalType() const override { return TraversalOption::vvl_as_built; }
83
84 private:
88 PairwiseFunctor *_functor;
93};
94
95template <class ParticleCell, class Particle_T, class PairwiseFunctor>
96void VVLAsBuildTraversal<ParticleCell, Particle_T, PairwiseFunctor>::iterateAoS(
97 VerletNeighborListAsBuild<Particle_T> &neighborList) {
98 const auto &list = neighborList.getAoSNeighborList();
99
100 AUTOPAS_OPENMP(parallel num_threads(list[0].size())) {
101 constexpr int numColors = 8;
102 for (int color = 0; color < numColors; color++) {
103 AUTOPAS_OPENMP(for schedule(static))
104 for (unsigned int thread = 0; thread < list[color].size(); thread++) {
105 const auto &particleToNeighborMap = list[color][thread];
106 for (const auto &[particlePtr, neighborPtrList] : particleToNeighborMap) {
107 for (auto neighborPtr : neighborPtrList) {
108 _functor->AoSFunctor(*particlePtr, *neighborPtr, _useNewton3);
109 }
110 }
111 }
112 }
113 }
114}
115
116template <class ParticleCell, class Particle_T, class PairwiseFunctor>
117void VVLAsBuildTraversal<ParticleCell, Particle_T, PairwiseFunctor>::iterateSoA(
118 VerletNeighborListAsBuild<Particle_T> &neighborList) {
119 const auto &soaNeighborList = neighborList.getSoANeighborList();
120
121 AUTOPAS_OPENMP(parallel num_threads(soaNeighborList[0].size())) {
122 constexpr int numColors = 8;
123 for (int color = 0; color < numColors; color++) {
124 AUTOPAS_OPENMP(for schedule(static))
125 for (unsigned int thread = 0; thread < soaNeighborList[color].size(); thread++) {
126 const auto &threadNeighborList = soaNeighborList[color][thread];
127 for (const auto &[indexFirst, neighbors] : threadNeighborList) {
128 _functor->SoAFunctorVerlet(*_soa, indexFirst, neighbors, _useNewton3);
129 }
130 }
131 }
132 }
133}
134
135} // namespace autopas
#define AUTOPAS_OPENMP(args)
Empty macro to throw away any arguments.
Definition: WrapOpenMP.h:126
PairwiseFunctor class.
Definition: PairwiseFunctor.h:31
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:75
Traversal for VarVerletLists with VerletNeighborListAsBuild as neighbor list.
Definition: VVLAsBuildTraversal.h:25
void traverseParticles() override
Traverse the particles by pairs, triplets etc.
Definition: VVLAsBuildTraversal.h:64
VVLAsBuildTraversal(PairwiseFunctor *pairwiseFunctor, DataLayoutOption dataLayout, bool useNewton3)
The Constructor of VVLAsBuildTraversal.
Definition: VVLAsBuildTraversal.h:46
void initTraversal() override
Initializes the traversal.
Definition: VVLAsBuildTraversal.h:49
TraversalOption getTraversalType() const override
Return a enum representing the name of the traversal class.
Definition: VVLAsBuildTraversal.h:82
bool isApplicable() const override
Checks if the traversal is applicable to the current state of the domain.
Definition: VVLAsBuildTraversal.h:78
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
auto * loadSoA(TFunctor *f)
Loads the particle information in the SoA and returns a pointer to the filled SoA.
Definition: VerletNeighborListAsBuild.h:200
void extractSoA(TFunctor *f)
Extracts the particle information out of the SoA returned by loadSoA() before.
Definition: VerletNeighborListAsBuild.h:226
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:63
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32