44template <
typename Particle_T>
54 LogicHandler(std::unordered_map<InteractionTypeOption::Value, std::unique_ptr<AutoTuner>> &autotuners,
55 const LogicHandlerInfo &logicHandlerInfo,
unsigned int rebuildFrequency,
const std::string &outputSuffix)
56 : _autoTunerRefs(autotuners),
57 _logicHandlerInfo(logicHandlerInfo),
58 _neighborListRebuildFrequency{rebuildFrequency},
61 _verletClusterSize(logicHandlerInfo.verletClusterSize),
62 _sortingThreshold(logicHandlerInfo.sortingThreshold),
63 _iterationLogger(outputSuffix, std::any_of(autotuners.
begin(), autotuners.end(),
64 [](const auto &tuner) {
return tuner.second->canMeasureEnergy(); })),
65 _flopLogger(outputSuffix),
66 _liveInfoLogger(outputSuffix),
68 using namespace autopas::utils::ArrayMath::literals;
70 for (
const auto &[interactionType, tuner] : autotuners) {
71 _interactionTypes.insert(interactionType);
73 const auto configuration = tuner->getCurrentConfig();
78 configuration.cellSizeFactor,
82 configuration.loadEstimator};
89 const auto interactionLength = logicHandlerInfo.cutoff + logicHandlerInfo.verletSkin;
90 const auto interactionLengthInv = 1. / interactionLength;
91 const auto boxLengthWithHalo = logicHandlerInfo.boxMax - logicHandlerInfo.boxMin + (2 * interactionLength);
92 initSpacialLocks(boxLengthWithHalo, interactionLengthInv);
93 for (
auto &lockPtr : _bufferLocks) {
94 lockPtr = std::make_unique<std::mutex>();
110 const auto &boxMin = _currentContainer->getBoxMin();
111 const auto &boxMax = _currentContainer->getBoxMax();
112 std::vector<Particle_T> leavingBufferParticles{};
113 for (
auto &cell : _particleBuffer) {
114 auto &buffer = cell._particles;
115 if (insertOwnedParticlesToContainer) {
117 for (
auto &p : buffer) {
123 _currentContainer->addParticle(p);
125 leavingBufferParticles.push_back(p);
130 for (
auto iter = buffer.begin(); iter < buffer.end();) {
133 auto fastRemoveP = [&]() {
135 std::swap(p, buffer.back());
147 if (not buffer.empty() and
utils::notInBox(p.getR(), boxMin, boxMax)) {
148 leavingBufferParticles.push_back(p);
156 return leavingBufferParticles;
163#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
168 if (_functorCalls > 0) {
170 for (
const auto &[interactionType, autoTuner] : _autoTunerRefs) {
173 if (autoTuner->inLastTuningIteration()) {
174 _iterationAtEndOfLastTuningPhase = _iteration;
176 autoTuner->bumpIterationCounters(needsToWait);
180 if (not _neighborListsAreValid.load(std::memory_order_relaxed)) {
181 _stepsSinceLastListRebuild = 0;
183 ++_stepsSinceLastListRebuild;
184 _currentContainer->setStepsSinceLastRebuild(_stepsSinceLastListRebuild);
191 AutoPasLog(TRACE,
"Initiating container update.");
192 auto leavingParticles = _currentContainer->updateContainer(not doDataStructureUpdate);
193 leavingParticles.insert(leavingParticles.end(), leavingBufferParticles.begin(), leavingBufferParticles.end());
196 _numParticlesOwned.fetch_sub(leavingParticles.size(), std::memory_order_relaxed);
198 std::for_each(_haloParticleBuffer.begin(), _haloParticleBuffer.end(), [](
auto &buffer) { buffer.clear(); });
199 _numParticlesHalo.store(0, std::memory_order_relaxed);
200 return leavingParticles;
209 std::vector<Particle_T>
resizeBox(
const std::array<double, 3> &boxMin,
const std::array<double, 3> &boxMax) {
210 using namespace autopas::utils::ArrayMath::literals;
211 const auto &oldMin = _currentContainer->getBoxMin();
212 const auto &oldMax = _currentContainer->getBoxMax();
215 if (oldMin == boxMin and oldMax == boxMax) {
220 for (
size_t i = 0; i < boxMin.size(); ++i) {
221 if (boxMin[i] >= boxMax[i]) {
223 "New box size in dimension {} is not positive!\nboxMin[{}] = {}\nboxMax[{}] = {}", i, i, boxMin[i], i,
229 const auto newLength = boxMax - boxMin;
230 const auto oldLength = oldMax - oldMin;
231 const auto relDiffLength = newLength / oldLength;
232 for (
size_t i = 0; i < newLength.size(); ++i) {
234 if (relDiffLength[i] > 1.3 or relDiffLength[i] < 0.7) {
236 "LogicHandler.resize(): Domain size changed drastically in dimension {}! Gathered AutoTuning "
237 "information might not be applicable anymore!\n"
238 "Size old box : {}\n"
239 "Size new box : {}\n"
247 _currentContainerSelectorInfo.
boxMin = boxMin;
248 _currentContainerSelectorInfo.
boxMax = boxMax;
251 std::vector<Particle_T> particlesNowOutside;
252 for (
auto pIter = _currentContainer->begin(); pIter.isValid(); ++pIter) {
254 if (not pIter->isOwned()) {
256 "LogicHandler::resizeBox() encountered non owned particle. "
257 "When calling resizeBox() these should be already deleted. "
258 "This could be solved by calling updateContainer() before resizeBox().");
262 particlesNowOutside.push_back(*pIter);
270 _currentContainerSelectorInfo);
271 setCurrentContainer(std::move(newContainer));
273 const auto boxLength = boxMax - boxMin;
274 const auto interactionLengthInv = 1. / _currentContainer->getInteractionLength();
275 initSpacialLocks(boxLength, interactionLengthInv);
278 _neighborListsAreValid.store(
false, std::memory_order_relaxed);
280 return particlesNowOutside;
291 numParticles, _currentContainer->getBoxMin(), _currentContainer->getBoxMax(),
292 _currentContainer->getInteractionLength());
293 reserve(numParticles, numParticlesHaloEstimate);
302 void reserve(
size_t numParticles,
size_t numHaloParticles) {
303 const auto numHaloParticlesPerBuffer = numHaloParticles / _haloParticleBuffer.size();
304 for (
auto &buffer : _haloParticleBuffer) {
305 buffer.reserve(numHaloParticlesPerBuffer);
308 for (
auto &buffer : _particleBuffer) {
309 buffer.reserve(numHaloParticlesPerBuffer);
312 _currentContainer->reserve(numParticles, numHaloParticles);
320 const auto &boxMin = _currentContainer->getBoxMin();
321 const auto &boxMax = _currentContainer->getBoxMax();
324 "LogicHandler: Trying to add a particle that is not in the bounding box.\n"
328 boxMin, boxMax, p.toString());
330 Particle_T particleCopy = p;
332 if (not _neighborListsAreValid.load(std::memory_order_relaxed)) {
334 _currentContainer->template addParticle<false>(particleCopy);
339 _numParticlesOwned.fetch_add(1, std::memory_order_relaxed);
346 const auto &boxMin = _currentContainer->getBoxMin();
347 const auto &boxMax = _currentContainer->getBoxMax();
348 Particle_T haloParticleCopy = haloParticle;
349 if (
utils::inBox(haloParticleCopy.getR(), boxMin, boxMax)) {
351 "LogicHandler: Trying to add a halo particle that is not outside the box of the container.\n"
358 if (not _neighborListsAreValid.load(std::memory_order_relaxed)) {
363 bool updated = _currentContainer->updateHaloParticle(haloParticleCopy);
369 _numParticlesHalo.fetch_add(1, std::memory_order_relaxed);
376 _neighborListsAreValid.store(
false, std::memory_order_relaxed);
377 _currentContainer->deleteAllParticles();
378 std::for_each(_particleBuffer.begin(), _particleBuffer.end(), [](
auto &buffer) { buffer.clear(); });
379 std::for_each(_haloParticleBuffer.begin(), _haloParticleBuffer.end(), [](
auto &buffer) { buffer.clear(); });
381 _numParticlesOwned.store(0, std::memory_order_relaxed);
382 _numParticlesHalo.store(0, std::memory_order_relaxed);
393 auto &bufferCollection = particle.isOwned() ? _particleBuffer : _haloParticleBuffer;
394 for (
auto &cell : bufferCollection) {
395 auto &buffer = cell._particles;
397 if (not buffer.empty() and &(buffer.front()) <= &particle and &particle <= &(buffer.back())) {
398 const bool isRearParticle = &particle == &buffer.back();
400 particle = buffer.back();
402 return {
true, not isRearParticle};
405 return {
false,
true};
414 if (particle.isOwned()) {
415 _numParticlesOwned.fetch_sub(1, std::memory_order_relaxed);
417 _numParticlesHalo.fetch_sub(1, std::memory_order_relaxed);
441 template <
class Functor>
450 template <
class Iterator>
452 typename Iterator::ParticleVecType additionalVectors;
453 if (not(behavior & IteratorBehavior::containerOnly)) {
454 additionalVectors.reserve(
static_cast<bool>(behavior & IteratorBehavior::owned) * _particleBuffer.size() +
455 static_cast<bool>(behavior & IteratorBehavior::halo) * _haloParticleBuffer.size());
456 if (behavior & IteratorBehavior::owned) {
457 for (
auto &buffer : _particleBuffer) {
461 if (not buffer.isEmpty()) {
462 additionalVectors.push_back(&(buffer._particles));
466 if (behavior & IteratorBehavior::halo) {
467 for (
auto &buffer : _haloParticleBuffer) {
468 if (not buffer.isEmpty()) {
469 additionalVectors.push_back(&(buffer._particles));
474 return additionalVectors;
481 auto additionalVectors = gatherAdditionalVectors<ContainerIterator<Particle_T, true, false>>(behavior);
482 return _currentContainer->begin(behavior, &additionalVectors);
489 auto additionalVectors =
492 return _currentContainer->begin(behavior, &additionalVectors);
499 const std::array<double, 3> &higherCorner,
500 IteratorBehavior behavior) {
502 for (
size_t d = 0; d < 3; ++d) {
503 if (lowerCorner[d] > higherCorner[d]) {
505 "Requesting region Iterator where the upper corner is lower than the lower corner!\n"
508 lowerCorner, higherCorner);
512 auto additionalVectors = gatherAdditionalVectors<ContainerIterator<Particle_T, true, true>>(behavior);
513 return _currentContainer->getRegionIterator(lowerCorner, higherCorner, behavior, &additionalVectors);
520 const std::array<double, 3> &higherCorner,
521 IteratorBehavior behavior)
const {
523 for (
size_t d = 0; d < 3; ++d) {
524 if (lowerCorner[d] > higherCorner[d]) {
526 "Requesting region Iterator where the upper corner is lower than the lower corner!\n"
529 lowerCorner, higherCorner);
533 auto additionalVectors =
535 return std::as_const(_currentContainer)->getRegionIterator(lowerCorner, higherCorner, behavior, &additionalVectors);
558 return std::any_of(std::begin(_autoTunerRefs), std::end(_autoTunerRefs), [&](
const auto &entry) {
559 return not(entry.first == interactionType) and entry.second->inTuningPhase();
575 template <
class Functor>
599 std::tuple<const std::vector<FullParticleCell<Particle_T>> &,
const std::vector<FullParticleCell<Particle_T>> &>
614#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
615 const auto numRebuilds = considerOnlyLastNonTuningPhase ? _numRebuildsInNonTuningPhase : _numRebuilds;
617 const auto iterationCount =
618 considerOnlyLastNonTuningPhase ? _iteration - _iterationAtEndOfLastTuningPhase : _iteration + 1;
619 if (numRebuilds == 0) {
620 return static_cast<double>(_neighborListRebuildFrequency);
622 return static_cast<double>(iterationCount) / numRebuilds;
625 return static_cast<double>(_neighborListRebuildFrequency);
670 void initSpacialLocks(
const std::array<double, 3> &boxLength,
double interactionLengthInv) {
671 using namespace autopas::utils::ArrayMath::literals;
681 constexpr size_t maxNumSpacialLocks{1000000};
684 const std::array<size_t, 3> locksPerDim = [&]() {
687 const std::array<size_t, 3> locksPerDimNaive =
688 static_cast_copy_array<size_t>(ceil(boxLength * interactionLengthInv));
689 const auto totalLocksNaive =
690 std::accumulate(locksPerDimNaive.begin(), locksPerDimNaive.end(), 1ul, std::multiplies<>());
692 if (totalLocksNaive <= maxNumSpacialLocks) {
693 return locksPerDimNaive;
697 const std::array<double, 3> boxSideProportions = {
699 boxLength[0] / boxLength[1],
700 boxLength[0] / boxLength[2],
703 const auto prodProportions =
704 std::accumulate(boxSideProportions.begin(), boxSideProportions.end(), 1., std::multiplies<>());
706 const auto locksInFirstDimFloat = std::floor(std::cbrt(maxNumSpacialLocks * prodProportions));
708 const std::array<size_t, 3> locksPerDimLimited = {
709 static_cast<size_t>(locksInFirstDimFloat),
710 static_cast<size_t>(locksInFirstDimFloat / boxSideProportions[1]),
711 static_cast<size_t>(locksInFirstDimFloat / boxSideProportions[2]),
713 return locksPerDimLimited;
716 _spacialLocks.resize(locksPerDim[0]);
717 for (
auto &lockVecVec : _spacialLocks) {
718 lockVecVec.resize(locksPerDim[1]);
719 for (
auto &lockVec : lockVecVec) {
720 lockVec.resize(locksPerDim[2]);
721 for (
auto &lockPtr : lockVec) {
723 lockPtr = std::make_unique<std::mutex>();
737 template <
class Functor>
738 std::tuple<Configuration, std::unique_ptr<TraversalInterface>,
bool> selectConfiguration(
739 Functor &functor,
const InteractionTypeOption &interactionType);
761 template <
class Functor>
774 template <
class Functor>
775 void computeRemainderInteractions(
Functor &functor,
bool newton3,
bool useSoA);
798 template <
bool newton3,
class ContainerType,
class PairwiseFunctor>
799 void computeRemainderInteractions2B(
PairwiseFunctor *f, ContainerType &container,
816 template <
bool newton3,
class ContainerType,
class PairwiseFunctor>
817 void remainderHelperBufferContainerAoS(
PairwiseFunctor *f, ContainerType &container,
830 template <
bool newton3,
class PairwiseFunctor>
841 template <
bool newton3,
class PairwiseFunctor>
851 template <
bool newton3,
class PairwiseFunctor>
867 template <
class PairwiseFunctor>
878 template <
class PairwiseFunctor>
890 template <
class PairwiseFunctor>
915 template <
bool newton3,
class ContainerType,
class TriwiseFunctor>
916 void computeRemainderInteractions3B(
TriwiseFunctor *f, ContainerType &container,
930 size_t collectBufferParticles(std::vector<Particle_T *> &bufferParticles,
943 template <
class TriwiseFunctor>
944 void remainderHelper3bBufferBufferBufferAoS(
const std::vector<Particle_T *> &bufferParticles,
958 template <
class ContainerType,
class TriwiseFunctor>
959 void remainderHelper3bBufferBufferContainerAoS(
const std::vector<Particle_T *> &bufferParticles,
960 size_t numOwnedBufferParticles, ContainerType &container,
975 template <
bool newton3,
class ContainerType,
class TriwiseFunctor>
976 void remainderHelper3bBufferContainerContainerAoS(
const std::vector<Particle_T *> &bufferParticles,
977 size_t numOwnedBufferParticles, ContainerType &container,
985 void checkMinimalSize()
const;
991 unsigned int _neighborListRebuildFrequency;
996 unsigned int _verletClusterSize;
1001 size_t _numRebuilds{0};
1007 size_t _numRebuildsInNonTuningPhase{0};
1012 size_t _sortingThreshold;
1017 std::unordered_map<InteractionTypeOption::Value, std::unique_ptr<AutoTuner>> &_autoTunerRefs;
1022 std::unique_ptr<ParticleContainerInterface<Particle_T>> _currentContainer;
1032 std::set<InteractionTypeOption> _interactionTypes{};
1037 std::atomic<bool> _neighborListsAreValid{
false};
1042 unsigned int _stepsSinceLastListRebuild{0};
1047 unsigned int _functorCalls{0};
1052 unsigned int _iteration{0};
1057 unsigned int _iterationAtEndOfLastTuningPhase{0};
1062 std::atomic<size_t> _numParticlesOwned{0ul};
1067 std::atomic<size_t> _numParticlesHalo{0ul};
1072 std::vector<FullParticleCell<Particle_T>> _particleBuffer;
1077 std::vector<FullParticleCell<Particle_T>> _haloParticleBuffer;
1084 std::vector<std::vector<std::vector<std::unique_ptr<std::mutex>>>> _spacialLocks;
1089 std::vector<std::unique_ptr<std::mutex>> _bufferLocks;
1100 bool _neighborListInvalidDoDynamicRebuild{
false};
1105 void updateRebuildPositions();
1118template <
typename Particle_T>
1120#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
1125 for (
auto iter = this->begin(IteratorBehavior::owned | IteratorBehavior::containerOnly); iter.isValid(); ++iter) {
1126 iter->resetRAtRebuild();
1131template <
typename Particle_T>
1134 for (
unsigned int dim = 0; dim < 3; ++dim) {
1135 if (_currentContainer->getBoxMax()[dim] - _currentContainer->getBoxMin()[dim] <
1136 _currentContainer->getInteractionLength()) {
1138 "Box (boxMin[{}]={} and boxMax[{}]={}) is too small.\nHas to be at least cutoff({}) + skin({}) = {}.", dim,
1139 _currentContainer->getBoxMin()[dim], dim, _currentContainer->getBoxMax()[dim], _currentContainer->getCutoff(),
1140 _currentContainer->getVerletSkin(), _currentContainer->getCutoff() + _currentContainer->getVerletSkin());
1145template <
typename Particle_T>
1147 return _neighborListInvalidDoDynamicRebuild;
1150template <
typename Particle_T>
1153 const auto needRebuild = [&](
const InteractionTypeOption &interactionOption) {
1154 return _interactionTypes.count(interactionOption) != 0 and
1155 _autoTunerRefs[interactionOption]->willRebuildNeighborLists();
1158 if (_stepsSinceLastListRebuild >= _neighborListRebuildFrequency
1159#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
1160 or getNeighborListsInvalidDoDynamicRebuild()
1162 or needRebuild(InteractionTypeOption::pairwise) or needRebuild(InteractionTypeOption::triwise)) {
1163 _neighborListsAreValid.store(
false, std::memory_order_relaxed);
1166 return _neighborListsAreValid.load(std::memory_order_relaxed);
1169template <
typename Particle_T>
1171#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
1172 const auto skin = getContainer().getVerletSkin();
1174 const auto halfSkinSquare = skin * skin * 0.25;
1178 AUTOPAS_OPENMP(parallel reduction(or : _neighborListInvalidDoDynamicRebuild))
1179 for (
auto iter = this->begin(IteratorBehavior::owned | IteratorBehavior::containerOnly); iter.isValid(); ++iter) {
1180 const auto distance = iter->calculateDisplacementSinceRebuild();
1183 _neighborListInvalidDoDynamicRebuild |= distanceSquare >= halfSkinSquare;
1188template <
typename Particle_T>
1190 _neighborListInvalidDoDynamicRebuild =
false;
1193template <
typename Particle_T>
1197 auto exchangeBuffer = [](
const auto &newBuffers,
auto &oldBuffers,
auto &particleCounter) {
1199 if (oldBuffers.size() < newBuffers.size()) {
1201 "The number of new buffers ({}) is larger than number of existing buffers ({})!", newBuffers.size(),
1206 const auto numParticlesInOldBuffers =
1207 std::transform_reduce(oldBuffers.begin(), std::next(oldBuffers.begin(), newBuffers.size()), 0, std::plus<>(),
1208 [](
const auto &cell) { return cell.size(); });
1209 particleCounter.fetch_sub(numParticlesInOldBuffers, std::memory_order_relaxed);
1212 size_t numParticlesInNewBuffers = 0;
1213 for (
size_t i = 0; i < newBuffers.size(); ++i) {
1214 oldBuffers[i].clear();
1215 for (
const auto &p : newBuffers[i]) {
1216 ++numParticlesInNewBuffers;
1217 oldBuffers[i].addParticle(p);
1221 particleCounter.fetch_add(numParticlesInNewBuffers, std::memory_order_relaxed);
1224 exchangeBuffer(particleBuffers, _particleBuffer, _numParticlesOwned);
1225 exchangeBuffer(haloParticleBuffers, _haloParticleBuffer, _numParticlesHalo);
1228template <
typename Particle_T>
1229std::tuple<const std::vector<FullParticleCell<Particle_T>> &,
const std::vector<FullParticleCell<Particle_T>> &>
1231 return {_particleBuffer, _haloParticleBuffer};
1234template <
typename Particle_T>
1235template <
class Functor>
1238 constexpr auto interactionType = [] {
1240 return InteractionTypeOption::pairwise;
1242 return InteractionTypeOption::triwise;
1245 "LogicHandler::computeInteractions(): Functor is not valid. Only pairwise and triwise functors are "
1247 "Please use a functor derived from "
1248 "PairwiseFunctor or TriwiseFunctor.");
1252 auto &autoTuner = *_autoTunerRefs[interactionType];
1253#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
1254 if (autoTuner.inFirstTuningIteration()) {
1255 autoTuner.setRebuildFrequency(getMeanRebuildFrequency(
true));
1256 _numRebuildsInNonTuningPhase = 0;
1264 const bool energyMeasurementsPossible = autoTuner.resetEnergy();
1270 if (not _neighborListsAreValid.load(std::memory_order_relaxed)) {
1271 timerRebuild.
start();
1272#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
1273 this->updateRebuildPositions();
1275 _currentContainer->rebuildNeighborLists(&traversal);
1276#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
1277 this->resetNeighborListsInvalidDoDynamicRebuild();
1279 if (not autoTuner.inTuningPhase()) {
1280 _numRebuildsInNonTuningPhase++;
1283 timerRebuild.
stop();
1284 _neighborListsAreValid.store(
true, std::memory_order_relaxed);
1287 timerComputeInteractions.
start();
1288 _currentContainer->computeInteractions(&traversal);
1289 timerComputeInteractions.
stop();
1291 timerComputeRemainder.
start();
1292 const bool newton3 = autoTuner.getCurrentConfig().newton3;
1293 const auto dataLayout = autoTuner.getCurrentConfig().dataLayout;
1294 computeRemainderInteractions(functor, newton3, dataLayout);
1295 timerComputeRemainder.
stop();
1299 const auto [energyWatts, energyJoules, energyDeltaT, energyTotal] = autoTuner.sampleEnergy();
1302 constexpr auto nanD = std::numeric_limits<double>::quiet_NaN();
1303 constexpr auto nanL = std::numeric_limits<long>::quiet_NaN();
1308 energyMeasurementsPossible,
1309 energyMeasurementsPossible ? energyWatts : nanD,
1310 energyMeasurementsPossible ? energyJoules : nanD,
1311 energyMeasurementsPossible ? energyDeltaT : nanD,
1312 energyMeasurementsPossible ? energyTotal : nanL};
1315template <
typename Particle_T>
1316template <
class Functor>
1321 computeRemainderInteractions2B<true>(&functor, actualContainerType, _particleBuffer, _haloParticleBuffer,
1324 computeRemainderInteractions2B<false>(&functor, actualContainerType, _particleBuffer, _haloParticleBuffer,
1329 computeRemainderInteractions3B<true>(&functor, actualContainerType, _particleBuffer, _haloParticleBuffer);
1331 computeRemainderInteractions3B<false>(&functor, actualContainerType, _particleBuffer, _haloParticleBuffer);
1337template <
class Particle_T>
1338template <
bool newton3,
class ContainerType,
class PairwiseFunctor>
1343 if (_bufferLocks.size() < particleBuffers.size()) {
1345 _bufferLocks.size(), particleBuffers.size());
1351 auto cellToVec = [](
auto &cell) -> std::vector<Particle_T> & {
return cell._particles; };
1359#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
1365 timerBufferContainer.
start();
1372 remainderHelperBufferContainerAoS<newton3>(f, container, particleBuffers, haloParticleBuffers);
1374#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
1375 timerBufferContainer.
stop();
1376 timerBufferSoAConversion.
start();
1380 for (
auto &buffer : particleBuffers) {
1381 f->
SoALoader(buffer, buffer._particleSoABuffer, 0,
false);
1383 for (
auto &buffer : haloParticleBuffers) {
1384 f->
SoALoader(buffer, buffer._particleSoABuffer, 0,
false);
1387#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
1388 timerBufferSoAConversion.
stop();
1389 timerPBufferPBuffer.
start();
1393 remainderHelperBufferBuffer<newton3>(f, particleBuffers, useSoA);
1395#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
1396 timerPBufferPBuffer.
stop();
1397 timerPBufferHBuffer.
start();
1401 remainderHelperBufferHaloBuffer(f, particleBuffers, haloParticleBuffers, useSoA);
1403#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
1404 timerPBufferHBuffer.
stop();
1409 for (
auto &buffer : particleBuffers) {
1422template <
class Particle_T>
1423template <
bool newton3,
class ContainerType,
class PairwiseFunctor>
1428 using namespace autopas::utils::ArrayMath::literals;
1431 const auto cutoff = container.getCutoff();
1432 const auto interactionLength = container.getInteractionLength();
1433 const auto interactionLengthInv = 1. / interactionLength;
1434 const auto haloBoxMin = container.getBoxMin() - interactionLength;
1435 const auto totalBoxLengthInv = 1. / (container.getBoxMax() + interactionLength - haloBoxMin);
1436 const std::array<size_t, 3> spacialLocksPerDim{
1437 _spacialLocks.size(),
1438 _spacialLocks[0].size(),
1439 _spacialLocks[0][0].size(),
1444 const auto getSpacialLock = [&](
const std::array<double, 3> &pos) -> std::mutex & {
1445 const auto posDistFromLowerCorner = pos - haloBoxMin;
1446 const auto relativePos = posDistFromLowerCorner * totalBoxLengthInv;
1448 const auto lockCoords =
1449 static_cast_copy_array<size_t>(static_cast_copy_array<double>(spacialLocksPerDim) * relativePos);
1450 return *_spacialLocks[lockCoords[0]][lockCoords[1]][lockCoords[2]];
1455 for (
int bufferId = 0; bufferId < particleBuffers.size(); ++bufferId) {
1456 auto &particleBuffer = particleBuffers[bufferId];
1457 auto &haloParticleBuffer = haloParticleBuffers[bufferId];
1459 for (
auto &&p1 : particleBuffer) {
1460 const auto pos = p1.getR();
1461 const auto min = pos - cutoff;
1462 const auto max = pos + cutoff;
1463 container.forEachInRegion(
1465 if constexpr (newton3) {
1466 const std::lock_guard<std::mutex> lock(getSpacialLock(p2.getR()));
1471 if (not p2.isHalo()) {
1472 const std::lock_guard<std::mutex> lock(getSpacialLock(p2.getR()));
1477 min,
max, IteratorBehavior::ownedOrHalo);
1481 for (
auto &&p1halo : haloParticleBuffer) {
1482 const auto pos = p1halo.getR();
1483 const auto min = pos - cutoff;
1484 const auto max = pos + cutoff;
1485 container.forEachInRegion(
1490 const std::lock_guard<std::mutex> lock(getSpacialLock(p2.getR()));
1493 min,
max, IteratorBehavior::owned);
1498template <
class Particle_T>
1499template <
bool newton3,
class PairwiseFunctor>
1504 remainderHelperBufferBufferSoA<newton3>(f, particleBuffers);
1506 remainderHelperBufferBufferAoS<newton3>(f, particleBuffers);
1510template <
class Particle_T>
1511template <
bool newton3,
class PairwiseFunctor>
1520 for (
size_t bufferIdxI = 0; bufferIdxI < particleBuffers.size(); ++bufferIdxI) {
1521 for (
size_t bufferIdxJOffset = 0; bufferIdxJOffset < particleBuffers.size(); ++bufferIdxJOffset) {
1523 const auto bufferIdxJ = (bufferIdxI + bufferIdxJOffset) % particleBuffers.size();
1526 if (bufferIdxI == bufferIdxJ) {
1529 const bool useNewton3 = newton3;
1530 auto &bufferRef = particleBuffers[bufferIdxI];
1531 const auto bufferSize = bufferRef.size();
1532 for (
auto i = 0; i < bufferSize; ++i) {
1533 auto &p1 = bufferRef[i];
1535 for (
auto j = useNewton3 ? i + 1 : 0; j < bufferSize; ++j) {
1539 auto &p2 = bufferRef[j];
1545 for (
auto &p1 : particleBuffers[bufferIdxI]) {
1546 for (
auto &p2 : particleBuffers[bufferIdxJ]) {
1555template <
class Particle_T>
1556template <
bool newton3,
class PairwiseFunctor>
1561 for (
size_t i = 0; i < particleBuffers.size(); ++i) {
1562 for (
size_t jj = 0; jj < particleBuffers.size(); ++jj) {
1563 auto *particleBufferSoAA = &particleBuffers[i]._particleSoABuffer;
1565 const auto j = (i + jj) % particleBuffers.size();
1572 auto *particleBufferSoAB = &particleBuffers[j]._particleSoABuffer;
1573 f->
SoAFunctorPair(*particleBufferSoAA, *particleBufferSoAB,
false);
1579template <
class Particle_T>
1580template <
class PairwiseFunctor>
1585 remainderHelperBufferHaloBufferSoA<PairwiseFunctor>(f, particleBuffers, haloParticleBuffers);
1587 remainderHelperBufferHaloBufferAoS<PairwiseFunctor>(f, particleBuffers, haloParticleBuffers);
1591template <
class Particle_T>
1592template <
class PairwiseFunctor>
1598 for (
int interactionOffset = 0; interactionOffset < haloParticleBuffers.size(); ++interactionOffset) {
1600 for (
size_t i = 0; i < particleBuffers.size(); ++i) {
1601 auto &particleBuffer = particleBuffers[i];
1602 auto &haloBuffer = haloParticleBuffers[(i + interactionOffset) % haloParticleBuffers.size()];
1604 for (
auto &p1 : particleBuffer) {
1605 for (
auto &p2 : haloBuffer) {
1613template <
class Particle_T>
1614template <
class PairwiseFunctor>
1620 for (
int interactionOffset = 0; interactionOffset < haloParticleBuffers.size(); ++interactionOffset) {
1622 for (
size_t i = 0; i < particleBuffers.size(); ++i) {
1623 auto &particleBufferSoA = particleBuffers[i]._particleSoABuffer;
1624 auto &haloBufferSoA =
1625 haloParticleBuffers[(i + interactionOffset) % haloParticleBuffers.size()]._particleSoABuffer;
1631template <
class Particle_T>
1632template <
bool newton3,
class ContainerType,
class TriwiseFunctor>
1637 std::vector<Particle_T *> bufferParticles;
1638 const auto numOwnedBufferParticles = collectBufferParticles(bufferParticles, particleBuffers, haloParticleBuffers);
1643#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
1647 timerBufferBufferBuffer.
start();
1651 remainderHelper3bBufferBufferBufferAoS(bufferParticles, numOwnedBufferParticles, f);
1653#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
1654 timerBufferBufferBuffer.
stop();
1655 timerBufferBufferContainer.
start();
1659 remainderHelper3bBufferBufferContainerAoS(bufferParticles, numOwnedBufferParticles, container, f);
1661#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
1662 timerBufferBufferContainer.
stop();
1663 timerBufferContainerContainer.
start();
1667 remainderHelper3bBufferContainerContainerAoS<newton3>(bufferParticles, numOwnedBufferParticles, container, f);
1669#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
1670 timerBufferContainerContainer.
stop();
1674 AutoPasLog(TRACE,
"Timer Buffer <-> Buffer <-> Container : {}", timerBufferBufferContainer.
getTotalTime());
1675 AutoPasLog(TRACE,
"Timer Buffer <-> Container <-> Container : {}", timerBufferContainerContainer.
getTotalTime());
1678template <
class Particle_T>
1683 auto cellToVec = [](
auto &cell) -> std::vector<Particle_T> & {
return cell._particles; };
1685 const size_t numOwnedBufferParticles =
1686 std::transform_reduce(particleBuffers.begin(), particleBuffers.end(), 0, std::plus<>(),
1687 [&](
auto &vec) { return cellToVec(vec).size(); });
1689 const size_t numHaloBufferParticles =
1690 std::transform_reduce(haloParticleBuffers.begin(), haloParticleBuffers.end(), 0, std::plus<>(),
1691 [&](
auto &vec) { return cellToVec(vec).size(); });
1693 bufferParticles.reserve(numOwnedBufferParticles + numHaloBufferParticles);
1696 for (
auto &buffer : particleBuffers) {
1697 for (
auto &particle : buffer._particles) {
1698 bufferParticles.push_back(&particle);
1703 for (
auto &buffer : haloParticleBuffers) {
1704 for (
auto &particle : buffer._particles) {
1705 bufferParticles.push_back(&particle);
1709 return numOwnedBufferParticles;
1712template <
class Particle_T>
1713template <
class TriwiseFunctor>
1715 const size_t numOwnedBufferParticles,
1718 for (
auto i = 0; i < numOwnedBufferParticles; ++i) {
1719 Particle_T &p1 = *bufferParticles[i];
1721 for (
auto j = 0; j < bufferParticles.size(); ++j) {
1722 if (i == j)
continue;
1723 Particle_T &p2 = *bufferParticles[j];
1725 for (
auto k = j + 1; k < bufferParticles.size(); ++k) {
1726 if (k == i)
continue;
1727 Particle_T &p3 = *bufferParticles[k];
1735template <
class Particle_T>
1736template <
class ContainerType,
class TriwiseFunctor>
1738 const std::vector<Particle_T *> &bufferParticles,
const size_t numOwnedBufferParticles, ContainerType &container,
1741 using namespace autopas::utils::ArrayMath::literals;
1743 const auto haloBoxMin = container.getBoxMin() - container.getInteractionLength();
1744 const auto interactionLengthInv = 1. / container.getInteractionLength();
1745 const double cutoff = container.getCutoff();
1748 for (
auto i = 0; i < bufferParticles.size(); ++i) {
1749 Particle_T &p1 = *bufferParticles[i];
1750 const auto pos = p1.getR();
1751 const auto min = pos - cutoff;
1752 const auto max = pos + cutoff;
1754 for (
auto j = 0; j < bufferParticles.size(); ++j) {
1755 if (j == i)
continue;
1756 Particle_T &p2 = *bufferParticles[j];
1758 container.forEachInRegion(
1760 const auto lockCoords = static_cast_copy_array<size_t>((p3.getR() - haloBoxMin) * interactionLengthInv);
1761 if (i < numOwnedBufferParticles) f->
AoSFunctor(p1, p2, p3,
false);
1762 if (!p3.isHalo() && i < j) {
1763 const std::lock_guard<std::mutex> lock(*_spacialLocks[lockCoords[0]][lockCoords[1]][lockCoords[2]]);
1767 min,
max, IteratorBehavior::ownedOrHalo);
1772template <
class Particle_T>
1773template <
bool newton3,
class ContainerType,
class TriwiseFunctor>
1775 const std::vector<Particle_T *> &bufferParticles,
const size_t numOwnedBufferParticles, ContainerType &container,
1779 using namespace autopas::utils::ArrayMath::literals;
1781 const double cutoff = container.getCutoff();
1783 for (
auto i = 0; i < bufferParticles.size(); ++i) {
1784 Particle_T &p1 = *bufferParticles[i];
1785 const auto pos = p1.getR();
1786 const auto boxmin = pos - cutoff;
1787 const auto boxmax = pos + cutoff;
1789 auto p2Iter = container.getRegionIterator(
1790 boxmin, boxmax, IteratorBehavior::ownedOrHalo | IteratorBehavior::forceSequential,
nullptr);
1791 for (; p2Iter.isValid(); ++p2Iter) {
1792 Particle_T &p2 = *p2Iter;
1794 auto p3Iter = p2Iter;
1797 for (; p3Iter.isValid(); ++p3Iter) {
1798 Particle_T &p3 = *p3Iter;
1800 if constexpr (newton3) {
1803 if (i < numOwnedBufferParticles) {
1818template <
typename Particle_T>
1819template <
class Functor>
1821 Functor &functor,
const InteractionTypeOption &interactionType) {
1822 auto &autoTuner = *_autoTunerRefs[interactionType];
1827#ifdef AUTOPAS_LOG_LIVEINFO
1828 auto particleIter = this->begin(IteratorBehavior::ownedOrHalo);
1829 info.gather(particleIter, _neighborListRebuildFrequency, getNumberOfParticlesOwned(), _logicHandlerInfo.boxMin,
1830 _logicHandlerInfo.boxMax, _logicHandlerInfo.cutoff, _logicHandlerInfo.verletSkin);
1831 _liveInfoLogger.logLiveInfo(info, _iteration);
1836 auto configuration = autoTuner.getCurrentConfig();
1837 auto [traversalPtr, _] = isConfigurationApplicable(configuration, functor);
1839 if (not traversalPtr) {
1842 "LogicHandler: Functor {} is not relevant for tuning but the given configuration is not applicable!",
1845 return {configuration, std::move(traversalPtr),
false};
1848 if (autoTuner.needsLiveInfo()) {
1850 if (info.get().empty()) {
1851 auto particleIter = this->begin(IteratorBehavior::ownedOrHalo);
1852 info.gather(particleIter, _neighborListRebuildFrequency, getNumberOfParticlesOwned(), _logicHandlerInfo.boxMin,
1853 _logicHandlerInfo.boxMax, _logicHandlerInfo.cutoff, _logicHandlerInfo.verletSkin);
1855 autoTuner.receiveLiveInfo(info);
1858 auto [configuration, stillTuning] = autoTuner.getNextConfig();
1863 auto [traversalPtr, rejectIndefinitely] = isConfigurationApplicable(configuration, functor);
1865 return {configuration, std::move(traversalPtr), stillTuning};
1868 std::tie(configuration, stillTuning) = autoTuner.rejectConfig(configuration, rejectIndefinitely);
1872template <
typename Particle_T>
1876 if (_currentContainer !=
nullptr and newContainer !=
nullptr) {
1878 const auto numParticlesTotal = _currentContainer->size();
1880 numParticlesTotal, _currentContainer->getBoxMin(), _currentContainer->getBoxMax(),
1881 _currentContainer->getInteractionLength());
1883 newContainer->reserve(numParticlesTotal, numParticlesHalo);
1884 for (
auto particleIter = _currentContainer->begin(IteratorBehavior::ownedOrHalo); particleIter.isValid();
1887 if (particleIter->isOwned()) {
1888 newContainer->addParticle(*particleIter);
1890 newContainer->addHaloParticle(*particleIter);
1895 _currentContainer = std::move(newContainer);
1898template <
typename Particle_T>
1899template <
class Functor>
1901 const InteractionTypeOption &interactionType) {
1902 if (not _interactionTypes.count(interactionType)) {
1904 "LogicHandler::computeInteractionsPipeline(): AutPas was not initialized for the Functor's interactions type: "
1910 tuningTimer.
start();
1911 const auto [configuration, traversalPtr, stillTuning] = selectConfiguration(*functor, interactionType);
1913 auto &autoTuner = *_autoTunerRefs[interactionType];
1914 autoTuner.logTuningResult(stillTuning, tuningTimer.
getTotalTime());
1917 const auto rebuildIteration = not _neighborListsAreValid.load(std::memory_order_relaxed);
1920 AutoPasLog(DEBUG,
"Iterating with configuration: {} tuning: {}", configuration.toString(), stillTuning);
1924 auto bufferSizeListing = [](
const auto &buffers) -> std::string {
1925 std::stringstream ss;
1927 for (
const auto &buffer : buffers) {
1928 ss << buffer.size() <<
", ";
1929 sum += buffer.size();
1931 ss <<
" Total: " << sum;
1934 AutoPasLog(TRACE,
"particleBuffer size : {}", bufferSizeListing(_particleBuffer));
1935 AutoPasLog(TRACE,
"haloParticleBuffer size : {}", bufferSizeListing(_haloParticleBuffer));
1936 AutoPasLog(DEBUG,
"Type of interaction : {}", interactionType.to_string());
1945 _iterationLogger.logIteration(configuration, _iteration, functor->
getName(), stillTuning, tuningTimer.
getTotalTime(),
1955 const auto measurement = [&]() {
1956 switch (autoTuner.getTuningMetric()) {
1966 autoTuner.addMeasurement(measurement, rebuildIteration);
1969 AutoPasLog(TRACE,
"Skipping adding of sample because functor is not marked relevant.");
1975template <
typename Particle_T>
1976template <
class Functor>
1980 const auto allContainerTraversals =
1982 if (allContainerTraversals.find(config.
traversal) == allContainerTraversals.end()) {
1983 AutoPasLog(WARN,
"Configuration rejected: Container {} does not support the traversal {}.", config.
container,
1985 return {
nullptr,
true};
1991 AutoPasLog(DEBUG,
"Configuration rejected: The functor doesn't support Newton 3 {}!", config.
newton3);
1992 return {
nullptr,
true};
1995 auto containerInfo =
1997 _currentContainer->getCutoff(), config.
cellSizeFactor, _currentContainer->getVerletSkin(),
1998 _verletClusterSize, _sortingThreshold, config.
loadEstimator);
2000 const auto traversalInfo = containerPtr->getTraversalSelectorInfo();
2003 auto traversalPtr = TraversalSelector::generateTraversalFromConfig<Particle_T, Functor>(
2004 config, functor, containerPtr->getTraversalSelectorInfo());
2006 if (traversalPtr and (_currentContainer->getContainerType() != containerPtr->getContainerType() or
2007 containerInfo != _currentContainerSelectorInfo)) {
2008 _currentContainerSelectorInfo = containerInfo;
2009 setCurrentContainer(std::move(containerPtr));
2012 return {std::move(traversalPtr),
false};
#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
Class containing multiple options that form an algorithm configuration for the pairwise iteration.
Definition: Configuration.h:24
LoadEstimatorOption loadEstimator
Load Estimator option.
Definition: Configuration.h:126
TraversalOption traversal
Traversal option.
Definition: Configuration.h:122
double cellSizeFactor
CellSizeFactor.
Definition: Configuration.h:138
InteractionTypeOption interactionType
Interaction type of the configuration.
Definition: Configuration.h:142
ContainerOption container
Container option.
Definition: Configuration.h:118
Newton3Option newton3
Newton 3 option.
Definition: Configuration.h:134
Public iterator class that iterates over a particle container and additional vectors (which are typic...
Definition: ContainerIterator.h:93
Info to generate a container.
Definition: ContainerSelectorInfo.h:17
std::array< double, 3 > boxMin
Lower corner of the container.
Definition: ContainerSelectorInfo.h:93
std::array< double, 3 > boxMax
Upper corner of the container.
Definition: ContainerSelectorInfo.h:98
static std::unique_ptr< ParticleContainerInterface< Particle_T > > generateContainer(ContainerOption containerChoice, const ContainerSelectorInfo &containerInfo)
Container factory method.
Definition: ContainerSelector.h:44
Helper to log FLOP count and HitRate for AutoPas::iteratePairwise() calls with the functors in the mo...
Definition: FLOPLogger.h:30
This class handles the storage of particles in their full form.
Definition: FullParticleCell.h:26
Functor base class.
Definition: Functor.h:40
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
virtual size_t getNumFLOPs() const
Get the number of FLOPs.
Definition: Functor.h:177
virtual bool allowsNewton3()=0
Specifies whether the functor is capable of Newton3-like functors.
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
virtual void initTraversal()
This function is called at the start of each traversal.
Definition: Functor.h:63
virtual bool allowsNonNewton3()=0
Specifies whether the functor is capable of non-Newton3-like functors.
virtual void endTraversal(bool newton3)
This function is called at the end of each traversal.
Definition: Functor.h:70
virtual bool isRelevantForTuning()=0
Specifies whether the functor should be considered for the auto-tuning process.
virtual std::string getName()=0
Returns name of functor.
virtual double getHitRate() const
Get the hit rate.
Definition: Functor.h:187
Helper to log performance data of AutoPas::computeInteractions() to a csv file for easier analysis.
Definition: IterationLogger.h:24
Helper to log the collected LiveInfo data during tuning to a csv file for easier analysis.
Definition: LiveInfoLogger.h:23
This class is able to gather and store important information for a tuning phase from a container and ...
Definition: LiveInfo.h:33
Class that wraps all arguments for the logic handler to provide a more stable API.
Definition: LogicHandlerInfo.h:16
double verletSkin
Length added to the cutoff for the Verlet lists' skin.
Definition: LogicHandlerInfo.h:33
std::array< double, 3 > boxMax
Upper corner of the container without halo.
Definition: LogicHandlerInfo.h:25
double cutoff
Cutoff radius to be used in this simulation.
Definition: LogicHandlerInfo.h:29
std::array< double, 3 > boxMin
Lower corner of the container without halo.
Definition: LogicHandlerInfo.h:21
The LogicHandler takes care of the containers s.t.
Definition: LogicHandler.h:45
void setParticleBuffers(const std::vector< FullParticleCell< Particle_T > > &particleBuffers, const std::vector< FullParticleCell< Particle_T > > &haloParticleBuffers)
Directly exchange the internal particle and halo buffers with the given vectors and update particle c...
Definition: LogicHandler.h:1194
void reserve(size_t numParticles, size_t numHaloParticles)
Reserves space in the particle buffers and the container.
Definition: LogicHandler.h:302
std::tuple< std::unique_ptr< TraversalInterface >, bool > isConfigurationApplicable(const Configuration &config, Functor &functor)
Checks if the given configuration can be used with the given functor and the current state of the sim...
Definition: LogicHandler.h:1977
ContainerIterator< Particle_T, true, false > begin(IteratorBehavior behavior)
Iterate over all particles by using for(auto iter = autoPas.begin(); iter.isValid(); ++iter)
Definition: LogicHandler.h:480
std::vector< Particle_T > updateContainer()
Updates the container.
Definition: LogicHandler.h:162
unsigned long getNumberOfParticlesOwned() const
Get the number of owned particles.
Definition: LogicHandler.h:542
bool computeInteractionsPipeline(Functor *functor, const InteractionTypeOption &interactionType)
This function covers the full pipeline of all mechanics happening during the computation of particle ...
Definition: LogicHandler.h:1900
std::tuple< const std::vector< FullParticleCell< Particle_T > > &, const std::vector< FullParticleCell< Particle_T > > & > getParticleBuffers() const
Getter for the particle buffers.
Definition: LogicHandler.h:1230
void addParticle(const Particle_T &p)
Adds a particle to the container.
Definition: LogicHandler.h:318
void decreaseParticleCounter(Particle_T &particle)
Decrease the correct internal particle counters.
Definition: LogicHandler.h:413
std::vector< Particle_T > collectLeavingParticlesFromBuffer(bool insertOwnedParticlesToContainer)
Collects leaving particles from buffer and potentially inserts owned particles to the container.
Definition: LogicHandler.h:109
LogicHandler(std::unordered_map< InteractionTypeOption::Value, std::unique_ptr< AutoTuner > > &autotuners, const LogicHandlerInfo &logicHandlerInfo, unsigned int rebuildFrequency, const std::string &outputSuffix)
Constructor of the LogicHandler.
Definition: LogicHandler.h:54
bool neighborListsAreValid()
Checks if in the next iteration the neighbor lists have to be rebuilt.
Definition: LogicHandler.h:1151
unsigned long getNumberOfParticlesHalo() const
Get the number of halo particles.
Definition: LogicHandler.h:548
std::tuple< bool, bool > deleteParticleFromBuffers(Particle_T &particle)
Takes a particle, checks if it is in any of the particle buffers, and deletes it from them if found.
Definition: LogicHandler.h:391
bool checkTuningStates(const InteractionTypeOption &interactionType)
Check if other autotuners for any other interaction types are still in a tuning phase.
Definition: LogicHandler.h:555
void checkNeighborListsInvalidDoDynamicRebuild()
Checks if any particle has moved more than skin/2.
Definition: LogicHandler.h:1170
Iterator::ParticleVecType gatherAdditionalVectors(IteratorBehavior behavior)
Create the additional vectors vector for a given iterator behavior.
Definition: LogicHandler.h:451
ParticleContainerInterface< Particle_T > & getContainer()
Returns a non-const reference to the currently selected particle container.
Definition: LogicHandler.h:102
void addHaloParticle(const Particle_T &haloParticle)
Adds a particle to the container that lies in the halo region of the container.
Definition: LogicHandler.h:345
ContainerIterator< Particle_T, false, true > getRegionIterator(const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior) const
Iterate over all particles in a specified region.
Definition: LogicHandler.h:519
void deleteAllParticles()
Deletes all particles.
Definition: LogicHandler.h:375
ContainerIterator< Particle_T, false, false > begin(IteratorBehavior behavior) const
Iterate over all particles by using for(auto iter = autoPas.begin(); iter.isValid(); ++iter)
Definition: LogicHandler.h:488
bool getNeighborListsInvalidDoDynamicRebuild()
getter function for _neighborListInvalidDoDynamicRebuild
Definition: LogicHandler.h:1146
void resetNeighborListsInvalidDoDynamicRebuild()
Checks if any particle has moved more than skin/2.
Definition: LogicHandler.h:1189
double getMeanRebuildFrequency(bool considerOnlyLastNonTuningPhase=false) const
Getter for the mean rebuild frequency.
Definition: LogicHandler.h:613
std::vector< Particle_T > resizeBox(const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax)
Pass values to the actual container.
Definition: LogicHandler.h:209
void reserve(size_t numParticles)
Estimates the number of halo particles via autopas::utils::NumParticlesEstimator::estimateNumHalosUni...
Definition: LogicHandler.h:289
ContainerIterator< Particle_T, true, true > getRegionIterator(const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior)
Iterate over all particles in a specified region.
Definition: LogicHandler.h:498
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
The ParticleContainerInterface class provides a basic interface for all Containers within AutoPas.
Definition: ParticleContainerInterface.h:37
This interface serves as a common parent class for all traversals.
Definition: TraversalInterface.h:18
TriwiseFunctor class.
Definition: TriwiseFunctor.h:28
virtual void AoSFunctor(Particle_T &i, Particle_T &j, Particle_T &k, bool newton3)
TriwiseFunctor for arrays of structures (AoS).
Definition: TriwiseFunctor.h:54
@ energy
Optimize for least energy usage.
Definition: TuningMetricOption.h:31
@ time
Optimize for shortest simulation time.
Definition: TuningMetricOption.h:27
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:63
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
void markParticleAsDeleted(Particle_T &p)
Marks a particle as deleted.
Definition: markParticleAsDeleted.h:23
constexpr T dot(const std::array< T, SIZE > &a, const std::array< T, SIZE > &b)
Generates the dot product of two arrays.
Definition: ArrayMath.h:233
constexpr std::array< T, SIZE > ceil(const std::array< T, SIZE > &a)
For each element in a, computes the smallest integer value not less than the element.
Definition: ArrayMath.h:316
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:200
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:81
void to_string(std::ostream &os, const Container &container, const std::string &delimiter, const std::array< std::string, 2 > &surround, Fun elemToString)
Generates a string representation of a container which fulfills the Container requirement (provide cb...
Definition: ArrayUtils.h:102
size_t estimateNumHalosUniform(size_t numParticles, const std::array< double, 3 > &boxMin, const std::array< double, 3 > &boxMax, double haloWidth)
Given a number of particles and the dimensions of a box, estimate the number of halo particles.
Definition: NumParticlesEstimator.cpp:9
decltype(isTriwiseFunctorImpl(std::declval< FunctorT >())) isTriwiseFunctor
Check whether a Functor Type is inheriting from TriwiseFunctor.
Definition: checkFunctorType.h:56
bool notInBox(const std::array< T, 3 > &position, const std::array< T, 3 > &low, const std::array< T, 3 > &high)
Checks if position is not inside of a box defined by low and high.
Definition: inBox.h:50
decltype(isPairwiseFunctorImpl(std::declval< FunctorT >())) isPairwiseFunctor
Check whether a Functor Type is inheriting from PairwiseFunctor.
Definition: checkFunctorType.h:49
bool inBox(const std::array< T, 3 > &position, const std::array< T, 3 > &low, const std::array< T, 3 > &high)
Checks if position is inside of a box defined by low and high.
Definition: inBox.h:26
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32
int autopas_get_max_threads()
Dummy for omp_get_max_threads() when no OpenMP is available.
Definition: WrapOpenMP.h:144
@ halo
Halo state, a particle with this state is an actual particle, but not owned by the current AutoPas ob...
@ owned
Owned state, a particle with this state is an actual particle and owned by the current AutoPas object...
decltype(auto) withStaticContainerType(ParticleContainerInterface< Particle_T > &container, FunctionType &&function)
Will execute the passed function body with the static container type of container.
Definition: StaticContainerSelector.h:35
int autopas_get_thread_num()
Dummy for omp_set_lock() when no OpenMP is available.
Definition: WrapOpenMP.h:132
Struct to collect all sorts of measurements taken during a computeInteractions iteration.
Definition: IterationMeasurements.h:13
double energyWatts
Average energy consumed per time in Watts.
Definition: IterationMeasurements.h:42
double energyDeltaT
Time in seconds during which energy was consumed.
Definition: IterationMeasurements.h:52
long timeRebuild
Time it takes for rebuilding neighbor lists.
Definition: IterationMeasurements.h:27
long energyTotal
Total energy consumed so far.
Definition: IterationMeasurements.h:57
long timeTotal
Time it takes for the complete iteratePairwise pipeline.
Definition: IterationMeasurements.h:32
long timeRemainderTraversal
Time it takes for the Remainder Traversal.
Definition: IterationMeasurements.h:22
long timeComputeInteractions
Time it takes for the LogicHandler's computeInteractions() function.
Definition: IterationMeasurements.h:17
bool energyMeasurementsPossible
Bool whether energy measurements are currently possible.
Definition: IterationMeasurements.h:37
double energyJoules
Total energy consumed in Joules.
Definition: IterationMeasurements.h:47