AutoPas  3.0.0
Loading...
Searching...
No Matches
VCLC01BalancedTraversal.h
Go to the documentation of this file.
1
7#pragma once
8
12
13namespace autopas {
14
22template <class Particle_T, class PairwiseFunctor>
24 public:
32 explicit VCLC01BalancedTraversal(PairwiseFunctor *pairwiseFunctor, size_t clusterSize, DataLayoutOption dataLayout,
33 bool useNewton3)
34 : TraversalInterface(dataLayout, useNewton3),
35 _functor(pairwiseFunctor),
36 _clusterFunctor(pairwiseFunctor, clusterSize, dataLayout, useNewton3) {}
37
38 [[nodiscard]] TraversalOption getTraversalType() const override { return TraversalOption::vcl_c01_balanced; }
39
40 [[nodiscard]] bool isApplicable() const override {
41 return (_dataLayout == DataLayoutOption::aos or _dataLayout == DataLayoutOption::soa) and not _useNewton3;
42 }
43
44 void initTraversal() override {
45 if (_dataLayout != DataLayoutOption::soa) return;
46
48 clusterList.loadParticlesIntoSoAs(_functor);
49 }
50
51 void endTraversal() override {
52 if (_dataLayout != DataLayoutOption::soa) return;
53
55 clusterList.extractParticlesFromSoAs(_functor);
56 }
57
58 void traverseParticles() override {
60 auto &clusterThreadPartition = clusterList.getClusterThreadPartition();
61
62 auto numThreads = clusterThreadPartition.size();
63 AUTOPAS_OPENMP(parallel num_threads(numThreads)) {
64 auto threadNum = autopas_get_thread_num();
65 const auto &clusterRange = clusterThreadPartition[threadNum];
67 size_t clusterCount = 0;
68 for (size_t towerIndex = clusterRange.startTowerIndex;
69 clusterCount < clusterRange.numClusters and towerIndex < towers.size(); towerIndex++) {
70 auto &currentTower = towers[towerIndex];
71 auto startIndexInTower =
72 clusterCount == 0 ? clusterRange.startIndexInTower : currentTower.getFirstOwnedClusterIndex();
73 for (size_t clusterIndex = startIndexInTower;
74 clusterCount < clusterRange.numClusters and clusterIndex < currentTower.getFirstTailHaloClusterIndex();
75 clusterIndex++, clusterCount++) {
76 const auto isHaloCluster = clusterIndex < currentTower.getFirstOwnedClusterIndex() or
77 clusterIndex >= currentTower.getFirstTailHaloClusterIndex();
78 _clusterFunctor.processCluster(currentTower.getCluster(clusterIndex), isHaloCluster);
79 }
80 }
81 if (clusterCount != clusterRange.numClusters) {
83 "VCLC01BalancedTraversal::traverseParticlePairs(): Not all or too many clusters traversed, probably "
84 "the clusterThreadPartitions are wrong! TraversedClusters={}, ClustersInRange={}",
85 clusterCount, clusterRange.numClusters);
86 }
87 }
88 }
89
90 bool needsStaticClusterThreadPartition() override { return true; }
91
92 private:
93 PairwiseFunctor *_functor;
95};
96} // namespace autopas
#define AUTOPAS_OPENMP(args)
Empty macro to throw away any arguments.
Definition: WrapOpenMP.h:126
PairwiseFunctor class.
Definition: PairwiseFunctor.h:31
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
Traversal for VerletClusterLists.
Definition: VCLC01BalancedTraversal.h:23
void initTraversal() override
Initializes the traversal.
Definition: VCLC01BalancedTraversal.h:44
VCLC01BalancedTraversal(PairwiseFunctor *pairwiseFunctor, size_t clusterSize, DataLayoutOption dataLayout, bool useNewton3)
Constructor of the VCLC01BalancedTraversal.
Definition: VCLC01BalancedTraversal.h:32
void traverseParticles() override
Traverse the particles by pairs, triplets etc.
Definition: VCLC01BalancedTraversal.h:58
bool isApplicable() const override
Checks if the traversal is applicable to the current state of the domain.
Definition: VCLC01BalancedTraversal.h:40
void endTraversal() override
Finalizes the traversal.
Definition: VCLC01BalancedTraversal.h:51
bool needsStaticClusterThreadPartition() override
Returns whether this traversal needs the static cluster thread partiton of the cluster list.
Definition: VCLC01BalancedTraversal.h:90
TraversalOption getTraversalType() const override
Return a enum representing the name of the traversal class.
Definition: VCLC01BalancedTraversal.h:38
Interface for traversals of the VerletClusterLists container.
Definition: VCLTraversalInterface.h:20
Provides methods to traverse a single cluster and a pair of clusters.
Definition: VCLClusterFunctor.h:21
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_thread_num()
Dummy for omp_set_lock() when no OpenMP is available.
Definition: WrapOpenMP.h:132