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
39 [[nodiscard]] bool isApplicable() const override {
40 // No parallel version with N3 and no data races is available, hence no N3 is completely disabled.
41 return (not _useNewton3) and (_dataLayout == DataLayoutOption::aos or _dataLayout == DataLayoutOption::soa);
42 }
43
44 void initTraversal() override {
45 auto &cells = *(this->_cells);
46 if (_dataLayout == DataLayoutOption::soa) {
47 // First resize the SoA to the required number of elements to store. This avoids resizing successively the SoA in
48 // SoALoader.
49 std::vector<size_t> offsets(cells.size() + 1);
50 std::inclusive_scan(
51 cells.begin(), cells.end(), offsets.begin() + 1,
52 [](const size_t &partialSum, const auto &cell) { return partialSum + cell.size(); }, 0);
53
54 _soa.resizeArrays(offsets.back());
55
56 AUTOPAS_OPENMP(parallel for)
57 for (size_t i = 0; i < cells.size(); ++i) {
58 _functor->SoALoader(cells[i], _soa, offsets[i], /*skipSoAResize*/ true);
59 }
60 }
61 }
62
63 void endTraversal() override {
64 auto &cells = *(this->_cells);
65 if (_dataLayout == DataLayoutOption::soa) {
66 size_t offset = 0;
67 for (auto &cell : cells) {
68 _functor->SoAExtractor(cell, _soa, offset);
69 offset += cell.size();
70 }
71 }
72 }
73
74 void traverseParticles() override {
75 auto &aosNeighborLists = *(this->_aosNeighborLists);
76 auto &soaNeighborLists = *(this->_soaNeighborLists);
77 switch (this->_dataLayout) {
78 case DataLayoutOption::aos: {
79 // If we use parallelization,
80 if (not _useNewton3) {
81 size_t buckets = aosNeighborLists.bucket_count();
83 AUTOPAS_OPENMP(parallel for schedule(dynamic))
84 for (size_t bucketId = 0; bucketId < buckets; bucketId++) {
85 auto endIter = aosNeighborLists.end(bucketId);
86 for (auto bucketIter = aosNeighborLists.begin(bucketId); bucketIter != endIter; ++bucketIter) {
87 ParticleType &particle = *(bucketIter->first);
88 for (auto neighborPtr : bucketIter->second) {
89 ParticleType &neighbor = *neighborPtr;
90 _functor->AoSFunctor(particle, neighbor, false);
91 }
92 }
93 }
94 } else {
95 for (auto &[particlePtr, neighborPtrList] : aosNeighborLists) {
96 ParticleType &particle = *particlePtr;
97 for (auto neighborPtr : neighborPtrList) {
98 ParticleType &neighbor = *neighborPtr;
99 _functor->AoSFunctor(particle, neighbor, _useNewton3);
100 }
101 }
102 }
103 return;
104 }
105
106 case DataLayoutOption::soa: {
107 if (not _useNewton3) {
109 AUTOPAS_OPENMP(parallel for schedule(dynamic, std::max(soaNeighborLists.size() / (autopas::autopas_get_max_threads() * 10), 1ul)))
110 for (size_t particleIndex = 0; particleIndex < soaNeighborLists.size(); particleIndex++) {
111 _functor->SoAFunctorVerlet(_soa, particleIndex, soaNeighborLists[particleIndex], _useNewton3);
112 }
113 } else {
114 // iterate over SoA
115 for (size_t particleIndex = 0; particleIndex < soaNeighborLists.size(); particleIndex++) {
116 _functor->SoAFunctorVerlet(_soa, particleIndex, soaNeighborLists[particleIndex], _useNewton3);
117 }
118 }
119 return;
120 }
121 default: {
122 utils::ExceptionHandler::exception("VerletList dataLayout {} not available", _dataLayout);
123 }
124 }
125 }
126
127 private:
131 PairwiseFunctor *_functor;
132
137};
138
139} // 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:112
void SoAExtractor(ParticleCell &cell, SoA< SoAArraysType > &soa, size_t offset)
Copies the data stored in the soa back into the cell.
Definition: Functor.h:126
PairwiseFunctor class.
Definition: PairwiseFunctor.h:31
virtual void AoSFunctor(Particle_T &i, Particle_T &j, bool newton3)
PairwiseFunctor for arrays of structures (AoS).
Definition: PairwiseFunctor.h:56
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:86
Particle_T ParticleType
The particle type for this cell.
Definition: ParticleCell.h:56
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:75
bool _useNewton3
If this traversal makes use of newton3.
Definition: TraversalInterface.h:80
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
VLListIterationTraversal(PairwiseFunctor *pairwiseFunctor, DataLayoutOption dataLayout, bool useNewton3)
Constructor for Verlet Traversal.
Definition: VLListIterationTraversal.h:34
bool isApplicable() const override
Checks if the traversal is applicable to the current state of the domain.
Definition: VLListIterationTraversal.h:39
void endTraversal() override
Finalizes the traversal.
Definition: VLListIterationTraversal.h:63
void initTraversal() override
Initializes the traversal.
Definition: VLListIterationTraversal.h:44
void traverseParticles() override
Traverse the particles by pairs, triplets etc.
Definition: VLListIterationTraversal.h:74
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:63
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32
int autopas_get_max_threads()
Dummy for omp_get_max_threads() when no OpenMP is available.
Definition: WrapOpenMP.h:144