30template <
typename Particle_T>
38 std::vector<std::vector<std::vector<std::unique_ptr<std::mutex>>>> &spatialLocks)
39 : _spatialLocks(spatialLocks) {}
62 template <
bool newton3,
class ContainerType,
class PairwiseFunctor>
74 timerBufferContainer.
start();
81 remainderHelperBufferContainerAoS<newton3>(f, container, particleBuffers, haloParticleBuffers);
83 timerBufferContainer.
stop();
84 timerBufferSoAConversion.
start();
88 for (
auto &buffer : particleBuffers) {
89 f->
SoALoader(buffer, buffer._particleSoABuffer, 0,
false);
91 for (
auto &buffer : haloParticleBuffers) {
92 f->
SoALoader(buffer, buffer._particleSoABuffer, 0,
false);
96 timerBufferSoAConversion.
stop();
97 timerPBufferPBuffer.
start();
100 remainderHelperBufferBuffer<newton3>(f, particleBuffers, useSoA);
102 timerPBufferPBuffer.
stop();
103 timerPBufferHBuffer.
start();
106 remainderHelperBufferHaloBuffer(f, particleBuffers, haloParticleBuffers, useSoA);
108 timerPBufferHBuffer.
stop();
109 timerBufferSoAConversion.
start();
113 for (
auto &buffer : particleBuffers) f->
SoAExtractor(buffer, buffer._particleSoABuffer, 0);
116 timerBufferSoAConversion.
stop();
130 std::vector<std::vector<std::vector<std::unique_ptr<std::mutex>>>> &_spatialLocks;
145 template <
bool newton3,
class ContainerType,
class PairwiseFunctor>
146 void remainderHelperBufferContainerAoS(
PairwiseFunctor *f, ContainerType &container,
150 using namespace autopas::utils::ArrayMath::literals;
153 const auto cutoff = container.getCutoff();
154 const auto interactionLength = container.getInteractionLength();
155 const auto haloBoxMin = container.getBoxMin() - interactionLength;
156 const auto totalBoxLengthInv = 1. / (container.getBoxMax() + interactionLength - haloBoxMin);
157 const std::array<size_t, 3> spacialLocksPerDim{_spatialLocks.size(), _spatialLocks[0].size(),
158 _spatialLocks[0][0].size()};
162 const auto getSpacialLock = [&](
const std::array<double, 3> &pos) -> std::mutex & {
163 const auto posDistFromLowerCorner = pos - haloBoxMin;
164 const auto relativePos = posDistFromLowerCorner * totalBoxLengthInv;
166 const auto lockCoords =
167 static_cast_copy_array<size_t>(static_cast_copy_array<double>(spacialLocksPerDim) * relativePos);
168 return *_spatialLocks[lockCoords[0]][lockCoords[1]][lockCoords[2]];
173 for (
int bufferId = 0; bufferId < particleBuffers.size(); ++bufferId) {
174 auto &particleBuffer = particleBuffers[bufferId];
175 auto &haloParticleBuffer = haloParticleBuffers[bufferId];
178 for (
auto &&p1 : particleBuffer) {
179 const auto min = p1.getR() - cutoff;
180 const auto max = p1.getR() + cutoff;
181 container.forEachInRegion(
183 if constexpr (newton3) {
184 const std::lock_guard<std::mutex> lock(getSpacialLock(p2.getR()));
189 if (not p2.isHalo()) {
190 const std::lock_guard<std::mutex> lock(getSpacialLock(p2.getR()));
195 min,
max, IteratorBehavior::ownedOrHalo);
199 for (
auto &&p1halo : haloParticleBuffer) {
200 const auto min = p1halo.getR() - cutoff;
201 const auto max = p1halo.getR() + cutoff;
202 container.forEachInRegion(
207 const std::lock_guard<std::mutex> lock(getSpacialLock(p2.getR()));
210 min,
max, IteratorBehavior::owned);
224 template <
bool newton3,
class PairwiseFunctor>
228 remainderHelperBufferBufferSoA<newton3>(f, particleBuffers);
230 remainderHelperBufferBufferAoS<newton3>(f, particleBuffers);
240 template <
bool newton3,
class PairwiseFunctor>
248 for (
size_t bufferIdxI = 0; bufferIdxI < particleBuffers.size(); ++bufferIdxI) {
249 for (
size_t bufferIdxJOffset = 0; bufferIdxJOffset < particleBuffers.size(); ++bufferIdxJOffset) {
251 const auto bufferIdxJ = (bufferIdxI + bufferIdxJOffset) % particleBuffers.size();
254 if (bufferIdxI == bufferIdxJ) {
257 const bool useNewton3 = newton3;
258 auto &bufferRef = particleBuffers[bufferIdxI];
259 const auto bufferSize = bufferRef.size();
260 for (
auto i = 0; i < bufferSize; ++i) {
261 auto &p1 = bufferRef[i];
263 for (
auto j = useNewton3 ? i + 1 : 0; j < bufferSize; ++j) {
267 auto &p2 = bufferRef[j];
273 for (
auto &p1 : particleBuffers[bufferIdxI]) {
274 for (
auto &p2 : particleBuffers[bufferIdxJ]) {
290 template <
bool newton3,
class PairwiseFunctor>
294 for (
size_t i = 0; i < particleBuffers.size(); ++i) {
295 for (
size_t jj = 0; jj < particleBuffers.size(); ++jj) {
296 auto *particleBufferSoAA = &particleBuffers[i]._particleSoABuffer;
299 const auto j = (i + jj) % particleBuffers.size();
306 auto *particleBufferSoAB = &particleBuffers[j]._particleSoABuffer;
307 f->
SoAFunctorPair(*particleBufferSoAA, *particleBufferSoAB,
false);
326 template <
class PairwiseFunctor>
330 remainderHelperBufferHaloBufferSoA(f, particleBuffers, haloParticleBuffers);
332 remainderHelperBufferHaloBufferAoS(f, particleBuffers, haloParticleBuffers);
342 template <
class PairwiseFunctor>
348 for (
int interactionOffset = 0; interactionOffset < haloParticleBuffers.size(); ++interactionOffset) {
350 for (
size_t i = 0; i < particleBuffers.size(); ++i) {
351 auto &particleBuffer = particleBuffers[i];
352 auto &haloBuffer = haloParticleBuffers[(i + interactionOffset) % haloParticleBuffers.size()];
354 for (
auto &p1 : particleBuffer) {
355 for (
auto &p2 : haloBuffer) {
370 template <
class PairwiseFunctor>
376 for (
int interactionOffset = 0; interactionOffset < haloParticleBuffers.size(); ++interactionOffset) {
378 for (
size_t i = 0; i < particleBuffers.size(); ++i) {
379 auto &particleBufferSoA = particleBuffers[i]._particleSoABuffer;
380 auto &haloBufferSoA =
381 haloParticleBuffers[(i + interactionOffset) % haloParticleBuffers.size()]._particleSoABuffer;
#define AutoPasLog(lvl, fmt,...)
Macro for logging providing common meta information without filename.
Definition: Logger.h:24
#define AUTOPAS_OPENMP(args)
Empty macro to throw away any arguments.
Definition: WrapOpenMP.h:126
This class handles the storage of particles in their full form.
Definition: FullParticleCell.h:26
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 SoAFunctorPair(SoAView< SoAArraysType > soa1, SoAView< SoAArraysType > soa2, bool newton3)
PairwiseFunctor for structure of arrays (SoA)
Definition: PairwiseFunctor.h:116
virtual void SoAFunctorSingle(SoAView< SoAArraysType > soa, bool newton3)
PairwiseFunctor for structure of arrays (SoA)
Definition: PairwiseFunctor.h:84
Handles pairwise interactions involving particle buffers (particles not yet inserted into the main co...
Definition: RemainderPairwiseInteractionHandler.h:31
void computeRemainderInteractions(PairwiseFunctor *f, ContainerType &container, std::vector< FullParticleCell< Particle_T > > &particleBuffers, std::vector< FullParticleCell< Particle_T > > &haloParticleBuffers, bool useSoA)
Performs the interactions ParticleContainer::computeInteractions() did not cover.
Definition: RemainderPairwiseInteractionHandler.h:63
RemainderPairwiseInteractionHandler(std::vector< std::vector< std::vector< std::unique_ptr< std::mutex > > > > &spatialLocks)
Constructor for RemainderPairwiseInteractionHandler.
Definition: RemainderPairwiseInteractionHandler.h:37
A wrapper around autopas::utils::Timer that only compiles implementation logic if the SPDLOG_ACTIVE_L...
Definition: TraceTimer.h:20
long getTotalTime() const
Get total accumulated time.
Definition: TraceTimer.h:63
void start()
start the timer.
Definition: TraceTimer.h:25
long stop()
Stops the timer and returns the time elapsed in nanoseconds since the last call to start.
Definition: TraceTimer.h:34
constexpr std::array< T, SIZE > max(const std::array< T, SIZE > &a, const std::array< T, SIZE > &b)
Takes elementwise maximum and returns the result.
Definition: ArrayMath.h:96
constexpr std::array< T, SIZE > min(const std::array< T, SIZE > &a, const std::array< T, SIZE > &b)
Takes elementwise minimum, returns the result.
Definition: ArrayMath.h:62
constexpr std::array< output_t, SIZE > static_cast_copy_array(const std::array< input_t, SIZE > &a)
Creates a new array by performing an element-wise static_cast<>.
Definition: ArrayUtils.h:33
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:34