From cb706ac3a5e99ea330fc31cdced3e90ab3a2cf96 Mon Sep 17 00:00:00 2001 From: capomav Date: Wed, 9 Aug 2023 18:06:05 +0200 Subject: [PATCH 1/2] stage 1 --- src/core/cell_system/CellStructure.cpp | 6 +++--- src/core/cell_system/CellStructure.hpp | 4 +++- src/core/cell_system/HybridDecomposition.cpp | 5 ++++- src/core/cell_system/RegularDecomposition.cpp | 8 ++++++-- src/core/cell_system/RegularDecomposition.hpp | 8 +++++++- src/core/cells.cpp | 18 +++++++++++++++--- src/core/cells.hpp | 5 +++++ src/core/event.cpp | 3 ++- .../cell_system/CellSystem.cpp | 13 +++++++++++++ 9 files changed, 58 insertions(+), 12 deletions(-) diff --git a/src/core/cell_system/CellStructure.cpp b/src/core/cell_system/CellStructure.cpp index 0ecdcc00ce9..6829df00cc5 100644 --- a/src/core/cell_system/CellStructure.cpp +++ b/src/core/cell_system/CellStructure.cpp @@ -264,9 +264,9 @@ void CellStructure::set_atom_decomposition(boost::mpi::communicator const &comm, void CellStructure::set_regular_decomposition( boost::mpi::communicator const &comm, double range, BoxGeometry const &box, - LocalBox &local_geo) { - set_particle_decomposition( - std::make_unique(comm, range, box, local_geo)); + LocalBox &local_geo, bool without_ghost_force_reduction) { + set_particle_decomposition(std::make_unique( + comm, range, box, local_geo, without_ghost_force_reduction)); m_type = CellStructureType::CELL_STRUCTURE_REGULAR; local_geo.set_cell_structure_type(m_type); } diff --git a/src/core/cell_system/CellStructure.hpp b/src/core/cell_system/CellStructure.hpp index 27c487e9b3d..37a435af134 100644 --- a/src/core/cell_system/CellStructure.hpp +++ b/src/core/cell_system/CellStructure.hpp @@ -527,10 +527,12 @@ struct CellStructure { * @param range Interaction range. * @param box Box Geometry. * @param local_geo Geometry of the local box. + * @param without_ghost_force_reduction remove the ghost force reduction. */ void set_regular_decomposition(boost::mpi::communicator const &comm, double range, BoxGeometry const &box, - LocalBox &local_geo); + LocalBox &local_geo, + bool without_ghost_force_reduction); /** * @brief Set the particle decomposition to @ref HybridDecomposition. diff --git a/src/core/cell_system/HybridDecomposition.cpp b/src/core/cell_system/HybridDecomposition.cpp index 073c03b636e..80e86932d70 100644 --- a/src/core/cell_system/HybridDecomposition.cpp +++ b/src/core/cell_system/HybridDecomposition.cpp @@ -40,6 +40,9 @@ #include #include +// TODO: check if we support without_ghost_force_reduction in +// HybridDecomposition too... + HybridDecomposition::HybridDecomposition(boost::mpi::communicator comm, double cutoff_regular, BoxGeometry const &box_geo, @@ -47,7 +50,7 @@ HybridDecomposition::HybridDecomposition(boost::mpi::communicator comm, std::set n_square_types) : m_comm(std::move(comm)), m_box(box_geo), m_cutoff_regular(cutoff_regular), m_regular_decomposition(RegularDecomposition( - m_comm, cutoff_regular + skin, m_box, local_box)), + m_comm, cutoff_regular + skin, m_box, local_box, false)), m_n_square(AtomDecomposition(m_comm, m_box)), m_n_square_types(std::move(n_square_types)) { diff --git a/src/core/cell_system/RegularDecomposition.cpp b/src/core/cell_system/RegularDecomposition.cpp index 6500a57a829..bf1a243c4b5 100644 --- a/src/core/cell_system/RegularDecomposition.cpp +++ b/src/core/cell_system/RegularDecomposition.cpp @@ -483,6 +483,8 @@ void RegularDecomposition::init_cell_interactions() { auto cell = &cells.at( get_linear_index(local_index(neighbor), ghost_cell_grid)); + // if (ind2 > ind1 or (without_ghost_force_reduction and + // is_ghost_cell(ind) )) { if (ind2 > ind1) { red_neighbors.push_back(cell); } else { @@ -633,8 +635,10 @@ GhostCommunicator RegularDecomposition::prepare_comm() { RegularDecomposition::RegularDecomposition(boost::mpi::communicator comm, double range, BoxGeometry const &box_geo, - LocalBox const &local_geo) - : m_comm(std::move(comm)), m_box(box_geo), m_local_box(local_geo) { + LocalBox const &local_geo, + bool without_ghost_force_reduction) + : m_comm(std::move(comm)), m_box(box_geo), m_local_box(local_geo), + m_without_ghost_force_reduction(without_ghost_force_reduction) { /* set up new regular decomposition cell structure */ create_cell_grid(range); diff --git a/src/core/cell_system/RegularDecomposition.hpp b/src/core/cell_system/RegularDecomposition.hpp index 77ccc09aa3b..2b7bd74d38f 100644 --- a/src/core/cell_system/RegularDecomposition.hpp +++ b/src/core/cell_system/RegularDecomposition.hpp @@ -85,11 +85,17 @@ struct RegularDecomposition : public ParticleDecomposition { std::vector m_ghost_cells; GhostCommunicator m_exchange_ghosts_comm; GhostCommunicator m_collect_ghost_force_comm; + bool m_without_ghost_force_reduction; public: RegularDecomposition(boost::mpi::communicator comm, double range, BoxGeometry const &box_geo, - LocalBox const &local_geo); + LocalBox const &local_geo, + bool without_ghost_force_reduction); + + bool get_without_ghost_force_reduction() const noexcept { + return m_without_ghost_force_reduction; + } GhostCommunicator const &exchange_ghosts_comm() const override { return m_exchange_ghosts_comm; diff --git a/src/core/cells.cpp b/src/core/cells.cpp index 1272800b4a7..d3c3c5f4619 100644 --- a/src/core/cells.cpp +++ b/src/core/cells.cpp @@ -203,12 +203,24 @@ void set_hybrid_decomposition(std::set n_square_types, on_cell_structure_change(); } +void set_regular_decomposition(bool without_ghost_force_reduction) { + cell_structure.set_regular_decomposition(comm_cart, interaction_range(), + box_geo, local_geo, + without_ghost_force_reduction); + on_cell_structure_change(); +} + void cells_re_init(CellStructureType new_cs) { switch (new_cs) { - case CellStructureType::CELL_STRUCTURE_REGULAR: - cell_structure.set_regular_decomposition(comm_cart, interaction_range(), - box_geo, local_geo); + case CellStructureType::CELL_STRUCTURE_REGULAR: { + auto ¤t_regular_decomposition = + dynamic_cast( + std::as_const(cell_structure).decomposition()); + cell_structure.set_regular_decomposition( + comm_cart, interaction_range(), box_geo, local_geo, + current_regular_decomposition.get_without_ghost_force_reduction()); break; + } case CellStructureType::CELL_STRUCTURE_NSQUARE: cell_structure.set_atom_decomposition(comm_cart, box_geo, local_geo); break; diff --git a/src/core/cells.hpp b/src/core/cells.hpp index 0dbcd3004f6..ef18bed6acf 100644 --- a/src/core/cells.hpp +++ b/src/core/cells.hpp @@ -84,6 +84,11 @@ extern CellStructure cell_structure; void set_hybrid_decomposition(std::set n_square_types, double cutoff_regular); +/** Initialize cell structure @ref RegularDecomposition + * @param without_ghost_force_reduction Remove the ghost force reduction + */ +void set_regular_decomposition(bool without_ghost_force_reduction); + /** Reinitialize the cell structures. * @param new_cs The new topology to use afterwards. */ diff --git a/src/core/event.cpp b/src/core/event.cpp index 9541c21235a..eff2ab49ea2 100644 --- a/src/core/event.cpp +++ b/src/core/event.cpp @@ -71,7 +71,8 @@ void on_program_start() { init_node_grid(); /* initially go for regular decomposition */ - cells_re_init(CellStructureType::CELL_STRUCTURE_REGULAR); + set_regular_decomposition(false); + // cells_re_init(CellStructureType::CELL_STRUCTURE_REGULAR); /* make sure interaction 0<->0 always exists */ make_particle_type_exist(0); diff --git a/src/script_interface/cell_system/CellSystem.cpp b/src/script_interface/cell_system/CellSystem.cpp index db39a9ad81b..1428c0996d3 100644 --- a/src/script_interface/cell_system/CellSystem.cpp +++ b/src/script_interface/cell_system/CellSystem.cpp @@ -125,6 +125,15 @@ CellSystem::CellSystem() { {"max_cut_nonbonded", AutoParameter::read_only, maximal_cutoff_nonbonded}, {"max_cut_bonded", AutoParameter::read_only, maximal_cutoff_bonded}, {"interaction_range", AutoParameter::read_only, interaction_range}, + {"without_ghost_force_reduction", AutoParameter::read_only, + []() { + if (::cell_structure.decomposition_type() != + CellStructureType::CELL_STRUCTURE_REGULAR) { + return Variant{none}; + } + auto const rd = get_regular_decomposition(); + return Variant{rd.get_without_ghost_force_reduction()}; + }}, }); } @@ -255,6 +264,10 @@ void CellSystem::initialize(CellStructureType const &cs_type, get_value_or>(params, "n_square_types", {}); auto n_square_types = std::set{ns_types.begin(), ns_types.end()}; set_hybrid_decomposition(std::move(n_square_types), cutoff_regular); + } else if (cs_type == CellStructureType::CELL_STRUCTURE_REGULAR) { + auto const without_ghost_force_reduction = + get_value_or(params, "without_ghost_force_reduction", false); + set_regular_decomposition(without_ghost_force_reduction); } else { cells_re_init(cs_type); } From 6154c6147909c5b5913d585004aa392b5fa3cfde Mon Sep 17 00:00:00 2001 From: capomav Date: Wed, 16 Aug 2023 15:47:37 +0200 Subject: [PATCH 2/2] removed comment --- src/core/cell_system/RegularDecomposition.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/core/cell_system/RegularDecomposition.cpp b/src/core/cell_system/RegularDecomposition.cpp index bf1a243c4b5..f2dc765d1db 100644 --- a/src/core/cell_system/RegularDecomposition.cpp +++ b/src/core/cell_system/RegularDecomposition.cpp @@ -483,8 +483,7 @@ void RegularDecomposition::init_cell_interactions() { auto cell = &cells.at( get_linear_index(local_index(neighbor), ghost_cell_grid)); - // if (ind2 > ind1 or (without_ghost_force_reduction and - // is_ghost_cell(ind) )) { + if (ind2 > ind1) { red_neighbors.push_back(cell); } else {