Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to AutoPas 2.0.0 #2

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ Thumbs.db

#cmake
/build*
/cmake-build*
/CMakeCache.txt
/CMakeFiles/
/Makefile
Expand Down
9 changes: 8 additions & 1 deletion cmake/Modules/Packages/USER-AUTOPAS.cmake
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
option(PKG_USER-AUTOPAS "Enable AutoPas support" ON)

if (PKG_USER-AUTOPAS)

if (CMAKE_VERSION VERSION_LESS "3.16")
Expand All @@ -19,11 +21,14 @@ if (PKG_USER-AUTOPAS)
set(autopasRepoPath [email protected]:AutoPas/AutoPas.git)
endif ()

# Final version of 2 Body AutoPas
set(AUTOPAS_TAG v2.0.0 CACHE STRING "AutoPas Git tag or commit id to use")

# Download and install autopas
FetchContent_Declare(
autopas
GIT_REPOSITORY ${autopasRepoPath}
GIT_TAG cacb3fa0e14b28bb8b50f10ec7fe16628bbb2582
GIT_TAG ${AUTOPAS_TAG}
)

option(AUTOPAS_BUILD_TESTS "" OFF)
Expand All @@ -43,6 +48,8 @@ if (PKG_USER-AUTOPAS)
FetchContent_MakeAvailable(autopas)

list(APPEND LAMMPS_LINK_LIBS "autopas")
# Link detached library which contains the particle properties library
list(APPEND LAMMPS_LINK_LIBS "molecularDynamicsLibrary")


######### 2. AutoPas package settings #########
Expand Down
2 changes: 1 addition & 1 deletion src/USER-AUTOPAS/atom_vec_atomic_autopas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -449,7 +449,7 @@ AtomVecAtomicAutopas::data_atom(double *coord, imageint imagetmp,
void AtomVecAtomicAutopas::pack_data(double **buf) {

#pragma omp parallel default(none) shared(buf)
for (auto iter = lmp->autopas->const_iterate<autopas::IteratorBehavior::ownedOnly>(); iter.isValid(); ++iter) {
for (auto iter = lmp->autopas->const_iterate<autopas::IteratorBehavior::owned>(); iter.isValid(); ++iter) {
auto &x_{iter->getR()};
auto idx{iter->getLocalID()};
buf[idx][0] = ubuf(tag[idx]).d;
Expand Down
104 changes: 48 additions & 56 deletions src/USER-AUTOPAS/autopas.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,27 +19,17 @@ AutoPasLMP::AutoPasLMP(class LAMMPS *lmp, int narg, char **argc)
: Pointers(lmp) {
lmp->autopas = this;

// TODO Check again with new Autopas version
// Remove additional traversals from the defaults provided by AutoPas
_opt.allowed_traversals.erase(
autopas::TraversalOption::vcl_cluster_iteration); // Wrong results
_opt.allowed_traversals.erase(
autopas::TraversalOption::vcl_c06); // Wrong results
_opt.allowed_traversals.erase(
autopas::TraversalOption::vcl_c01_balanced); // Wrong results
_opt.allowed_traversals.erase(
autopas::TraversalOption::vcc_cluster_iteration_cuda); // Vector out of
// range exception

// Command line parsing
std::vector<std::string> args(argc, argc + narg);

// Convert arguments all to lowercase
std::transform(args.begin(), args.end(), args.begin(), [](auto s) {
std::transform(s.begin(), s.end(), s.begin(), ::tolower);
return s;
});

int iarg = 0;
while (iarg < narg) {
if (args[iarg] == "log") {
Expand Down Expand Up @@ -92,13 +82,15 @@ AutoPasLMP::AutoPasLMP(class LAMMPS *lmp, int narg, char **argc)
error->all(FLERR, "Invalid AutoPas command-line arg: interval");
_opt.tuning_interval = std::stoi(args[iarg + 1]);
iarg += 2;
} else if (args[iarg] == "s" || args[iarg] == "strategy") {
} else if (args[iarg] == "s" || args[iarg] == "strategies") {
if (iarg + 2 > narg)
error->all(FLERR, "Invalid AutoPas command-line arg: strategy");
auto opts = autopas::TuningStrategyOption::parseOptions(args[iarg + 1]);
if (opts.size() != 1)
error->all(FLERR, "Invalid AutoPas command-line arg: strategy");
_opt.tuning_strategy = *opts.begin();
error->all(FLERR, "Invalid AutoPas command-line arg: strategies");
_opt.tuning_strategies = autopas::TuningStrategyOption::parseOptions<std::vector<autopas::TuningStrategyOption>>(args[iarg + 1]);
iarg += 2;
} else if (args[iarg] == "f" || args[iarg] == "rule_file") {
if (iarg + 2 > narg)
error->all(FLERR, "Invalid AutoPas command-line arg: rule_file");
_opt.rule_filename = args[iarg + 1];
iarg += 2;
} else if (args[iarg] == "selector") {
if (iarg + 2 > narg)
Expand Down Expand Up @@ -204,9 +196,9 @@ void AutoPasLMP::init_autopas(double cutoff, double **epsilon, double **sigma) {

_autopas->setAllowedCellSizeFactors(*_opt.allowed_cell_size_factors);

_autopas->setVerletSkin(neighbor->skin);
_autopas->setVerletRebuildFrequency(
std::max(neighbor->every, neighbor->delay));
_autopas->setVerletSkinPerTimestep(neighbor->skin / _autopas->getVerletRebuildFrequency());
_autopas->setVerletClusterSize(_opt.verlet_cluster_size);

_autopas->setTuningInterval(_opt.tuning_interval);
Expand All @@ -226,13 +218,14 @@ void AutoPasLMP::init_autopas(double cutoff, double **epsilon, double **sigma) {
_autopas->setAllowedTraversals(_opt.allowed_traversals);
_autopas->setAllowedDataLayouts(_opt.allowed_data_layouts);

_autopas->setRuleFileName(_opt.rule_filename);
// TODO AutoPas always calculates FullShell.
// Turn LAMMPS newton setting off to disable force exchange?
// Or just leave reverse_comm empty? What about other forces?
force->newton = force->newton_pair = force->newton_bond = false;
_autopas->setAllowedNewton3Options(_opt.allowed_newton3);

_autopas->setTuningStrategyOption(_opt.tuning_strategy);
_autopas->setTuningStrategyOption(_opt.tuning_strategies);

autopas::Logger::create();
autopas::Logger::get()->set_level(_opt.log_level);
Expand Down Expand Up @@ -282,8 +275,6 @@ void AutoPasLMP::print_config(double *const *epsilon,

if (_opt.allowed_traversals.count(
autopas::TraversalOption::vcl_cluster_iteration) ||
_opt.allowed_traversals.count(
autopas::TraversalOption::vcc_cluster_iteration_cuda) ||
_opt.allowed_traversals.count(autopas::TraversalOption::vcl_c06) ||
_opt.allowed_traversals.count(
autopas::TraversalOption::vcl_c01_balanced)) {
Expand All @@ -295,22 +286,23 @@ void AutoPasLMP::print_config(double *const *epsilon,
printVal("Num Samples", std::set{_opt.num_samples});
printVal("Max Evidence", std::set{_opt.max_evidence});

printOpt("Tuning Strategy", std::set{_opt.tuning_strategy},
printOpt("Tuning Strategies", _opt.tuning_strategies,
autopas::TuningStrategyOption::getOptionNames());
printOpt("Selector Strategy", std::set{_opt.selector_strategy},
autopas::SelectorStrategyOption::getOptionNames());

if (_opt.tuning_strategy == autopas::TuningStrategyOption::bayesianSearch ||
_opt.tuning_strategy ==
autopas::TuningStrategyOption::bayesianClusterSearch) {
printOpt("Acquisition Function", std::set{_opt.acquisition_function},
autopas::AcquisitionFunctionOption::getOptionNames());
} else if (_opt.tuning_strategy ==
autopas::TuningStrategyOption::predictiveTuning) {
printVal("Relative Optimum Range",
std::set{_opt.predictive_tuning.relative_optimum_range});
printVal("Max Tuning Phases Without Test",
std::set{_opt.predictive_tuning.max_tuning_phases_without_test});
for (const auto &strategy : _opt.tuning_strategies) {
if (strategy == autopas::TuningStrategyOption::bayesianSearch ||
strategy == autopas::TuningStrategyOption::bayesianClusterSearch) {
printOpt("Acquisition Function", std::set{_opt.acquisition_function},
autopas::AcquisitionFunctionOption::getOptionNames());
} else if (strategy ==
autopas::TuningStrategyOption::predictiveTuning) {
printVal("Relative Optimum Range",
std::set{_opt.predictive_tuning.relative_optimum_range});
printVal("Max Tuning Phases Without Test",
std::set{_opt.predictive_tuning.max_tuning_phases_without_test});
}
}

if (_opt.allowed_traversals.count(
Expand Down Expand Up @@ -343,12 +335,12 @@ void AutoPasLMP::print_config(double *const *epsilon,
}

// dummy because LAMMPS starts with typeID 1 and autopas with 0
_particlePropertiesLibrary->addType(0, 1, 1, 1);
_particlePropertiesLibrary->addSiteType(0, 1, 1, 1);
std::cout << " Particle Properties\n";
for (int i = 1; i <= atom->ntypes; ++i) {
std::cout << " Type, Eps, Sig: " << i << " " << epsilon[i][i] << " "
<< sigma[i][i] << "\n";
_particlePropertiesLibrary->addType(i, epsilon[i][i], sigma[i][i],
_particlePropertiesLibrary->addSiteType(i, epsilon[i][i], sigma[i][i],
atom->mass[i]);
}
_particlePropertiesLibrary->calculateMixingCoefficients();
Expand All @@ -367,15 +359,15 @@ AutoPasLMP::ParticleType *AutoPasLMP::particle_by_index(int idx) {
}
}

bool AutoPasLMP::update_autopas(bool must_rebuild) {
auto &&[invalidParticles, updated] = _autopas->updateContainer(must_rebuild);

if (updated) {
bool AutoPasLMP::update_autopas() {
auto invalidParticles = _autopas->updateContainer();
if (!invalidParticles.empty()) {
_leavingParticles = std::move(invalidParticles);
_index_structure_valid = false;
return true;
}

return updated;
return false;
}

void AutoPasLMP::move_into() {
Expand Down Expand Up @@ -412,7 +404,7 @@ void AutoPasLMP::copy_back() const {
atom->f = memory->grow(atom->f, nmax, 3, "atom:f");

#pragma omp parallel default(none)
for (auto iter = const_iterate<autopas::ownedOnly>(); iter.isValid();
for (auto iter = const_iterate<autopas::IteratorBehavior::owned>(); iter.isValid();
++iter) {
auto &p = *iter;
auto idx{iter->getLocalID()};
Expand All @@ -430,7 +422,7 @@ void AutoPasLMP::copy_back() const {
}

void AutoPasLMP::update_index_structure() {
auto n = _autopas->getNumberOfParticles(autopas::haloAndOwned);
auto n = _autopas->getNumberOfParticles(autopas::IteratorBehavior::ownedOrHalo);
if (_use_index_map) {
_index_map.clear();
_index_map.reserve(n);
Expand Down Expand Up @@ -460,7 +452,7 @@ template <bool halo> void AutoPasLMP::add_particle(const ParticleType &p) {
assert(p.getTypeId() <= atom->ntypes);

if constexpr (halo) {
_autopas->addOrUpdateHaloParticle(p);
_autopas->addHaloParticle(p);
} else {
_autopas->addParticle(p);
}
Expand All @@ -474,22 +466,22 @@ template <bool halo> void AutoPasLMP::add_particle(const ParticleType &p) {
#pragma clang diagnostic pop

template <bool haloOnly>
autopas::ParticleIteratorWrapper<AutoPasLMP::ParticleType, true>
AutoPasLMP::AutoPasType::RegionIteratorT
AutoPasLMP::particles_by_slab(int dim, double lo, double hi) const {

std::array<double, 3> low{};
std::array<double, 3> high{};

low.fill(-std::numeric_limits<double>::max());
low.fill(std::numeric_limits<double>::lowest());
high.fill(std::numeric_limits<double>::max());

low[dim] = lo;
high[dim] = hi;

if constexpr (haloOnly) {
return _autopas->getRegionIterator(low, high, autopas::haloOnly);
return _autopas->getRegionIterator(low, high, autopas::IteratorBehavior::halo);
} else {
return _autopas->getRegionIterator(low, high, autopas::haloAndOwned);
return _autopas->getRegionIterator(low, high, autopas::IteratorBehavior::ownedOrHalo);
}
}

Expand All @@ -513,27 +505,27 @@ bool AutoPasLMP::iterate_pairwise(AutoPasLMP::PairFunctorType *functor) {
return _autopas->iteratePairwise(functor);
}

AutoPasLMP::AutoPasType::const_iterator_t
AutoPasLMP::AutoPasType::ConstIteratorT
AutoPasLMP::const_iterate_auto(int first, int last) {
auto nlocal{atom->nlocal};
if (last < nlocal) {
return const_iterate<autopas::ownedOnly>();
return const_iterate<autopas::IteratorBehavior::owned>();
} else if (first >= nlocal) {
return const_iterate<autopas::haloOnly>();
return const_iterate<autopas::IteratorBehavior::halo>();
} else {
return const_iterate<autopas::haloAndOwned>();
return const_iterate<autopas::IteratorBehavior::ownedOrHalo>();
}
}

AutoPasLMP::AutoPasType::iterator_t AutoPasLMP::iterate_auto(int first,
AutoPasLMP::AutoPasType::IteratorT AutoPasLMP::iterate_auto(int first,
int last) {
auto nlocal{atom->nlocal};
if (last < nlocal) {
return iterate<autopas::ownedOnly>();
return iterate<autopas::IteratorBehavior::owned>();
} else if (first >= nlocal) {
return iterate<autopas::haloOnly>();
return iterate<autopas::IteratorBehavior::halo>();
} else {
return iterate<autopas::haloAndOwned>();
return iterate<autopas::IteratorBehavior::ownedOrHalo>();
}
}

Expand Down Expand Up @@ -585,8 +577,8 @@ template void AutoPasLMP::add_particle<false>(const ParticleType &p);

template void AutoPasLMP::add_particle<true>(const ParticleType &p);

template autopas::ParticleIteratorWrapper<AutoPasLMP::ParticleType, true>
template AutoPasLMP::AutoPasType::RegionIteratorT
AutoPasLMP::particles_by_slab<true>(int dim, double lo, double hi) const;

template autopas::ParticleIteratorWrapper<AutoPasLMP::ParticleType, true>
template AutoPasLMP::AutoPasType::RegionIteratorT
AutoPasLMP::particles_by_slab<false>(int dim, double lo, double hi) const;
28 changes: 13 additions & 15 deletions src/USER-AUTOPAS/autopas.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#include <autopas/AutoPas.h>
#include <autopas/cells/FullParticleCell.h>
#include <autopas/molecularDynamics/ParticlePropertiesLibrary.h>
#include <molecularDynamicsLibrary/ParticlePropertiesLibrary.h>

#include "autopas_lj_functor.h"
#include "autopas_lj_functor_avx.h"
Expand All @@ -24,9 +24,9 @@ class AutoPasLMP : protected Pointers {
using FloatVecType = std::array<FloatType, 3>;
using ParticleType = MoleculeLJLammps<FloatType>;
using ParticleCellType = autopas::FullParticleCell<ParticleType>;
using AutoPasType = autopas::AutoPas<ParticleType, ParticleCellType>;
using AutoPasType = autopas::AutoPas<ParticleType>;
using ParticlePropertiesLibraryType = ParticlePropertiesLibrary<FloatType, size_t>;
using PairFunctorType = LJFunctorAVXLammps<ParticleType, ParticleCellType, /*applyShift*/ false, /*useMixing*/ false, /*useNewton3*/ autopas::FunctorN3Modes::Both, /*calculateGlobals*/ true>;
using PairFunctorType = LJFunctorLammpsAVX<ParticleType, /*applyShift*/ false, /*useMixing*/ false, /*useNewton3*/ autopas::FunctorN3Modes::Both, /*calculateGlobals*/ true>;

/*
* Flag used to differentiate when LAMMPS is build with and without
Expand All @@ -49,10 +49,8 @@ class AutoPasLMP : protected Pointers {

/**
* Rebuild the AutoPas container and update the leaving particles with the ones returned by AutoPas.
* @param must_rebuild When false, let AutoPas decide if rebuild is necessary
* @return Was container rebuild?
*/
bool update_autopas(bool must_rebuild);
bool update_autopas();

/**
* Get a particle by its global index / particle ID.
Expand Down Expand Up @@ -97,16 +95,16 @@ class AutoPasLMP : protected Pointers {
* @return
*/
template<bool haloOnly = false>
[[nodiscard]] autopas::ParticleIteratorWrapper<ParticleType, true>
[[nodiscard]] AutoPasLMP::AutoPasType::RegionIteratorT
particles_by_slab(int dim, double lo, double hi) const;

/**
* Iterate over all particles in the AutoPas container.
* @tparam iterateBehavior Local, ghost or both
* @return Particle iterator
*/
template<autopas::IteratorBehavior iterateBehavior>
[[nodiscard]] AutoPasLMP::AutoPasType::iterator_t iterate() {
template<autopas::IteratorBehavior::Value iterateBehavior>
[[nodiscard]] AutoPasLMP::AutoPasType::IteratorT iterate() {
return _autopas->begin(iterateBehavior);
}

Expand All @@ -115,8 +113,8 @@ class AutoPasLMP : protected Pointers {
* @tparam iterateBehavior Local, ghost or both
* @return Const particle iterator
*/
template<autopas::IteratorBehavior iterateBehavior>
[[nodiscard]] AutoPasLMP::AutoPasType::const_iterator_t const_iterate() const {
template<autopas::IteratorBehavior::Value iterateBehavior>
[[nodiscard]] AutoPasLMP::AutoPasType::ConstIteratorT const_iterate() const {
return _autopas->cbegin(iterateBehavior);
}

Expand All @@ -128,7 +126,7 @@ class AutoPasLMP : protected Pointers {
* @param last Upper local index
* @return Particle iterator
*/
[[nodiscard]] AutoPasLMP::AutoPasType::const_iterator_t
[[nodiscard]] AutoPasLMP::AutoPasType::ConstIteratorT
const_iterate_auto(int first, int last);

/**
Expand All @@ -139,7 +137,7 @@ class AutoPasLMP : protected Pointers {
* @param last Upper local index
* @return Const particle iterator
*/
[[nodiscard]] AutoPasLMP::AutoPasType::iterator_t
[[nodiscard]] AutoPasLMP::AutoPasType::IteratorT
iterate_auto(int first, int last);


Expand Down Expand Up @@ -242,8 +240,8 @@ class AutoPasLMP : protected Pointers {
autopas::AcquisitionFunctionOption acquisition_function = {
autopas::AcquisitionFunctionOption::upperConfidenceBound};

autopas::TuningStrategyOption tuning_strategy{
autopas::TuningStrategyOption::fullSearch};
std::vector<autopas::TuningStrategyOption> tuning_strategies{};
std::string rule_filename{};
autopas::SelectorStrategyOption selector_strategy{
autopas::SelectorStrategyOption::fastestAbs};

Expand Down
Loading