AutoPas  3.0.0
Loading...
Searching...
No Matches
VLListIterationTraversal.h
Go to the documentation of this file.
1
7#pragma once
8
14
15namespace autopas {
16
23template <class ParticleCell, class PairwiseFunctor>
25 using ParticleType = typename ParticleCell::ParticleType;
26
27 public:
34 explicit VLListIterationTraversal(PairwiseFunctor &pairwiseFunctor, DataLayoutOption dataLayout, bool useNewton3)
35 : TraversalInterface(dataLayout, useNewton3), _functor(pairwiseFunctor) {}
36
37 [[nodiscard]] TraversalOption getTraversalType() const override { return TraversalOption::vl_list_iteration; }
38
43 [[nodiscard]] bool isApplicableToDomain() const override { return true; }
44
45 void initTraversal() override {
46 auto &cells = *(this->_cells);
47 if (_dataLayout == DataLayoutOption::soa) {
48 // First resize the SoA to the required number of elements to store. This avoids resizing successively the SoA in
49 // SoALoader.
50 std::vector<size_t> offsets(cells.size() + 1);
51 std::inclusive_scan(
52 cells.begin(), cells.end(), offsets.begin() + 1,
53 [](const size_t &partialSum, const auto &cell) { return partialSum + cell.size(); }, 0);
54
55 _soa.resizeArrays(offsets.back());
56
57 AUTOPAS_OPENMP(parallel for)
58 for (size_t i = 0; i < cells.size(); ++i) {
59 _functor.SoALoader(cells[i], _soa, offsets[i], /*skipSoAResize*/ true);
60 }
61 }
62 }
63
64 void endTraversal() override {
65 auto &cells = *(this->_cells);
66 if (_dataLayout == DataLayoutOption::soa) {
67 size_t offset = 0;
68 for (auto &cell : cells) {
69 _functor.SoAExtractor(cell, _soa, offset);
70 offset += cell.size();
71 }
72 }
73 }
74
75 void traverseParticles() override {
76 auto &aosNeighborLists = *(this->_aosNeighborLists);
77 auto &soaNeighborLists = *(this->_soaNeighborLists);
78 switch (this->_dataLayout) {
79 case DataLayoutOption::aos: {
80 // If we use parallelization,
81 if (not _useNewton3) {
82 size_t buckets = aosNeighborLists.bucket_count();
84 AUTOPAS_OPENMP(parallel for schedule(dynamic))
85 for (size_t bucketId = 0; bucketId < buckets; bucketId++) {
86 auto endIter = aosNeighborLists.end(bucketId);
87 for (auto bucketIter = aosNeighborLists.begin(bucketId); bucketIter != endIter; ++bucketIter) {
88 ParticleType &particle = *(bucketIter->first);
89 for (auto neighborPtr : bucketIter->second) {
90 ParticleType &neighbor = *neighborPtr;
91 _functor.AoSFunctor(particle, neighbor, false);
92 }
93 }
94 }
95 } else {
96 for (auto &[particlePtr, neighborPtrList] : aosNeighborLists) {
97 ParticleType &particle = *particlePtr;
98 for (auto neighborPtr : neighborPtrList) {
99 ParticleType &neighbor = *neighborPtr;
100 _functor.AoSFunctor(particle, neighbor, _useNewton3);
101 }
102 }
103 }
104 return;
105 }
106
107 case DataLayoutOption::soa: {
108 if (not _useNewton3) {
110 AUTOPAS_OPENMP(parallel for schedule(dynamic, std::max(soaNeighborLists.size() / (autopas::autopas_get_max_threads() * 10), 1ul)))
111 for (size_t particleIndex = 0; particleIndex < soaNeighborLists.size(); particleIndex++) {
112 _functor.SoAFunctorVerlet(_soa, particleIndex, soaNeighborLists[particleIndex], _useNewton3);
113 }
114 } else {
115 // iterate over SoA
116 for (size_t particleIndex = 0; particleIndex < soaNeighborLists.size(); particleIndex++) {
117 _functor.SoAFunctorVerlet(_soa, particleIndex, soaNeighborLists[particleIndex], _useNewton3);
118 }
119 }
120 return;
121 }
122 default: {
123 utils::ExceptionHandler::exception("VerletList dataLayout {} not available", _dataLayout);
124 }
125 }
126 }
127
128 private:
132 PairwiseFunctor &_functor;
133
138};
139
140} // namespace autopas
#define AUTOPAS_OPENMP(args)
Empty macro to throw away any arguments.
Definition: WrapOpenMP.h:126
void SoALoader(ParticleCell &cell, SoA< SoAArraysType > &soa, size_t offset, bool skipSoAResize)
Copies the AoS data of the given cell in the given soa.
Definition: Functor.h:127
void SoAExtractor(ParticleCell &cell, SoA< SoAArraysType > &soa, size_t offset)
Copies the data stored in the soa back into the cell.
Definition: Functor.h:141
PairwiseFunctor class.
Definition: PairwiseFunctor.h:45
virtual void AoSFunctor(Particle_T &i, Particle_T &j, bool newton3)
PairwiseFunctor for arrays of structures (AoS).
Definition: PairwiseFunctor.h:70
virtual void SoAFunctorVerlet(SoAView< SoAArraysType > soa, const size_t indexFirst, const std::vector< size_t, AlignedAllocator< size_t > > &neighborList, bool newton3)
PairwiseFunctor for structure of arrays (SoA) for neighbor lists.
Definition: PairwiseFunctor.h:100
Particle_T ParticleType
The particle type for this cell.
Definition: ParticleCell.h:54
Structur of the array class.
Definition: SoA.h:28
void resizeArrays(size_t length)
Resizes all Vectors to the given length.
Definition: SoA.h:45
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
bool _useNewton3
If this traversal makes use of newton3.
Definition: TraversalInterface.h:82
This class provides a Traversal for the verlet lists container.
Definition: VLListIterationTraversal.h:24
TraversalOption getTraversalType() const override
Return a enum representing the name of the traversal class.
Definition: VLListIterationTraversal.h:37
void endTraversal() override
Finalizes the traversal.
Definition: VLListIterationTraversal.h:64
void initTraversal() override
Initializes the traversal.
Definition: VLListIterationTraversal.h:45
void traverseParticles() override
Traverse the particles by pairs, triplets etc.
Definition: VLListIterationTraversal.h:75
VLListIterationTraversal(PairwiseFunctor &pairwiseFunctor, DataLayoutOption dataLayout, bool useNewton3)
Constructor for Verlet Traversal.
Definition: VLListIterationTraversal.h:34
bool isApplicableToDomain() const override
VL List iteration is always applicable to the domain.
Definition: VLListIterationTraversal.h:43
This class provides the Traversal Interface for the verlet lists container.
Definition: VLTraversalInterface.h:22
VerletListHelpers< typenameLinkedParticleCell::ParticleType >::NeighborListAoSType * _aosNeighborLists
The AoS neighbor list of the verlet lists container.
Definition: VLTraversalInterface.h:52
std::vector< ParticleCell > * _cells
The cells of the underlying linked cells container of the verlet lists container.
Definition: VLTraversalInterface.h:48
std::vector< std::vector< size_t, autopas::AlignedAllocator< size_t > > > * _soaNeighborLists
The SoA neighbor list of the verlet lists container.
Definition: VLTraversalInterface.h:57
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
int autopas_get_max_threads()
Dummy for omp_get_max_threads() when no OpenMP is available.
Definition: WrapOpenMP.h:144