46template <
typename Particle_T>
56 LogicHandler(std::unordered_map<InteractionTypeOption::Value, std::unique_ptr<AutoTuner>> &autotuners,
57 const LogicHandlerInfo &logicHandlerInfo,
unsigned int rebuildFrequency,
const std::string &outputSuffix)
58 : _autoTunerRefs(autotuners),
59 _logicHandlerInfo(logicHandlerInfo),
60 _neighborListRebuildFrequency{rebuildFrequency},
63 _containerSelector(logicHandlerInfo.boxMin, logicHandlerInfo.boxMax, logicHandlerInfo.cutoff),
64 _verletClusterSize(logicHandlerInfo.verletClusterSize),
65 _sortingThreshold(logicHandlerInfo.sortingThreshold),
66 _iterationLogger(outputSuffix, std::any_of(autotuners.
begin(), autotuners.end(),
67 [](const auto &tuner) {
return tuner.second->canMeasureEnergy(); })),
68 _flopLogger(outputSuffix),
69 _liveInfoLogger(outputSuffix),
71 using namespace autopas::utils::ArrayMath::literals;
73 for (
const auto &[interactionType, tuner] : autotuners) {
74 _interactionTypes.insert(interactionType);
76 const auto configuration = tuner->getCurrentConfig();
79 _neighborListRebuildFrequency, _verletClusterSize,
80 configuration.loadEstimator};
81 _containerSelector.selectContainer(configuration.container, containerSelectorInfo);
86 const auto interactionLength = logicHandlerInfo.cutoff + logicHandlerInfo.verletSkin;
87 const auto interactionLengthInv = 1. / interactionLength;
88 const auto boxLengthWithHalo = logicHandlerInfo.boxMax - logicHandlerInfo.boxMin + (2 * interactionLength);
89 initSpacialLocks(boxLengthWithHalo, interactionLengthInv);
90 for (
auto &lockPtr : _bufferLocks) {
91 lockPtr = std::make_unique<std::mutex>();
107 const auto &boxMin = _containerSelector.getCurrentContainer().getBoxMin();
108 const auto &boxMax = _containerSelector.getCurrentContainer().getBoxMax();
109 std::vector<Particle_T> leavingBufferParticles{};
110 for (
auto &cell : _particleBuffer) {
111 auto &buffer = cell._particles;
112 if (insertOwnedParticlesToContainer) {
114 for (
auto &p : buffer) {
120 _containerSelector.getCurrentContainer().addParticle(p);
122 leavingBufferParticles.push_back(p);
127 for (
auto iter = buffer.begin(); iter < buffer.end();) {
130 auto fastRemoveP = [&]() {
132 std::swap(p, buffer.back());
144 if (not buffer.empty() and
utils::notInBox(p.getR(), boxMin, boxMax)) {
145 leavingBufferParticles.push_back(p);
153 return leavingBufferParticles;
160#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
165 if (_functorCalls > 0) {
167 for (
const auto &[interactionType, autoTuner] : _autoTunerRefs) {
170 if (autoTuner->inLastTuningIteration()) {
171 _iterationAtEndOfLastTuningPhase = _iteration;
173 autoTuner->bumpIterationCounters(needsToWait);
177 if (not _neighborListsAreValid.load(std::memory_order_relaxed)) {
178 _stepsSinceLastListRebuild = 0;
180 ++_stepsSinceLastListRebuild;
181 _containerSelector.getCurrentContainer().setStepsSinceLastRebuild(_stepsSinceLastListRebuild);
188 AutoPasLog(TRACE,
"Initiating container update.");
189 auto leavingParticles = _containerSelector.getCurrentContainer().updateContainer(not doDataStructureUpdate);
190 leavingParticles.insert(leavingParticles.end(), leavingBufferParticles.begin(), leavingBufferParticles.end());
193 _numParticlesOwned.fetch_sub(leavingParticles.size(), std::memory_order_relaxed);
195 std::for_each(_haloParticleBuffer.begin(), _haloParticleBuffer.end(), [](
auto &buffer) { buffer.clear(); });
196 _numParticlesHalo.store(0, std::memory_order_relaxed);
197 return leavingParticles;
206 std::vector<Particle_T>
resizeBox(
const std::array<double, 3> &boxMin,
const std::array<double, 3> &boxMax) {
207 using namespace autopas::utils::ArrayMath::literals;
208 const auto &oldMin = _containerSelector.getCurrentContainer().getBoxMin();
209 const auto &oldMax = _containerSelector.getCurrentContainer().getBoxMax();
212 if (oldMin == boxMin and oldMax == boxMax) {
217 for (
size_t i = 0; i < boxMin.size(); ++i) {
218 if (boxMin[i] >= boxMax[i]) {
220 "New box size in dimension {} is not positive!\nboxMin[{}] = {}\nboxMax[{}] = {}", i, i, boxMin[i], i,
226 const auto newLength = boxMax - boxMin;
227 const auto oldLength = oldMax - oldMin;
228 const auto relDiffLength = newLength / oldLength;
229 for (
size_t i = 0; i < newLength.size(); ++i) {
231 if (relDiffLength[i] > 1.3 or relDiffLength[i] < 0.7) {
233 "LogicHandler.resize(): Domain size changed drastically in dimension {}! Gathered AutoTuning "
234 "information might not be applicable anymore!\n"
235 "Size old box : {}\n"
236 "Size new box : {}\n"
244 std::vector<Particle_T> particlesNowOutside;
245 for (
auto pIter = _containerSelector.getCurrentContainer().begin(); pIter.isValid(); ++pIter) {
247 if (not pIter->isOwned()) {
249 "LogicHandler::resizeBox() encountered non owned particle. "
250 "When calling resizeBox() these should be already deleted. "
251 "This could be solved by calling updateContainer() before resizeBox().");
255 particlesNowOutside.push_back(*pIter);
262 _containerSelector.resizeBox(boxMin, boxMax);
264 const auto boxLength = boxMax - boxMin;
265 const auto interactionLengthInv = 1. / (_containerSelector.getCurrentContainer().getInteractionLength());
266 initSpacialLocks(boxLength, interactionLengthInv);
269 _neighborListsAreValid.store(
false, std::memory_order_relaxed);
271 return particlesNowOutside;
281 const auto &container = _containerSelector.getCurrentContainer();
283 numParticles, container.getBoxMin(), container.getBoxMax(), container.getInteractionLength());
284 reserve(numParticles, numParticlesHaloEstimate);
293 void reserve(
size_t numParticles,
size_t numHaloParticles) {
294 const auto numHaloParticlesPerBuffer = numHaloParticles / _haloParticleBuffer.size();
295 for (
auto &buffer : _haloParticleBuffer) {
296 buffer.reserve(numHaloParticlesPerBuffer);
299 for (
auto &buffer : _particleBuffer) {
300 buffer.reserve(numHaloParticlesPerBuffer);
303 _containerSelector.getCurrentContainer().reserve(numParticles, numHaloParticles);
311 const auto &boxMin = _containerSelector.getCurrentContainer().getBoxMin();
312 const auto &boxMax = _containerSelector.getCurrentContainer().getBoxMax();
315 "LogicHandler: Trying to add a particle that is not in the bounding box.\n"
319 boxMin, boxMax, p.toString());
321 Particle_T particleCopy = p;
323 if (not _neighborListsAreValid.load(std::memory_order_relaxed)) {
325 _containerSelector.getCurrentContainer().template addParticle<false>(particleCopy);
330 _numParticlesOwned.fetch_add(1, std::memory_order_relaxed);
337 auto &container = _containerSelector.getCurrentContainer();
338 const auto &boxMin = container.getBoxMin();
339 const auto &boxMax = container.getBoxMax();
340 Particle_T haloParticleCopy = haloParticle;
341 if (
utils::inBox(haloParticleCopy.getR(), boxMin, boxMax)) {
343 "LogicHandler: Trying to add a halo particle that is not outside the box of the container.\n"
350 if (not _neighborListsAreValid.load(std::memory_order_relaxed)) {
355 bool updated = container.updateHaloParticle(haloParticleCopy);
361 _numParticlesHalo.fetch_add(1, std::memory_order_relaxed);
368 _neighborListsAreValid.store(
false, std::memory_order_relaxed);
369 _containerSelector.getCurrentContainer().deleteAllParticles();
370 std::for_each(_particleBuffer.begin(), _particleBuffer.end(), [](
auto &buffer) { buffer.clear(); });
371 std::for_each(_haloParticleBuffer.begin(), _haloParticleBuffer.end(), [](
auto &buffer) { buffer.clear(); });
373 _numParticlesOwned.store(0, std::memory_order_relaxed);
374 _numParticlesHalo.store(0, std::memory_order_relaxed);
385 auto &bufferCollection = particle.isOwned() ? _particleBuffer : _haloParticleBuffer;
386 for (
auto &cell : bufferCollection) {
387 auto &buffer = cell._particles;
389 if (not buffer.empty() and &(buffer.front()) <= &particle and &particle <= &(buffer.back())) {
390 const bool isRearParticle = &particle == &buffer.back();
392 particle = buffer.back();
394 return {
true, not isRearParticle};
397 return {
false,
true};
406 if (particle.isOwned()) {
407 _numParticlesOwned.fetch_sub(1, std::memory_order_relaxed);
409 _numParticlesHalo.fetch_sub(1, std::memory_order_relaxed);
433 template <
class Functor>
442 template <
class Iterator>
444 typename Iterator::ParticleVecType additionalVectors;
445 if (not(behavior & IteratorBehavior::containerOnly)) {
446 additionalVectors.reserve(
static_cast<bool>(behavior & IteratorBehavior::owned) * _particleBuffer.size() +
447 static_cast<bool>(behavior & IteratorBehavior::halo) * _haloParticleBuffer.size());
448 if (behavior & IteratorBehavior::owned) {
449 for (
auto &buffer : _particleBuffer) {
453 if (not buffer.isEmpty()) {
454 additionalVectors.push_back(&(buffer._particles));
458 if (behavior & IteratorBehavior::halo) {
459 for (
auto &buffer : _haloParticleBuffer) {
460 if (not buffer.isEmpty()) {
461 additionalVectors.push_back(&(buffer._particles));
466 return additionalVectors;
473 auto additionalVectors = gatherAdditionalVectors<ContainerIterator<Particle_T, true, false>>(behavior);
474 return _containerSelector.getCurrentContainer().begin(behavior, &additionalVectors);
481 auto additionalVectors =
484 return _containerSelector.getCurrentContainer().begin(behavior, &additionalVectors);
491 const std::array<double, 3> &higherCorner,
492 IteratorBehavior behavior) {
494 for (
size_t d = 0; d < 3; ++d) {
495 if (lowerCorner[d] > higherCorner[d]) {
497 "Requesting region Iterator where the upper corner is lower than the lower corner!\n"
500 lowerCorner, higherCorner);
504 auto additionalVectors = gatherAdditionalVectors<ContainerIterator<Particle_T, true, true>>(behavior);
505 return _containerSelector.getCurrentContainer().getRegionIterator(lowerCorner, higherCorner, behavior,
513 const std::array<double, 3> &higherCorner,
514 IteratorBehavior behavior)
const {
516 for (
size_t d = 0; d < 3; ++d) {
517 if (lowerCorner[d] > higherCorner[d]) {
519 "Requesting region Iterator where the upper corner is lower than the lower corner!\n"
522 lowerCorner, higherCorner);
526 auto additionalVectors =
528 return std::as_const(_containerSelector)
529 .getCurrentContainer()
530 .getRegionIterator(lowerCorner, higherCorner, behavior, &additionalVectors);
553 return std::any_of(std::begin(_autoTunerRefs), std::end(_autoTunerRefs), [&](
const auto &entry) {
554 return not(entry.first == interactionType) and entry.second->inTuningPhase();
572 template <
class Functor>
596 std::tuple<const std::vector<FullParticleCell<Particle_T>> &,
const std::vector<FullParticleCell<Particle_T>> &>
611#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
612 const auto numRebuilds = considerOnlyLastNonTuningPhase ? _numRebuildsInNonTuningPhase : _numRebuilds;
614 const auto iterationCount =
615 considerOnlyLastNonTuningPhase ? _iteration - _iterationAtEndOfLastTuningPhase : _iteration + 1;
616 if (numRebuilds == 0) {
617 return static_cast<double>(_neighborListRebuildFrequency);
619 return static_cast<double>(iterationCount) / numRebuilds;
622 return static_cast<double>(_neighborListRebuildFrequency);
667 void initSpacialLocks(
const std::array<double, 3> &boxLength,
double interactionLengthInv) {
668 using namespace autopas::utils::ArrayMath::literals;
678 constexpr size_t maxNumSpacialLocks{1000000};
681 const std::array<size_t, 3> locksPerDim = [&]() {
684 const std::array<size_t, 3> locksPerDimNaive =
685 static_cast_copy_array<size_t>(ceil(boxLength * interactionLengthInv));
686 const auto totalLocksNaive =
687 std::accumulate(locksPerDimNaive.begin(), locksPerDimNaive.end(), 1ul, std::multiplies<>());
689 if (totalLocksNaive <= maxNumSpacialLocks) {
690 return locksPerDimNaive;
694 const std::array<double, 3> boxSideProportions = {
696 boxLength[0] / boxLength[1],
697 boxLength[0] / boxLength[2],
700 const auto prodProportions =
701 std::accumulate(boxSideProportions.begin(), boxSideProportions.end(), 1., std::multiplies<>());
703 const auto locksInFirstDimFloat = std::floor(std::cbrt(maxNumSpacialLocks * prodProportions));
705 const std::array<size_t, 3> locksPerDimLimited = {
706 static_cast<size_t>(locksInFirstDimFloat),
707 static_cast<size_t>(locksInFirstDimFloat / boxSideProportions[1]),
708 static_cast<size_t>(locksInFirstDimFloat / boxSideProportions[2]),
710 return locksPerDimLimited;
713 _spacialLocks.resize(locksPerDim[0]);
714 for (
auto &lockVecVec : _spacialLocks) {
715 lockVecVec.resize(locksPerDim[1]);
716 for (
auto &lockVec : lockVecVec) {
717 lockVec.resize(locksPerDim[2]);
718 for (
auto &lockPtr : lockVec) {
720 lockPtr = std::make_unique<std::mutex>();
734 template <
class Functor>
735 std::tuple<Configuration, std::unique_ptr<TraversalInterface>,
bool> selectConfiguration(
736 Functor &functor,
const InteractionTypeOption &interactionType);
752 template <
class Functor>
765 template <
class Functor>
766 void computeRemainderInteractions(
Functor &functor,
bool newton3,
bool useSoA);
789 template <
bool newton3,
class ContainerType,
class PairwiseFunctor>
790 void computeRemainderInteractions2B(
PairwiseFunctor *f, ContainerType &container,
807 template <
bool newton3,
class ContainerType,
class PairwiseFunctor>
808 void remainderHelperBufferContainerAoS(
PairwiseFunctor *f, ContainerType &container,
821 template <
bool newton3,
class PairwiseFunctor>
832 template <
bool newton3,
class PairwiseFunctor>
842 template <
bool newton3,
class PairwiseFunctor>
858 template <
class PairwiseFunctor>
869 template <
class PairwiseFunctor>
881 template <
class PairwiseFunctor>
906 template <
bool newton3,
class ContainerType,
class TriwiseFunctor>
907 void computeRemainderInteractions3B(
TriwiseFunctor *f, ContainerType &container,
921 size_t collectBufferParticles(std::vector<Particle_T *> &bufferParticles,
934 template <
class TriwiseFunctor>
935 void remainderHelper3bBufferBufferBufferAoS(
const std::vector<Particle_T *> &bufferParticles,
949 template <
class ContainerType,
class TriwiseFunctor>
950 void remainderHelper3bBufferBufferContainerAoS(
const std::vector<Particle_T *> &bufferParticles,
951 size_t numOwnedBufferParticles, ContainerType &container,
966 template <
bool newton3,
class ContainerType,
class TriwiseFunctor>
967 void remainderHelper3bBufferContainerContainerAoS(
const std::vector<Particle_T *> &bufferParticles,
968 size_t numOwnedBufferParticles, ContainerType &container,
976 void checkMinimalSize()
const;
982 unsigned int _neighborListRebuildFrequency;
987 unsigned int _verletClusterSize;
992 size_t _numRebuilds{0};
998 size_t _numRebuildsInNonTuningPhase{0};
1003 size_t _sortingThreshold;
1008 std::unordered_map<InteractionTypeOption::Value, std::unique_ptr<autopas::AutoTuner>> &_autoTunerRefs;
1013 std::set<InteractionTypeOption> _interactionTypes{};
1018 std::atomic<bool> _neighborListsAreValid{
false};
1023 unsigned int _stepsSinceLastListRebuild{0};
1028 unsigned int _functorCalls{0};
1033 unsigned int _iteration{0};
1038 unsigned int _iterationAtEndOfLastTuningPhase{0};
1043 std::atomic<size_t> _numParticlesOwned{0ul};
1048 std::atomic<size_t> _numParticlesHalo{0ul};
1053 std::vector<FullParticleCell<Particle_T>> _particleBuffer;
1058 std::vector<FullParticleCell<Particle_T>> _haloParticleBuffer;
1070 std::vector<std::vector<std::vector<std::unique_ptr<std::mutex>>>> _spacialLocks;
1075 std::vector<std::unique_ptr<std::mutex>> _bufferLocks;
1086 bool _neighborListInvalidDoDynamicRebuild{
false};
1091 void updateRebuildPositions();
1104template <
typename Particle_T>
1106#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
1111 for (
auto iter = this->begin(IteratorBehavior::owned | IteratorBehavior::containerOnly); iter.isValid(); ++iter) {
1112 iter->resetRAtRebuild();
1117template <
typename Particle_T>
1119 const auto &container = _containerSelector.getCurrentContainer();
1121 for (
unsigned int dim = 0; dim < 3; ++dim) {
1122 if (container.getBoxMax()[dim] - container.getBoxMin()[dim] < container.getInteractionLength()) {
1124 "Box (boxMin[{}]={} and boxMax[{}]={}) is too small.\nHas to be at least cutoff({}) + skin({}) = {}.", dim,
1125 container.getBoxMin()[dim], dim, container.getBoxMax()[dim], container.getCutoff(), container.getVerletSkin(),
1126 container.getCutoff() + container.getVerletSkin());
1131template <
typename Particle_T>
1133 return _neighborListInvalidDoDynamicRebuild;
1136template <
typename Particle_T>
1139 const auto needRebuild = [&](
const InteractionTypeOption &interactionOption) {
1140 return _interactionTypes.count(interactionOption) != 0 and
1141 _autoTunerRefs[interactionOption]->willRebuildNeighborLists();
1144 if (_stepsSinceLastListRebuild >= _neighborListRebuildFrequency
1145#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
1146 or getNeighborListsInvalidDoDynamicRebuild()
1148 or needRebuild(InteractionTypeOption::pairwise) or needRebuild(InteractionTypeOption::triwise)) {
1149 _neighborListsAreValid.store(
false, std::memory_order_relaxed);
1152 return _neighborListsAreValid.load(std::memory_order_relaxed);
1155template <
typename Particle_T>
1157#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
1158 const auto skin = getContainer().getVerletSkin();
1160 const auto halfSkinSquare = skin * skin * 0.25;
1164 AUTOPAS_OPENMP(parallel reduction(or : _neighborListInvalidDoDynamicRebuild))
1165 for (
auto iter = this->begin(IteratorBehavior::owned | IteratorBehavior::containerOnly); iter.isValid(); ++iter) {
1166 const auto distance = iter->calculateDisplacementSinceRebuild();
1169 _neighborListInvalidDoDynamicRebuild |= distanceSquare >= halfSkinSquare;
1174template <
typename Particle_T>
1176 _neighborListInvalidDoDynamicRebuild =
false;
1179template <
typename Particle_T>
1183 auto exchangeBuffer = [](
const auto &newBuffers,
auto &oldBuffers,
auto &particleCounter) {
1185 if (oldBuffers.size() < newBuffers.size()) {
1187 "The number of new buffers ({}) is larger than number of existing buffers ({})!", newBuffers.size(),
1192 const auto numParticlesInOldBuffers =
1193 std::transform_reduce(oldBuffers.begin(), std::next(oldBuffers.begin(), newBuffers.size()), 0, std::plus<>(),
1194 [](
const auto &cell) { return cell.size(); });
1195 particleCounter.fetch_sub(numParticlesInOldBuffers, std::memory_order_relaxed);
1198 size_t numParticlesInNewBuffers = 0;
1199 for (
size_t i = 0; i < newBuffers.size(); ++i) {
1200 oldBuffers[i].clear();
1201 for (
const auto &p : newBuffers[i]) {
1202 ++numParticlesInNewBuffers;
1203 oldBuffers[i].addParticle(p);
1207 particleCounter.fetch_add(numParticlesInNewBuffers, std::memory_order_relaxed);
1210 exchangeBuffer(particleBuffers, _particleBuffer, _numParticlesOwned);
1211 exchangeBuffer(haloParticleBuffers, _haloParticleBuffer, _numParticlesHalo);
1214template <
typename Particle_T>
1215std::tuple<const std::vector<FullParticleCell<Particle_T>> &,
const std::vector<FullParticleCell<Particle_T>> &>
1217 return {_particleBuffer, _haloParticleBuffer};
1220template <
typename Particle_T>
1221template <
class Functor>
1224 constexpr auto interactionType = [] {
1226 return InteractionTypeOption::pairwise;
1228 return InteractionTypeOption::triwise;
1231 "LogicHandler::computeInteractions(): Functor is not valid. Only pairwise and triwise functors are "
1233 "Please use a functor derived from "
1234 "PairwiseFunctor or TriwiseFunctor.");
1238 auto &autoTuner = *_autoTunerRefs[interactionType];
1239 auto &container = _containerSelector.getCurrentContainer();
1240#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
1241 if (autoTuner.inFirstTuningIteration()) {
1242 autoTuner.setRebuildFrequency(getMeanRebuildFrequency(
true));
1243 _numRebuildsInNonTuningPhase = 0;
1251 const bool energyMeasurementsPossible = autoTuner.resetEnergy();
1257 if (not _neighborListsAreValid.load(std::memory_order_relaxed)) {
1258 timerRebuild.
start();
1259#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
1260 this->updateRebuildPositions();
1262 container.rebuildNeighborLists(&traversal);
1263#ifdef AUTOPAS_ENABLE_DYNAMIC_CONTAINERS
1264 this->resetNeighborListsInvalidDoDynamicRebuild();
1266 if (not autoTuner.inTuningPhase()) {
1267 _numRebuildsInNonTuningPhase++;
1270 timerRebuild.
stop();
1271 _neighborListsAreValid.store(
true, std::memory_order_relaxed);
1274 timerComputeInteractions.
start();
1275 container.computeInteractions(&traversal);
1276 timerComputeInteractions.
stop();
1278 timerComputeRemainder.
start();
1279 const bool newton3 = autoTuner.getCurrentConfig().newton3;
1280 const auto dataLayout = autoTuner.getCurrentConfig().dataLayout;
1281 computeRemainderInteractions(functor, newton3, dataLayout);
1282 timerComputeRemainder.
stop();
1286 const auto [energyWatts, energyJoules, energyDeltaT, energyTotal] = autoTuner.sampleEnergy();
1289 constexpr auto nanD = std::numeric_limits<double>::quiet_NaN();
1290 constexpr auto nanL = std::numeric_limits<long>::quiet_NaN();
1295 energyMeasurementsPossible,
1296 energyMeasurementsPossible ? energyWatts : nanD,
1297 energyMeasurementsPossible ? energyJoules : nanD,
1298 energyMeasurementsPossible ? energyDeltaT : nanD,
1299 energyMeasurementsPossible ? energyTotal : nanL};
1302template <
typename Particle_T>
1303template <
class Functor>
1305 auto &container = _containerSelector.getCurrentContainer();
1310 computeRemainderInteractions2B<true>(&functor, actualContainerType, _particleBuffer, _haloParticleBuffer,
1313 computeRemainderInteractions2B<false>(&functor, actualContainerType, _particleBuffer, _haloParticleBuffer,
1318 computeRemainderInteractions3B<true>(&functor, actualContainerType, _particleBuffer, _haloParticleBuffer);
1320 computeRemainderInteractions3B<false>(&functor, actualContainerType, _particleBuffer, _haloParticleBuffer);
1326template <
class Particle_T>
1327template <
bool newton3,
class ContainerType,
class PairwiseFunctor>
1332 if (_bufferLocks.size() < particleBuffers.size()) {
1334 _bufferLocks.size(), particleBuffers.size());
1340 auto cellToVec = [](
auto &cell) -> std::vector<Particle_T> & {
return cell._particles; };
1348#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
1354 timerBufferContainer.
start();
1361 remainderHelperBufferContainerAoS<newton3>(f, container, particleBuffers, haloParticleBuffers);
1363#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
1364 timerBufferContainer.
stop();
1365 timerBufferSoAConversion.
start();
1369 for (
auto &buffer : particleBuffers) {
1370 f->
SoALoader(buffer, buffer._particleSoABuffer, 0,
false);
1372 for (
auto &buffer : haloParticleBuffers) {
1373 f->
SoALoader(buffer, buffer._particleSoABuffer, 0,
false);
1376#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
1377 timerBufferSoAConversion.
stop();
1378 timerPBufferPBuffer.
start();
1382 remainderHelperBufferBuffer<newton3>(f, particleBuffers, useSoA);
1384#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
1385 timerPBufferPBuffer.
stop();
1386 timerPBufferHBuffer.
start();
1390 remainderHelperBufferHaloBuffer(f, particleBuffers, haloParticleBuffers, useSoA);
1392#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
1393 timerPBufferHBuffer.
stop();
1398 for (
auto &buffer : particleBuffers) {
1411template <
class Particle_T>
1412template <
bool newton3,
class ContainerType,
class PairwiseFunctor>
1417 using namespace autopas::utils::ArrayMath::literals;
1420 const auto cutoff = container.getCutoff();
1421 const auto interactionLength = container.getInteractionLength();
1422 const auto interactionLengthInv = 1. / interactionLength;
1423 const auto haloBoxMin = container.getBoxMin() - interactionLength;
1424 const auto totalBoxLengthInv = 1. / (container.getBoxMax() + interactionLength - haloBoxMin);
1425 const std::array<size_t, 3> spacialLocksPerDim{
1426 _spacialLocks.size(),
1427 _spacialLocks[0].size(),
1428 _spacialLocks[0][0].size(),
1433 const auto getSpacialLock = [&](
const std::array<double, 3> &pos) -> std::mutex & {
1434 const auto posDistFromLowerCorner = pos - haloBoxMin;
1435 const auto relativePos = posDistFromLowerCorner * totalBoxLengthInv;
1437 const auto lockCoords =
1438 static_cast_copy_array<size_t>(static_cast_copy_array<double>(spacialLocksPerDim) * relativePos);
1439 return *_spacialLocks[lockCoords[0]][lockCoords[1]][lockCoords[2]];
1444 for (
int bufferId = 0; bufferId < particleBuffers.size(); ++bufferId) {
1445 auto &particleBuffer = particleBuffers[bufferId];
1446 auto &haloParticleBuffer = haloParticleBuffers[bufferId];
1448 for (
auto &&p1 : particleBuffer) {
1449 const auto pos = p1.getR();
1450 const auto min = pos - cutoff;
1451 const auto max = pos + cutoff;
1452 container.forEachInRegion(
1454 if constexpr (newton3) {
1455 const std::lock_guard<std::mutex> lock(getSpacialLock(p2.getR()));
1460 if (not p2.isHalo()) {
1461 const std::lock_guard<std::mutex> lock(getSpacialLock(p2.getR()));
1466 min,
max, IteratorBehavior::ownedOrHalo);
1470 for (
auto &&p1halo : haloParticleBuffer) {
1471 const auto pos = p1halo.getR();
1472 const auto min = pos - cutoff;
1473 const auto max = pos + cutoff;
1474 container.forEachInRegion(
1479 const std::lock_guard<std::mutex> lock(getSpacialLock(p2.getR()));
1482 min,
max, IteratorBehavior::owned);
1487template <
class Particle_T>
1488template <
bool newton3,
class PairwiseFunctor>
1493 remainderHelperBufferBufferSoA<newton3>(f, particleBuffers);
1495 remainderHelperBufferBufferAoS<newton3>(f, particleBuffers);
1499template <
class Particle_T>
1500template <
bool newton3,
class PairwiseFunctor>
1509 for (
size_t bufferIdxI = 0; bufferIdxI < particleBuffers.size(); ++bufferIdxI) {
1510 for (
size_t bufferIdxJOffset = 0; bufferIdxJOffset < particleBuffers.size(); ++bufferIdxJOffset) {
1512 const auto bufferIdxJ = (bufferIdxI + bufferIdxJOffset) % particleBuffers.size();
1515 if (bufferIdxI == bufferIdxJ) {
1518 const bool useNewton3 = newton3;
1519 auto &bufferRef = particleBuffers[bufferIdxI];
1520 const auto bufferSize = bufferRef.size();
1521 for (
auto i = 0; i < bufferSize; ++i) {
1522 auto &p1 = bufferRef[i];
1524 for (
auto j = useNewton3 ? i + 1 : 0; j < bufferSize; ++j) {
1528 auto &p2 = bufferRef[j];
1534 for (
auto &p1 : particleBuffers[bufferIdxI]) {
1535 for (
auto &p2 : particleBuffers[bufferIdxJ]) {
1544template <
class Particle_T>
1545template <
bool newton3,
class PairwiseFunctor>
1550 for (
size_t i = 0; i < particleBuffers.size(); ++i) {
1551 for (
size_t jj = 0; jj < particleBuffers.size(); ++jj) {
1552 auto *particleBufferSoAA = &particleBuffers[i]._particleSoABuffer;
1554 const auto j = (i + jj) % particleBuffers.size();
1561 auto *particleBufferSoAB = &particleBuffers[j]._particleSoABuffer;
1562 f->
SoAFunctorPair(*particleBufferSoAA, *particleBufferSoAB,
false);
1568template <
class Particle_T>
1569template <
class PairwiseFunctor>
1574 remainderHelperBufferHaloBufferSoA<PairwiseFunctor>(f, particleBuffers, haloParticleBuffers);
1576 remainderHelperBufferHaloBufferAoS<PairwiseFunctor>(f, particleBuffers, haloParticleBuffers);
1580template <
class Particle_T>
1581template <
class PairwiseFunctor>
1587 for (
int interactionOffset = 0; interactionOffset < haloParticleBuffers.size(); ++interactionOffset) {
1589 for (
size_t i = 0; i < particleBuffers.size(); ++i) {
1590 auto &particleBuffer = particleBuffers[i];
1591 auto &haloBuffer = haloParticleBuffers[(i + interactionOffset) % haloParticleBuffers.size()];
1593 for (
auto &p1 : particleBuffer) {
1594 for (
auto &p2 : haloBuffer) {
1602template <
class Particle_T>
1603template <
class PairwiseFunctor>
1609 for (
int interactionOffset = 0; interactionOffset < haloParticleBuffers.size(); ++interactionOffset) {
1611 for (
size_t i = 0; i < particleBuffers.size(); ++i) {
1612 auto &particleBufferSoA = particleBuffers[i]._particleSoABuffer;
1613 auto &haloBufferSoA =
1614 haloParticleBuffers[(i + interactionOffset) % haloParticleBuffers.size()]._particleSoABuffer;
1620template <
class Particle_T>
1621template <
bool newton3,
class ContainerType,
class TriwiseFunctor>
1626 std::vector<Particle_T *> bufferParticles;
1627 const auto numOwnedBufferParticles = collectBufferParticles(bufferParticles, particleBuffers, haloParticleBuffers);
1632#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
1636 timerBufferBufferBuffer.
start();
1640 remainderHelper3bBufferBufferBufferAoS(bufferParticles, numOwnedBufferParticles, f);
1642#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
1643 timerBufferBufferBuffer.
stop();
1644 timerBufferBufferContainer.
start();
1648 remainderHelper3bBufferBufferContainerAoS(bufferParticles, numOwnedBufferParticles, container, f);
1650#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
1651 timerBufferBufferContainer.
stop();
1652 timerBufferContainerContainer.
start();
1656 remainderHelper3bBufferContainerContainerAoS<newton3>(bufferParticles, numOwnedBufferParticles, container, f);
1658#if SPDLOG_ACTIVE_LEVEL <= SPDLOG_LEVEL_TRACE
1659 timerBufferContainerContainer.
stop();
1663 AutoPasLog(TRACE,
"Timer Buffer <-> Buffer <-> Container : {}", timerBufferBufferContainer.
getTotalTime());
1664 AutoPasLog(TRACE,
"Timer Buffer <-> Container <-> Container : {}", timerBufferContainerContainer.
getTotalTime());
1667template <
class Particle_T>
1672 auto cellToVec = [](
auto &cell) -> std::vector<Particle_T> & {
return cell._particles; };
1674 const size_t numOwnedBufferParticles =
1675 std::transform_reduce(particleBuffers.begin(), particleBuffers.end(), 0, std::plus<>(),
1676 [&](
auto &vec) { return cellToVec(vec).size(); });
1678 const size_t numHaloBufferParticles =
1679 std::transform_reduce(haloParticleBuffers.begin(), haloParticleBuffers.end(), 0, std::plus<>(),
1680 [&](
auto &vec) { return cellToVec(vec).size(); });
1682 bufferParticles.reserve(numOwnedBufferParticles + numHaloBufferParticles);
1685 for (
auto &buffer : particleBuffers) {
1686 for (
auto &particle : buffer._particles) {
1687 bufferParticles.push_back(&particle);
1692 for (
auto &buffer : haloParticleBuffers) {
1693 for (
auto &particle : buffer._particles) {
1694 bufferParticles.push_back(&particle);
1698 return numOwnedBufferParticles;
1701template <
class Particle_T>
1702template <
class TriwiseFunctor>
1704 const size_t numOwnedBufferParticles,
1707 for (
auto i = 0; i < numOwnedBufferParticles; ++i) {
1708 Particle_T &p1 = *bufferParticles[i];
1710 for (
auto j = 0; j < bufferParticles.size(); ++j) {
1711 if (i == j)
continue;
1712 Particle_T &p2 = *bufferParticles[j];
1714 for (
auto k = j + 1; k < bufferParticles.size(); ++k) {
1715 if (k == i)
continue;
1716 Particle_T &p3 = *bufferParticles[k];
1724template <
class Particle_T>
1725template <
class ContainerType,
class TriwiseFunctor>
1727 const std::vector<Particle_T *> &bufferParticles,
const size_t numOwnedBufferParticles, ContainerType &container,
1730 using namespace autopas::utils::ArrayMath::literals;
1732 const auto haloBoxMin = container.getBoxMin() - container.getInteractionLength();
1733 const auto interactionLengthInv = 1. / container.getInteractionLength();
1734 const double cutoff = container.getCutoff();
1737 for (
auto i = 0; i < bufferParticles.size(); ++i) {
1738 Particle_T &p1 = *bufferParticles[i];
1739 const auto pos = p1.getR();
1740 const auto min = pos - cutoff;
1741 const auto max = pos + cutoff;
1743 for (
auto j = 0; j < bufferParticles.size(); ++j) {
1744 if (j == i)
continue;
1745 Particle_T &p2 = *bufferParticles[j];
1747 container.forEachInRegion(
1749 const auto lockCoords = static_cast_copy_array<size_t>((p3.getR() - haloBoxMin) * interactionLengthInv);
1750 if (i < numOwnedBufferParticles) f->
AoSFunctor(p1, p2, p3,
false);
1751 if (!p3.isHalo() && i < j) {
1752 const std::lock_guard<std::mutex> lock(*_spacialLocks[lockCoords[0]][lockCoords[1]][lockCoords[2]]);
1756 min,
max, IteratorBehavior::ownedOrHalo);
1761template <
class Particle_T>
1762template <
bool newton3,
class ContainerType,
class TriwiseFunctor>
1764 const std::vector<Particle_T *> &bufferParticles,
const size_t numOwnedBufferParticles, ContainerType &container,
1768 using namespace autopas::utils::ArrayMath::literals;
1770 const double cutoff = container.getCutoff();
1772 for (
auto i = 0; i < bufferParticles.size(); ++i) {
1773 Particle_T &p1 = *bufferParticles[i];
1774 const auto pos = p1.getR();
1775 const auto boxmin = pos - cutoff;
1776 const auto boxmax = pos + cutoff;
1778 auto p2Iter = container.getRegionIterator(
1779 boxmin, boxmax, IteratorBehavior::ownedOrHalo | IteratorBehavior::forceSequential,
nullptr);
1780 for (; p2Iter.isValid(); ++p2Iter) {
1781 Particle_T &p2 = *p2Iter;
1783 auto p3Iter = p2Iter;
1786 for (; p3Iter.isValid(); ++p3Iter) {
1787 Particle_T &p3 = *p3Iter;
1789 if constexpr (newton3) {
1792 if (i < numOwnedBufferParticles) {
1807template <
typename Particle_T>
1808template <
class Functor>
1810 Functor &functor,
const InteractionTypeOption &interactionType) {
1811 bool stillTuning =
false;
1813 std::optional<std::unique_ptr<TraversalInterface>> traversalPtrOpt{};
1814 auto &autoTuner = *_autoTunerRefs[interactionType];
1821 stillTuning =
false;
1822 configuration = autoTuner.getCurrentConfig();
1825 if (_containerSelector.getCurrentContainer().getContainerType() != configuration.container) {
1826 _containerSelector.selectContainer(
1827 configuration.container,
1828 ContainerSelectorInfo(configuration.cellSizeFactor, _containerSelector.getCurrentContainer().getVerletSkin(),
1829 _neighborListRebuildFrequency, _verletClusterSize, configuration.loadEstimator));
1831 const auto &container = _containerSelector.getCurrentContainer();
1832 traversalPtrOpt = autopas::utils::withStaticCellType<Particle_T>(
1833 container.getParticleCellTypeEnum(), [&](
const auto &particleCellDummy) ->
decltype(traversalPtrOpt) {
1836 TraversalSelector<std::decay_t<decltype(particleCellDummy)>>::template generateTraversal<Functor>(
1837 configuration.traversal, functor, container.getTraversalSelectorInfo(), configuration.dataLayout,
1838 configuration.newton3);
1841 if (auto *cellTraversalPtr =
1842 dynamic_cast<autopas::CellTraversal<std::decay_t<decltype(particleCellDummy)>> *>(
1843 traversalPtr.get())) {
1844 cellTraversalPtr->setSortingThreshold(_sortingThreshold);
1846 if (traversalPtr->isApplicable()) {
1847 return std::optional{std::move(traversalPtr)};
1849 return std::nullopt;
1853 if (autoTuner.needsHomogeneityAndMaxDensityBeforePrepare()) {
1855 timerCalculateHomogeneity.
start();
1856 const auto &container = _containerSelector.getCurrentContainer();
1858 timerCalculateHomogeneity.
stop();
1859 autoTuner.addHomogeneityAndMaxDensity(homogeneity, maxDensity, timerCalculateHomogeneity.
getTotalTime());
1862 const auto needsLiveInfo = autoTuner.prepareIteration();
1864 if (needsLiveInfo) {
1865 info.gather(_containerSelector.getCurrentContainer(), functor, _neighborListRebuildFrequency);
1866 autoTuner.receiveLiveInfo(info);
1869 std::tie(configuration, stillTuning) = autoTuner.getNextConfig();
1872 bool rejectIndefinitely =
false;
1875 std::tie(traversalPtrOpt, rejectIndefinitely) =
1876 isConfigurationApplicable(configuration, functor, interactionType);
1877 if (traversalPtrOpt.has_value()) {
1881 std::tie(configuration, stillTuning) = autoTuner.rejectConfig(configuration, rejectIndefinitely);
1885#ifdef AUTOPAS_LOG_LIVEINFO
1887 if (info.get().empty()) {
1888 info.gather(_containerSelector.getCurrentContainer(), functor, _neighborListRebuildFrequency);
1890 _liveInfoLogger.logLiveInfo(info, _iteration);
1893 return {configuration, std::move(traversalPtrOpt.value()), stillTuning};
1896template <
typename Particle_T>
1897template <
class Functor>
1899 const InteractionTypeOption &interactionType) {
1900 if (not _interactionTypes.count(interactionType)) {
1902 "LogicHandler::computeInteractionsPipeline(): AutPas was not initialized for the Functor's interactions type: "
1908 tuningTimer.
start();
1909 const auto [configuration, traversalPtr, stillTuning] = selectConfiguration(*functor, interactionType);
1911 auto &autoTuner = *_autoTunerRefs[interactionType];
1912 autoTuner.logTuningResult(stillTuning, tuningTimer.
getTotalTime());
1915 const auto rebuildIteration = not _neighborListsAreValid.load(std::memory_order_relaxed);
1918 AutoPasLog(DEBUG,
"Iterating with configuration: {} tuning: {}", configuration.toString(), stillTuning);
1922 auto bufferSizeListing = [](
const auto &buffers) -> std::string {
1923 std::stringstream ss;
1925 for (
const auto &buffer : buffers) {
1926 ss << buffer.size() <<
", ";
1927 sum += buffer.size();
1929 ss <<
" Total: " << sum;
1932 AutoPasLog(TRACE,
"particleBuffer size : {}", bufferSizeListing(_particleBuffer));
1933 AutoPasLog(TRACE,
"haloParticleBuffer size : {}", bufferSizeListing(_haloParticleBuffer));
1934 AutoPasLog(DEBUG,
"Type of interaction : {}", interactionType.to_string());
1943 _iterationLogger.logIteration(configuration, _iteration, functor->
getName(), stillTuning, tuningTimer.
getTotalTime(),
1953 const auto measurement = [&]() {
1954 switch (autoTuner.getTuningMetric()) {
1955 case TuningMetricOption::time:
1957 case TuningMetricOption::energy:
1961 "LogicHandler::computeInteractionsPipeline(): Unknown tuning metric.");
1965 autoTuner.addMeasurement(measurement, rebuildIteration);
1968 AutoPasLog(TRACE,
"Skipping adding of sample because functor is not marked relevant.");
1974template <
typename Particle_T>
1975template <
class Functor>
1976std::tuple<std::optional<std::unique_ptr<TraversalInterface>>,
bool>
1978 const InteractionTypeOption &interactionType) {
1980 const auto allContainerTraversals =
1982 if (allContainerTraversals.find(conf.
traversal) == allContainerTraversals.end()) {
1983 AutoPasLog(WARN,
"Configuration rejected: Container {} does not support the traversal {}.", conf.
container,
1985 return {std::nullopt,
true};
1991 AutoPasLog(DEBUG,
"Configuration rejected: The functor doesn't support Newton 3 {}!", conf.
newton3);
1992 return {std::nullopt,
true};
1996 _containerSelector.selectContainer(
1999 _neighborListRebuildFrequency, _verletClusterSize, conf.
loadEstimator));
2000 const auto &container = _containerSelector.getCurrentContainer();
2001 const auto traversalInfo = container.getTraversalSelectorInfo();
2003 auto traversalPtrOpt = autopas::utils::withStaticCellType<Particle_T>(
2004 container.getParticleCellTypeEnum(),
2005 [&](
const auto &particleCellDummy) -> std::optional<std::unique_ptr<TraversalInterface>> {
2008 TraversalSelector<std::decay_t<decltype(particleCellDummy)>>::template generateTraversal<Functor>(
2009 conf.traversal, functor, traversalInfo, conf.dataLayout, conf.newton3);
2012 if (auto *cellTraversalPtr =
2013 dynamic_cast<autopas::CellTraversal<std::decay_t<decltype(particleCellDummy)>> *>(traversalPtr.get())) {
2014 cellTraversalPtr->setSortingThreshold(_sortingThreshold);
2016 if (traversalPtr->isApplicable()) {
2017 return std::optional{std::move(traversalPtr)};
2019 return std::nullopt;
2022 return {std::move(traversalPtrOpt),
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
double cellSizeFactor
cellSizeFactor Cell size factor to be used in this container (only relevant for LinkedCells)
Definition: ContainerSelectorInfo.h:81
Selector for a particle container.
Definition: ContainerSelector.h:40
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:31
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
The LogicHandler takes care of the containers s.t.
Definition: LogicHandler.h:47
autopas::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:480
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:1180
autopas::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:472
void reserve(size_t numParticles, size_t numHaloParticles)
Reserves space in the particle buffers and the container.
Definition: LogicHandler.h:293
autopas::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:512
std::vector< Particle_T > updateContainer()
Updates the container.
Definition: LogicHandler.h:159
unsigned long getNumberOfParticlesOwned() const
Get the number of owned particles.
Definition: LogicHandler.h:537
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:1898
std::tuple< const std::vector< FullParticleCell< Particle_T > > &, const std::vector< FullParticleCell< Particle_T > > & > getParticleBuffers() const
Getter for the particle buffers.
Definition: LogicHandler.h:1216
void addParticle(const Particle_T &p)
Adds a particle to the container.
Definition: LogicHandler.h:309
void decreaseParticleCounter(Particle_T &particle)
Decrease the correct internal particle counters.
Definition: LogicHandler.h:405
std::vector< Particle_T > collectLeavingParticlesFromBuffer(bool insertOwnedParticlesToContainer)
Collects leaving particles from buffer and potentially inserts owned particles to the container.
Definition: LogicHandler.h:106
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:56
bool neighborListsAreValid()
Checks if in the next iteration the neighbor lists have to be rebuilt.
Definition: LogicHandler.h:1137
unsigned long getNumberOfParticlesHalo() const
Get the number of halo particles.
Definition: LogicHandler.h:543
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:383
bool checkTuningStates(const InteractionTypeOption &interactionType)
Check if other autotuners for any other interaction types are still in a tuning phase.
Definition: LogicHandler.h:550
void checkNeighborListsInvalidDoDynamicRebuild()
Checks if any particle has moved more than skin/2.
Definition: LogicHandler.h:1156
Iterator::ParticleVecType gatherAdditionalVectors(IteratorBehavior behavior)
Create the additional vectors vector for a given iterator behavior.
Definition: LogicHandler.h:443
void addHaloParticle(const Particle_T &haloParticle)
Adds a particle to the container that lies in the halo region of the container.
Definition: LogicHandler.h:336
void deleteAllParticles()
Deletes all particles.
Definition: LogicHandler.h:367
std::tuple< std::optional< std::unique_ptr< TraversalInterface > >, bool > isConfigurationApplicable(const Configuration &conf, Functor &functor, const InteractionTypeOption &interactionType)
Checks if the given configuration can be used with the given functor and the current state of the sim...
Definition: LogicHandler.h:1977
bool getNeighborListsInvalidDoDynamicRebuild()
getter function for _neighborListInvalidDoDynamicRebuild
Definition: LogicHandler.h:1132
void resetNeighborListsInvalidDoDynamicRebuild()
Checks if any particle has moved more than skin/2.
Definition: LogicHandler.h:1175
double getMeanRebuildFrequency(bool considerOnlyLastNonTuningPhase=false) const
Getter for the mean rebuild frequency.
Definition: LogicHandler.h:610
autopas::ParticleContainerInterface< Particle_T > & getContainer()
Returns a non-const reference to the currently selected particle container.
Definition: LogicHandler.h:99
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:206
void reserve(size_t numParticles)
Estimates number of halo particles via autopas::utils::NumParticlesEstimator::estimateNumHalosUniform...
Definition: LogicHandler.h:280
autopas::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:490
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
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
std::pair< double, double > calculateHomogeneityAndMaxDensity(const ParticleContainerInterface< Particle > &container)
Calculates homogeneity and max density of given AutoPas container.
Definition: SimilarityFunctions.h:47
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
decltype(auto) withStaticContainerType(autopas::ParticleContainerInterface< Particle_T > &container, FunctionType &&function)
Will execute the passed function body with the static container type of container.
Definition: StaticContainerSelector.h:33
@ 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...
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