41 DataLayoutOption, Newton3Option>;
80 template <
class Particle_T,
class PairwiseFunctor>
82 unsigned int rebuildFrequency) {
83 using namespace autopas::utils::ArrayMath::literals;
88 const auto &boxMin = container.
getBoxMin();
89 const auto &boxMax = container.
getBoxMax();
90 const auto cutoff = container.
getCutoff();
91 const auto cutoffInv = 1.0 / cutoff;
94 infos[
"numParticles"] = numParticles;
95 infos[
"cutoff"] = cutoff;
97 infos[
"rebuildFrequency"] =
static_cast<size_t>(rebuildFrequency);
98 const auto domainSize = boxMax - boxMin;
100 infos[
"domainSizeX"] = domainSize[0];
101 infos[
"domainSizeY"] = domainSize[1];
102 infos[
"domainSizeZ"] = domainSize[2];
104 infos[
"particleSize"] =
sizeof(Particle_T);
107 const auto cellsPerDim = ceilToInt(domainSize * cutoffInv);
108 const auto numCells =
static_cast<size_t>(cellsPerDim[0] * cellsPerDim[1] * cellsPerDim[2]);
109 infos[
"numCells"] = numCells;
112 std::vector<size_t> particleBins;
114 particleBins.resize(numCells + 1);
116 std::vector<size_t> particleBinsBlurred;
117 particleBinsBlurred.resize(27);
118 const auto blurredCellDimsReciproc = std::array<double, 3>{3.0, 3.0, 3.0} / domainSize;
119 for (
const Particle_T &particle : container) {
122 const auto offsetIntoBox = particle.getR() - boxMin;
123 const auto cell = floorToInt(offsetIntoBox * cutoffInv);
124 const auto binIndex = (cell[2] * cellsPerDim[1] + cell[1]) * cellsPerDim[0] + cell[0];
125 particleBins[binIndex]++;
128 const auto cellBlurred = floorToInt(offsetIntoBox * blurredCellDimsReciproc);
129 const auto binIndexBlurred = (cellBlurred[2] * 3 + cellBlurred[1]) * 3 + cellBlurred[0];
130 particleBinsBlurred[binIndexBlurred]++;
133 particleBins.back()++;
137 infos[
"numHaloParticles"] = particleBins.back();
140 const auto avgParticlesPerCell = numParticles == 0
143 static_cast<double>(numCells);
144 const auto avgParticlesPerBlurredCell =
145 numParticles == 0 ? 0.
147 static_cast<double>(particleBinsBlurred.size());
149 const auto [estimatedNumNeighborInteractions, maxDiff, sumStddev, numEmptyCells, maxParticlesPerCell,
150 minParticlesPerCell] = [&]() {
151 double estimatedNumNeighborInteractionsLambda = 0.;
152 double maxDiffLambda = 0.;
153 double sumStddevLambda = 0.;
154 size_t numEmptyCellsLambda = 0;
155 size_t maxParticlesPerCellLambda = std::numeric_limits<size_t>::min();
156 size_t minParticlesPerCellLambda = std::numeric_limits<size_t>::max();
158 for (
size_t i = 0; i < particleBins.size() - 1; i++) {
159 const auto particlesInBin = particleBins[i];
160 if (particlesInBin == 0) {
161 ++numEmptyCellsLambda;
163 const auto estimatedNumParticlesInVicinity = particlesInBin * (particlesInBin * 27 - 1);
165 constexpr double probabilityParticleWithinCutoff = 0.155;
166 estimatedNumNeighborInteractionsLambda += estimatedNumParticlesInVicinity * probabilityParticleWithinCutoff;
168 maxParticlesPerCellLambda = std::max(particlesInBin, maxParticlesPerCellLambda);
169 minParticlesPerCellLambda = std::min(particlesInBin, minParticlesPerCellLambda);
170 const auto diffFromAvg = avgParticlesPerCell -
static_cast<int>(particlesInBin);
171 maxDiffLambda = std::max(diffFromAvg, maxDiffLambda);
172 sumStddevLambda += diffFromAvg * diffFromAvg;
174 estimatedNumNeighborInteractionsLambda /= 2;
176 return std::tuple{estimatedNumNeighborInteractionsLambda,
180 maxParticlesPerCellLambda,
181 minParticlesPerCellLambda};
184 infos[
"numEmptyCells"] = numEmptyCells;
185 infos[
"maxParticlesPerCell"] = maxParticlesPerCell;
186 infos[
"minParticlesPerCell"] = minParticlesPerCell;
187 infos[
"particlesPerCellStdDev"] =
188 numParticles == 0 ? 0.
189 : std::sqrt(sumStddev) /
static_cast<double>(particleBins.size() - 1) / avgParticlesPerCell;
190 infos[
"avgParticlesPerCell"] = avgParticlesPerCell;
194 infos[
"homogeneity"] = homogeneity;
195 infos[
"maxDensity"] = maxDensity;
197 infos[
"estimatedNumNeighborInteractions"] =
static_cast<unsigned long>(estimatedNumNeighborInteractions);
199 const double sumStddevBlurred = [&]() {
201 for (
auto numParticlesInBin : particleBinsBlurred) {
202 auto diff = avgParticlesPerBlurredCell -
static_cast<int>(numParticlesInBin);
207 infos[
"particlesPerBlurredCellStdDev"] = numParticles == 0 ? 0.
208 : std::sqrt(sumStddevBlurred) /
209 static_cast<double>(particleBinsBlurred.size()) /
210 avgParticlesPerBlurredCell;
214 constexpr size_t particleSizeNeededByFunctor = calculateParticleSizeNeededByFunctor<Particle_T, PairwiseFunctor>(
216 infos[
"particleSizeNeededByFunctor"] = particleSizeNeededByFunctor;
223 [[nodiscard]]
const auto &
get()
const {
return infos; }
230 auto typeToString = [](
auto type) {
231 if constexpr (std::is_same_v<
decltype(type),
bool> or std::is_same_v<
decltype(type),
double> or
232 std::is_same_v<
decltype(type),
size_t>) {
233 return std::to_string(type);
234 }
else if constexpr (std::is_base_of_v<Option<
decltype(type)>,
decltype(type)>) {
235 return type.to_string();
237 return std::string{
"fail"};
239 auto pairToString = [&](
const auto &pair) {
return pair.first +
"=" + std::visit(typeToString, pair.second); };
240 std::string res{
"Live Info: "};
241 if (not infos.empty()) {
243 res += std::accumulate(std::next(infos.begin()), infos.end(), pairToString(*infos.begin()),
244 [&](std::string s,
const auto &elem) { return std::move(s) +
" " + pairToString(elem); });
256 out << info.infos.size() <<
' ';
257 for (
const auto &[name, val] : info.infos) {
260 out << name <<
' ' << val.index() <<
' ';
261 std::visit([&](
const auto &v) { out << v <<
' '; }, val);
273 size_t numElements{0};
275 for (
size_t i = 0; i < numElements; i++) {
281 readIndex<LiveInfo::InfoType>(in, idx, std::make_index_sequence<std::variant_size_v<LiveInfo::InfoType>>());
282 info.infos[name] = val;
292 [[nodiscard]] std::pair<std::string, std::string>
getCSVLine()
const {
295 const auto keyRegex = std::regex(
"([^= ]+)=[^ ]*");
297 const auto valueRegex = std::regex(
"=([^ ]+)");
301 searchString = searchString.substr(std::string(
"Live Info: ").size());
303 std::sregex_iterator keyIter(searchString.begin(), searchString.end(), keyRegex);
304 std::sregex_iterator valueIter(searchString.begin(), searchString.end(), valueRegex);
305 std::sregex_iterator end;
307 std::stringstream header;
308 std::stringstream line;
310 while (keyIter != end) {
312 header << keyIter->str(1) <<
",";
315 while (valueIter != end) {
317 line << valueIter->str(1) <<
",";
321 auto headerStr = header.str();
322 auto lineStr = line.str();
324 headerStr.pop_back();
327 return std::make_pair(headerStr, lineStr);
340 constexpr static auto calculateParticleSizeNeededByFunctor(std::index_sequence<Idx...>) {
343 typename Particle_T::SoAArraysType>::type::value_type));
356 template <
class Variant,
class Type,
size_t Idx>
357 static void readIndexHelper(std::istream &in,
size_t idx, Variant &var) {
373 template <
class Variant,
size_t... Idx>
374 static Variant readIndex(std::istream &in,
size_t idx, std::index_sequence<Idx...>) {
376 (readIndexHelper<Variant, std::variant_alternative_t<Idx, Variant>, Idx>(in, idx, var), ...);
383 std::map<std::string, InfoType> infos;
static constexpr std::array< typename Particle_T::AttributeNames, 0 > getNeededAttr()
Get attributes needed for computation.
Definition: Functor.h:77
This class is able to gather and store important information for a tuning phase from a container and ...
Definition: LiveInfo.h:31
std::string toString() const
Creates a string containing all live info gathered.
Definition: LiveInfo.h:229
std::pair< std::string, std::string > getCSVLine() const
Generate a csv representation containing all values from the toString() method.
Definition: LiveInfo.h:292
friend std::istream & operator>>(std::istream &in, LiveInfo &info)
Stream operator to read the LiveInfo in from a stream.
Definition: LiveInfo.h:272
void gather(const autopas::ParticleContainerInterface< Particle_T > &container, const PairwiseFunctor &functor, unsigned int rebuildFrequency)
Gathers important information from a particle container and functor.
Definition: LiveInfo.h:81
friend std::ostream & operator<<(std::ostream &out, const LiveInfo &info)
Stream operator to write the LiveInfo to a stream.
Definition: LiveInfo.h:255
std::variant< bool, double, size_t, ContainerOption, TraversalOption, LoadEstimatorOption, DataLayoutOption, Newton3Option > InfoType
The type of an info.
Definition: LiveInfo.h:41
const auto & get() const
Returns a map of all infos.
Definition: LiveInfo.h:223
Class representing the load estimator choices.
Definition: LoadEstimatorOption.h:18
PairwiseFunctor class.
Definition: PairwiseFunctor.h:31
The ParticleContainerInterface class provides a basic interface for all Containers within AutoPas.
Definition: ParticleContainerInterface.h:37
virtual const std::array< double, 3 > & getBoxMin() const =0
Get the lower corner of the container without halo.
virtual double getCutoff() const =0
Return the cutoff of the container.
virtual const std::array< double, 3 > & getBoxMax() const =0
Get the upper corner of the container without halo.
virtual double getVerletSkin() const =0
Return the verletSkin of the container verletSkin.
virtual size_t getNumberOfParticles(IteratorBehavior behavior=IteratorBehavior::owned) const =0
Get the number of particles with respect to the specified IteratorBehavior.
constexpr std::array< int, SIZE > floorToInt(const std::array< T, SIZE > &a)
Floors all array elements and converts them to integers.
Definition: ArrayMath.h:332
constexpr std::array< int, SIZE > ceilToInt(const std::array< T, SIZE > &a)
Ceils all array elements and converts them to integers.
Definition: ArrayMath.h:348
std::pair< double, double > calculateHomogeneityAndMaxDensity(const ParticleContainerInterface< Particle > &container)
Calculates homogeneity and max density of given AutoPas container.
Definition: SimilarityFunctions.h:47
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
Type
Enum describing all types that are allowed in a rule program.
Definition: RuleBasedProgramTree.h:10