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
44 [[nodiscard]] bool isApplicableToDomain() const override { return true; }
45
46 void initTraversal() override {
47 if (_dataLayout != DataLayoutOption::soa) return;
48
50 clusterList.loadParticlesIntoSoAs(_functor);
51 }
52
53 void endTraversal() override {
54 if (_dataLayout != DataLayoutOption::soa) return;
55
57 clusterList.extractParticlesFromSoAs(_functor);
58 }
59
60 void traverseParticles() override {
62 auto &clusterThreadPartition = clusterList.getClusterThreadPartition();
63
64 auto numThreads = clusterThreadPartition.size();
65 AUTOPAS_OPENMP(parallel num_threads(numThreads)) {
66 auto threadNum = autopas_get_thread_num();
67 const auto &clusterRange = clusterThreadPartition[threadNum];
69 size_t clusterCount = 0;
70 for (size_t towerIndex = clusterRange.startTowerIndex;
71 clusterCount < clusterRange.numClusters and towerIndex < towers.size(); towerIndex++) {
72 auto &currentTower = towers[towerIndex];
73 auto startIndexInTower =
74 clusterCount == 0 ? clusterRange.startIndexInTower : currentTower.getFirstOwnedClusterIndex();
75 for (size_t clusterIndex = startIndexInTower;
76 clusterCount < clusterRange.numClusters and clusterIndex < currentTower.getFirstTailHaloClusterIndex();
77 clusterIndex++, clusterCount++) {
78 const auto isHaloCluster = clusterIndex < currentTower.getFirstOwnedClusterIndex() or
79 clusterIndex >= currentTower.getFirstTailHaloClusterIndex();
80 _clusterFunctor.processCluster(currentTower.getCluster(clusterIndex), isHaloCluster);
81 }
82 }
83 if (clusterCount != clusterRange.numClusters) {
85 "VCLC01BalancedTraversal::traverseParticlePairs(): Not all or too many clusters traversed, probably "
86 "the clusterThreadPartitions are wrong! TraversedClusters={}, ClustersInRange={}",
87 clusterCount, clusterRange.numClusters);
88 }
89 }
90 }
91
92 bool needsStaticClusterThreadPartition() override { return true; }
93
94 private:
95 PairwiseFunctor &_functor;
97};
98} // namespace autopas
#define AUTOPAS_OPENMP(args)
Empty macro to throw away any arguments.
Definition: WrapOpenMP.h:126
PairwiseFunctor class.
Definition: PairwiseFunctor.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
Traversal for VerletClusterLists.
Definition: VCLC01BalancedTraversal.h:23
void initTraversal() override
Initializes the traversal.
Definition: VCLC01BalancedTraversal.h:46
void traverseParticles() override
Traverse the particles by pairs, triplets etc.
Definition: VCLC01BalancedTraversal.h:60
VCLC01BalancedTraversal(PairwiseFunctor &pairwiseFunctor, size_t clusterSize, DataLayoutOption dataLayout, bool useNewton3)
Constructor of the VCLC01BalancedTraversal.
Definition: VCLC01BalancedTraversal.h:32
bool isApplicableToDomain() const override
VCL C01 Balanced is always applicable to the domain.
Definition: VCLC01BalancedTraversal.h:44
void endTraversal() override
Finalizes the traversal.
Definition: VCLC01BalancedTraversal.h:53
bool needsStaticClusterThreadPartition() override
Returns whether this traversal needs the static cluster thread partition of the cluster list.
Definition: VCLC01BalancedTraversal.h:92
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:64
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:34
int autopas_get_thread_num()
Dummy for omp_set_lock() when no OpenMP is available.
Definition: WrapOpenMP.h:132