19#include "autopas/Version.h"
34template <
class Particle_T>
39template <
class Particle_T>
44template <
class Particle_T>
47template <
class Particle_T>
49 _tuningManager = std::move(other._tuningManager);
50 _logicHandler = std::move(other._logicHandler);
54template <
class Particle_T>
59 AutoPasLog(INFO,
"AutoPas Version: {}", AutoPas_VERSION);
66 _externalMPICommunicator =
true;
68 if (std::find(_tuningStrategyOptions.begin(), _tuningStrategyOptions.end(),
69 TuningStrategyOption::mpiDivideAndConquer) != _tuningStrategyOptions.end()) {
70 _tuningStrategyFactoryInfo.mpiDivideAndConquer =
true;
77 const auto interactionLength = _logicHandlerInfo.cutoff * _logicHandlerInfo.verletSkin;
78 const auto boxLengthX = _logicHandlerInfo.boxMax[0] - _logicHandlerInfo.boxMin[0];
82 return {_allowedCellSizeFactors->getAll()};
86 _tuningManager = std::make_shared<TuningManager>(_autoTunerInfo);
88 for (
const auto &interactionType : _allowedInteractionTypeOptions) {
90 _allowedContainers, _allowedTraversals[interactionType], _allowedLoadEstimators,
91 _allowedDataLayouts[interactionType], _allowedNewton3Options[interactionType], &cellSizeFactors,
92 _allowedVecPatternsOptions[interactionType], interactionType);
95 tuningStrategies.reserve(_tuningStrategyOptions.size());
96 for (
const auto &strategy : _tuningStrategyOptions) {
97 tuningStrategies.emplace_back(TuningStrategyFactory::generateTuningStrategy(
98 searchSpace, strategy, _tuningStrategyFactoryInfo, interactionType, _outputSuffix));
100 if (_useTuningStrategyLoggerProxy) {
101 tuningStrategies.emplace_back(std::make_unique<TuningStrategyLogger>(_outputSuffix));
103 auto tunerOutputSuffix = _outputSuffix +
"_" + interactionType.to_string();
104 _tuningManager->addAutoTuner(std::make_unique<AutoTuner>(tuningStrategies, searchSpace, _autoTunerInfo,
105 _verletRebuildFrequency, tunerOutputSuffix),
110 _logicHandler = std::make_unique<std::remove_reference_t<
decltype(*_logicHandler)>>(
111 _tuningManager, _logicHandlerInfo, _verletRebuildFrequency, _outputSuffix);
114template <
class Particle_T>
115template <
class Functor>
118 not std::is_same_v<Functor, autopas::Functor<Particle_T, Functor>>,
119 "The static type of Functor in computeInteractions is not allowed to be autopas::Functor. Please use the "
120 "derived type instead, e.g. by using a dynamic_cast.");
121 if (f->
getCutoff() > this->getCutoff()) {
127 return _logicHandler->template computeInteractionsPipeline<Functor>(f, InteractionTypeOption::pairwise);
129 return _logicHandler->template computeInteractionsPipeline<Functor>(f, InteractionTypeOption::triwise);
132 "Functor is not valid. Only pairwise and triwise functors are supported. Please use a functor derived from "
133 "PairwiseFunctor or TriwiseFunctor.");
138template <
class Particle_T>
140 size_t numParticles{0};
141 if (behavior & IteratorBehavior::owned) {
142 numParticles += _logicHandler->getNumberOfParticlesOwned();
144 if (behavior & IteratorBehavior::halo) {
145 numParticles += _logicHandler->getNumberOfParticlesHalo();
148 if (behavior & ~(IteratorBehavior::ownedOrHalo)) {
150 "AutoPas::getNumberOfParticles() does not support iterator behaviors other than owned or halo.");
156template <
class Particle_T>
158 _logicHandler->reserve(numParticles);
161template <
class Particle_T>
163 _logicHandler->reserve(numParticles, numHaloParticles);
166template <
class Particle_T>
170 reserve(getNumberOfParticles(IteratorBehavior::owned) + numParticlesToAdd,
171 getNumberOfParticles(IteratorBehavior::halo) + numHalosToAdd);
172 AUTOPAS_OPENMP(parallel
for schedule(
static, std::max(1ul, collectionSize / omp_get_max_threads())))
173 for (auto i = 0; i < collectionSize; ++i) {
178template <
class Particle_T>
180 _logicHandler->addParticle(p);
183template <
class Particle_T>
184template <
class Collection>
186 addParticlesAux(particles.size(), 0, particles.size(), [&](
auto i) { addParticle(particles[i]); });
189template <
class Particle_T>
190template <
class Collection,
class F>
192 std::vector<char> predicateMask(particles.size());
195 for (
auto i = 0; i < particles.size(); ++i) {
196 if (predicate(particles[i])) {
197 predicateMask[i] =
static_cast<char>(
true);
200 predicateMask[i] =
static_cast<char>(
false);
204 addParticlesAux(numTrue, 0, particles.size(), [&](
auto i) {
205 if (predicateMask[i]) {
206 addParticle(particles[i]);
211template <
class Particle_T>
216template <
class Particle_T>
218 const std::array<double, 3> &boxMax) {
219 if (_allowedCellSizeFactors->isInterval()) {
221 "The allowed Cell Size Factors are a continuous interval but internally only those values that "
222 "yield unique numbers of cells are used. Resizing does not cause these values to be recalculated so "
223 "the same configurations might now yield different and non-unique numbers of cells!");
225 _logicHandlerInfo.boxMin = boxMin;
226 _logicHandlerInfo.boxMax = boxMax;
227 return _logicHandler->resizeBox(boxMin, boxMax);
230template <
class Particle_T>
235template <
class Particle_T>
240template <
class Particle_T>
241template <
class Collection>
243 addParticlesAux(0, particles.size(), particles.size(), [&](
auto i) { addHaloParticle(particles[i]); });
246template <
class Particle_T>
247template <
class Collection,
class F>
249 std::vector<char> predicateMask(particles.size());
252 for (
auto i = 0; i < particles.size(); ++i) {
253 if (predicate(particles[i])) {
254 predicateMask[i] =
static_cast<char>(
true);
257 predicateMask[i] =
static_cast<char>(
false);
261 addParticlesAux(0, numTrue, particles.size(), [&](
auto i) {
262 if (predicateMask[i]) {
263 addHaloParticle(particles[i]);
268template <
class Particle_T>
273template <
class Particle_T>
275 _logicHandler->decreaseParticleCounter(*iter);
276 internal::deleteParticle(iter);
279template <
class Particle_T>
281 _logicHandler->decreaseParticleCounter(*iter);
282 internal::deleteParticle(iter);
285template <
class Particle_T>
287 _logicHandler->decreaseParticleCounter(particle);
289 auto [particleDeleted, refStillValid] = _logicHandler->deleteParticleFromBuffers(particle);
290 if (not particleDeleted) {
291 refStillValid = _logicHandler->getContainer().deleteParticle(particle);
293 return refStillValid;
296template <
class Particle_T>
298 return _logicHandler->
begin(behavior);
301template <
class Particle_T>
303 return std::as_const(*_logicHandler).
begin(behavior);
306template <
class Particle_T>
308 const std::array<double, 3> &lowerCorner,
const std::array<double, 3> &higherCorner, IteratorBehavior behavior) {
312template <
class Particle_T>
314 const std::array<double, 3> &lowerCorner,
const std::array<double, 3> &higherCorner,
315 IteratorBehavior behavior)
const {
316 return std::as_const(*_logicHandler).
getRegionIterator(lowerCorner, higherCorner, behavior);
319template <
class Particle_T>
321 return _logicHandler->getContainer().getContainerType();
324template <
class Particle_T>
326 return _logicHandler->getContainer().getBoxMin();
329template <
class Particle_T>
331 return _logicHandler->getContainer().getBoxMax();
334template <
class Particle_T>
336 return _logicHandler->getContainer();
339template <
class Particle_T>
341 return _logicHandler->getContainer();
344template <
class Particle_T>
346 return _tuningManager->allSearchSpacesAreTrivial();
#define AutoPasLog(lvl, fmt,...)
Macro for logging providing common meta information without filename.
Definition: Logger.h:24
#define AUTOPAS_MPI_COMM_NULL
Wrapper for MPI_COMM_NULL.
Definition: WrapMPI.h:118
#define AUTOPAS_MPI_COMM_WORLD
Wrapper for MPI_COMM_WORLD.
Definition: WrapMPI.h:120
#define AUTOPAS_OPENMP(args)
Empty macro to throw away any arguments.
Definition: WrapOpenMP.h:126
The AutoPas class is intended to be the main point of Interaction for the user.
Definition: AutoPasDecl.h:47
std::vector< Particle_T > updateContainer()
Updates the container.
Definition: AutoPasImpl.h:212
void reserve(size_t numParticles)
Reserve memory for a given number of particles in the container and logic layers.
Definition: AutoPasImpl.h:157
void addParticles(Collection &&particles)
Adds all particles from the collection to the container.
Definition: AutoPasImpl.h:185
void addParticlesIf(Collection &&particles, F predicate)
Adds all particles for which predicate(particle) == true to the container.
Definition: AutoPasImpl.h:191
void addHaloParticle(const Particle_T &haloParticle)
Adds a particle to the container that lies in the halo region of the container.
Definition: AutoPasImpl.h:236
AutoPas(std::ostream &logOutputStream=std::cout)
Constructor for the AutoPas class.
Definition: AutoPasImpl.h:35
RegionIteratorT getRegionIterator(const std::array< double, 3 > &lowerCorner, const std::array< double, 3 > &higherCorner, IteratorBehavior behavior=IteratorBehavior::ownedOrHalo)
Iterate over all particles in a specified region.
Definition: AutoPasImpl.h:307
AutoPas & operator=(AutoPas &&other) noexcept
Move assignment operator.
Definition: AutoPasImpl.h:48
void init()
Initialize AutoPas.
Definition: AutoPasImpl.h:55
void forceRetune()
Force the internal tuner to enter a new tuning phase upon the next call to computeInteractions().
Definition: AutoPasImpl.h:231
size_t getNumberOfParticles(IteratorBehavior behavior=IteratorBehavior::owned) const
Returns the number of particles in this container.
Definition: AutoPasImpl.h:139
void deleteAllParticles()
Deletes all particles.
Definition: AutoPasImpl.h:269
bool computeInteractions(Functor *f)
Function to iterate over all inter-particle interactions in the container This function only handles ...
Definition: AutoPasImpl.h:116
void addParticle(const Particle_T &p)
Adds a particle to the container.
Definition: AutoPasImpl.h:179
IteratorT begin(IteratorBehavior behavior=IteratorBehavior::ownedOrHalo)
Iterate over all particles by using for(auto iter = autoPas.begin(); iter.isValid(); ++iter)
Definition: AutoPasImpl.h:297
std::vector< std::unique_ptr< TuningStrategyInterface > > TuningStrategiesListType
Type for the member holding all tuning strategies.
Definition: AutoTuner.h:45
Public iterator class that iterates over a particle container and additional vectors (which are typic...
Definition: ContainerIterator.h:95
Functor base class.
Definition: Functor.h:41
double getCutoff() const
Getter for the functor's cutoff.
Definition: Functor.h:191
static void create(std::ostream &logOutputStream=std::cout)
Explicitly initialize/reset the logger to write to an output stream.
Definition: Logger.h:68
Class describing an interval.
Definition: NumberInterval.h:15
Class describing a finite set of numbers.
Definition: NumberSetFinite.h:19
The ParticleContainerInterface class provides a basic interface for all Containers within AutoPas.
Definition: ParticleContainerInterface.h:38
static void exception(const Exception e)
Handle an exception derived by std::exception.
Definition: ExceptionHandler.h:64
std::set< double > calculateRelevantCsfs(const NumberInterval< double > &numberInterval, double interactionLength, double domainLengthX)
For a given domain parametrization, calculate which cell size factors (csf) in an interval actually a...
Definition: SearchSpaceGenerators.cpp:84
std::set< Configuration > cartesianProduct(const std::set< ContainerOption > &allowedContainerOptions, const std::set< TraversalOption > &allowedTraversalOptions, const std::set< LoadEstimatorOption > &allowedLoadEstimatorOptions, const std::set< DataLayoutOption > &allowedDataLayoutOptions, const std::set< Newton3Option > &allowedNewton3Options, const NumberSet< double > *allowedCellSizeFactors, const std::set< VectorizationPatternOption > &allowedVecPatternOptions, const InteractionTypeOption &interactionType)
Fills the search space with the cartesian product of the given options (minus invalid combinations).
Definition: SearchSpaceGenerators.cpp:18
std::string getCompilerInfo()
Get name and version number of a list of known compilers.
Definition: CompileInfo.cpp:9
decltype(isTriwiseFunctorImpl(std::declval< FunctorT >())) isTriwiseFunctor
Check whether a Functor Type is inheriting from TriwiseFunctor.
Definition: checkFunctorType.h:56
decltype(isPairwiseFunctorImpl(std::declval< FunctorT >())) isPairwiseFunctor
Check whether a Functor Type is inheriting from PairwiseFunctor.
Definition: checkFunctorType.h:49
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:34
int AutoPas_MPI_Comm_dup(AutoPas_MPI_Comm comm, AutoPas_MPI_Comm *newComm)
Wrapper for MPI_Comm_dup.
Definition: WrapMPI.h:815
int AutoPas_MPI_Comm_rank(AutoPas_MPI_Comm comm, int *rank)
Wrapper for MPI_Comm_rank.
Definition: WrapMPI.h:807