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>
69 auto cellToVec = [](
auto &cell) -> std::vector<Particle_T> & {
return cell._particles; };
77#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
78 autopas::utils::Timer timerBufferContainer, timerPBufferPBuffer, timerPBufferHBuffer, timerBufferSoAConversion;
79 timerBufferContainer.
start();
86 remainderHelperBufferContainerAoS<newton3>(f, container, particleBuffers, haloParticleBuffers);
88#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
89 timerBufferContainer.
stop();
90 timerBufferSoAConversion.
start();
95 for (
auto &buffer : particleBuffers) {
96 f->
SoALoader(buffer, buffer._particleSoABuffer, 0,
false);
98 for (
auto &buffer : haloParticleBuffers) {
99 f->
SoALoader(buffer, buffer._particleSoABuffer, 0,
false);
102#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
103 timerBufferSoAConversion.
stop();
104 timerPBufferPBuffer.
start();
108 remainderHelperBufferBuffer<newton3>(f, particleBuffers, useSoA);
110#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
111 timerPBufferPBuffer.
stop();
112 timerPBufferHBuffer.
start();
116 remainderHelperBufferHaloBuffer(f, particleBuffers, haloParticleBuffers, useSoA);
118#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
119 timerPBufferHBuffer.
stop();
120 timerBufferSoAConversion.
start();
125 for (
auto &buffer : particleBuffers) f->
SoAExtractor(buffer, buffer._particleSoABuffer, 0);
128#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
129 timerBufferSoAConversion.
stop();
144 std::vector<std::vector<std::vector<std::unique_ptr<std::mutex>>>> &_spatialLocks;
159 template <
bool newton3,
class ContainerType,
class PairwiseFunctor>
160 void remainderHelperBufferContainerAoS(
PairwiseFunctor *f, ContainerType &container,
164 using namespace autopas::utils::ArrayMath::literals;
167 const auto cutoff = container.getCutoff();
168 const auto interactionLength = container.getInteractionLength();
169 const auto haloBoxMin = container.getBoxMin() - interactionLength;
170 const auto totalBoxLengthInv = 1. / (container.getBoxMax() + interactionLength - haloBoxMin);
171 const std::array<size_t, 3> spacialLocksPerDim{_spatialLocks.size(), _spatialLocks[0].size(),
172 _spatialLocks[0][0].size()};
176 const auto getSpacialLock = [&](
const std::array<double, 3> &pos) -> std::mutex & {
177 const auto posDistFromLowerCorner = pos - haloBoxMin;
178 const auto relativePos = posDistFromLowerCorner * totalBoxLengthInv;
180 const auto lockCoords =
181 static_cast_copy_array<size_t>(static_cast_copy_array<double>(spacialLocksPerDim) * relativePos);
182 return *_spatialLocks[lockCoords[0]][lockCoords[1]][lockCoords[2]];
187 for (
int bufferId = 0; bufferId < particleBuffers.size(); ++bufferId) {
188 auto &particleBuffer = particleBuffers[bufferId];
189 auto &haloParticleBuffer = haloParticleBuffers[bufferId];
192 for (
auto &&p1 : particleBuffer) {
193 const auto min = p1.getR() - cutoff;
194 const auto max = p1.getR() + cutoff;
195 container.forEachInRegion(
197 if constexpr (newton3) {
198 const std::lock_guard<std::mutex> lock(getSpacialLock(p2.getR()));
203 if (not p2.isHalo()) {
204 const std::lock_guard<std::mutex> lock(getSpacialLock(p2.getR()));
209 min,
max, IteratorBehavior::ownedOrHalo);
213 for (
auto &&p1halo : haloParticleBuffer) {
214 const auto min = p1halo.getR() - cutoff;
215 const auto max = p1halo.getR() + cutoff;
216 container.forEachInRegion(
221 const std::lock_guard<std::mutex> lock(getSpacialLock(p2.getR()));
224 min,
max, IteratorBehavior::owned);
238 template <
bool newton3,
class PairwiseFunctor>
242 remainderHelperBufferBufferSoA<newton3>(f, particleBuffers);
244 remainderHelperBufferBufferAoS<newton3>(f, particleBuffers);
254 template <
bool newton3,
class PairwiseFunctor>
262 for (
size_t bufferIdxI = 0; bufferIdxI < particleBuffers.size(); ++bufferIdxI) {
263 for (
size_t bufferIdxJOffset = 0; bufferIdxJOffset < particleBuffers.size(); ++bufferIdxJOffset) {
265 const auto bufferIdxJ = (bufferIdxI + bufferIdxJOffset) % particleBuffers.size();
268 if (bufferIdxI == bufferIdxJ) {
271 const bool useNewton3 = newton3;
272 auto &bufferRef = particleBuffers[bufferIdxI];
273 const auto bufferSize = bufferRef.size();
274 for (
auto i = 0; i < bufferSize; ++i) {
275 auto &p1 = bufferRef[i];
277 for (
auto j = useNewton3 ? i + 1 : 0; j < bufferSize; ++j) {
281 auto &p2 = bufferRef[j];
287 for (
auto &p1 : particleBuffers[bufferIdxI]) {
288 for (
auto &p2 : particleBuffers[bufferIdxJ]) {
304 template <
bool newton3,
class PairwiseFunctor>
308 for (
size_t i = 0; i < particleBuffers.size(); ++i) {
309 for (
size_t jj = 0; jj < particleBuffers.size(); ++jj) {
310 auto *particleBufferSoAA = &particleBuffers[i]._particleSoABuffer;
313 const auto j = (i + jj) % particleBuffers.size();
320 auto *particleBufferSoAB = &particleBuffers[j]._particleSoABuffer;
321 f->
SoAFunctorPair(*particleBufferSoAA, *particleBufferSoAB,
false);
340 template <
class PairwiseFunctor>
344 remainderHelperBufferHaloBufferSoA(f, particleBuffers, haloParticleBuffers);
346 remainderHelperBufferHaloBufferAoS(f, particleBuffers, haloParticleBuffers);
356 template <
class PairwiseFunctor>
362 for (
int interactionOffset = 0; interactionOffset < haloParticleBuffers.size(); ++interactionOffset) {
364 for (
size_t i = 0; i < particleBuffers.size(); ++i) {
365 auto &particleBuffer = particleBuffers[i];
366 auto &haloBuffer = haloParticleBuffers[(i + interactionOffset) % haloParticleBuffers.size()];
368 for (
auto &p1 : particleBuffer) {
369 for (
auto &p2 : haloBuffer) {
384 template <
class PairwiseFunctor>
390 for (
int interactionOffset = 0; interactionOffset < haloParticleBuffers.size(); ++interactionOffset) {
392 for (
size_t i = 0; i < particleBuffers.size(); ++i) {
393 auto &particleBufferSoA = particleBuffers[i]._particleSoABuffer;
394 auto &haloBufferSoA =
395 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: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 SoAFunctorPair(SoAView< SoAArraysType > soa1, SoAView< SoAArraysType > soa2, bool newton3)
PairwiseFunctor for structure of arrays (SoA)
Definition: PairwiseFunctor.h:102
virtual void SoAFunctorSingle(SoAView< SoAArraysType > soa, bool newton3)
PairwiseFunctor for structure of arrays (SoA)
Definition: PairwiseFunctor.h:70
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
Timer class to stop times.
Definition: Timer.h:20
void start()
start the timer.
Definition: Timer.cpp:17
long getTotalTime() const
Get total accumulated time.
Definition: Timer.h:53
long stop()
Stops the timer and returns the time elapsed in nanoseconds since the last call to start.
Definition: Timer.cpp:25
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
void balanceVectors(OuterContainerT &vecvec)
Given a collection of vectors, redistributes the elements of the vectors so they all have the same (o...
Definition: ArrayUtils.h:151
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:32