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; };
81 timerBufferContainer.
start();
88 remainderHelperBufferContainerAoS<newton3>(f, container, particleBuffers, haloParticleBuffers);
90 timerBufferContainer.
stop();
91 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);
103 timerBufferSoAConversion.
stop();
104 timerPBufferPBuffer.
start();
107 remainderHelperBufferBuffer<newton3>(f, particleBuffers, useSoA);
109 timerPBufferPBuffer.
stop();
110 timerPBufferHBuffer.
start();
113 remainderHelperBufferHaloBuffer(f, particleBuffers, haloParticleBuffers, useSoA);
115 timerPBufferHBuffer.
stop();
116 timerBufferSoAConversion.
start();
120 for (
auto &buffer : particleBuffers) f->
SoAExtractor(buffer, buffer._particleSoABuffer, 0);
123 timerBufferSoAConversion.
stop();
137 std::vector<std::vector<std::vector<std::unique_ptr<std::mutex>>>> &_spatialLocks;
152 template <
bool newton3,
class ContainerType,
class PairwiseFunctor>
153 void remainderHelperBufferContainerAoS(
PairwiseFunctor *f, ContainerType &container,
157 using namespace autopas::utils::ArrayMath::literals;
160 const auto cutoff = container.getCutoff();
161 const auto interactionLength = container.getInteractionLength();
162 const auto haloBoxMin = container.getBoxMin() - interactionLength;
163 const auto totalBoxLengthInv = 1. / (container.getBoxMax() + interactionLength - haloBoxMin);
164 const std::array<size_t, 3> spacialLocksPerDim{_spatialLocks.size(), _spatialLocks[0].size(),
165 _spatialLocks[0][0].size()};
169 const auto getSpacialLock = [&](
const std::array<double, 3> &pos) -> std::mutex & {
170 const auto posDistFromLowerCorner = pos - haloBoxMin;
171 const auto relativePos = posDistFromLowerCorner * totalBoxLengthInv;
173 const auto lockCoords =
174 static_cast_copy_array<size_t>(static_cast_copy_array<double>(spacialLocksPerDim) * relativePos);
175 return *_spatialLocks[lockCoords[0]][lockCoords[1]][lockCoords[2]];
180 for (
int bufferId = 0; bufferId < particleBuffers.size(); ++bufferId) {
181 auto &particleBuffer = particleBuffers[bufferId];
182 auto &haloParticleBuffer = haloParticleBuffers[bufferId];
185 for (
auto &&p1 : particleBuffer) {
186 const auto min = p1.getR() - cutoff;
187 const auto max = p1.getR() + cutoff;
188 container.forEachInRegion(
190 if constexpr (newton3) {
191 const std::lock_guard<std::mutex> lock(getSpacialLock(p2.getR()));
196 if (not p2.isHalo()) {
197 const std::lock_guard<std::mutex> lock(getSpacialLock(p2.getR()));
202 min,
max, IteratorBehavior::ownedOrHalo);
206 for (
auto &&p1halo : haloParticleBuffer) {
207 const auto min = p1halo.getR() - cutoff;
208 const auto max = p1halo.getR() + cutoff;
209 container.forEachInRegion(
214 const std::lock_guard<std::mutex> lock(getSpacialLock(p2.getR()));
217 min,
max, IteratorBehavior::owned);
231 template <
bool newton3,
class PairwiseFunctor>
235 remainderHelperBufferBufferSoA<newton3>(f, particleBuffers);
237 remainderHelperBufferBufferAoS<newton3>(f, particleBuffers);
247 template <
bool newton3,
class PairwiseFunctor>
255 for (
size_t bufferIdxI = 0; bufferIdxI < particleBuffers.size(); ++bufferIdxI) {
256 for (
size_t bufferIdxJOffset = 0; bufferIdxJOffset < particleBuffers.size(); ++bufferIdxJOffset) {
258 const auto bufferIdxJ = (bufferIdxI + bufferIdxJOffset) % particleBuffers.size();
261 if (bufferIdxI == bufferIdxJ) {
264 const bool useNewton3 = newton3;
265 auto &bufferRef = particleBuffers[bufferIdxI];
266 const auto bufferSize = bufferRef.size();
267 for (
auto i = 0; i < bufferSize; ++i) {
268 auto &p1 = bufferRef[i];
270 for (
auto j = useNewton3 ? i + 1 : 0; j < bufferSize; ++j) {
274 auto &p2 = bufferRef[j];
280 for (
auto &p1 : particleBuffers[bufferIdxI]) {
281 for (
auto &p2 : particleBuffers[bufferIdxJ]) {
297 template <
bool newton3,
class PairwiseFunctor>
301 for (
size_t i = 0; i < particleBuffers.size(); ++i) {
302 for (
size_t jj = 0; jj < particleBuffers.size(); ++jj) {
303 auto *particleBufferSoAA = &particleBuffers[i]._particleSoABuffer;
306 const auto j = (i + jj) % particleBuffers.size();
313 auto *particleBufferSoAB = &particleBuffers[j]._particleSoABuffer;
314 f->
SoAFunctorPair(*particleBufferSoAA, *particleBufferSoAB,
false);
333 template <
class PairwiseFunctor>
337 remainderHelperBufferHaloBufferSoA(f, particleBuffers, haloParticleBuffers);
339 remainderHelperBufferHaloBufferAoS(f, particleBuffers, haloParticleBuffers);
349 template <
class PairwiseFunctor>
355 for (
int interactionOffset = 0; interactionOffset < haloParticleBuffers.size(); ++interactionOffset) {
357 for (
size_t i = 0; i < particleBuffers.size(); ++i) {
358 auto &particleBuffer = particleBuffers[i];
359 auto &haloBuffer = haloParticleBuffers[(i + interactionOffset) % haloParticleBuffers.size()];
361 for (
auto &p1 : particleBuffer) {
362 for (
auto &p2 : haloBuffer) {
377 template <
class PairwiseFunctor>
383 for (
int interactionOffset = 0; interactionOffset < haloParticleBuffers.size(); ++interactionOffset) {
385 for (
size_t i = 0; i < particleBuffers.size(); ++i) {
386 auto &particleBufferSoA = particleBuffers[i]._particleSoABuffer;
387 auto &haloBufferSoA =
388 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
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
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