Skip to content

Commit

Permalink
Readability for n_square_type; code formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
pkreissl committed Dec 17, 2021
1 parent f4b8885 commit 869f8b5
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 30 deletions.
15 changes: 8 additions & 7 deletions src/core/HybridDecomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,18 @@

#include "HybridDecomposition.hpp"

#include <utility>
#include <utils/Vector.hpp>
#include <utils/mpi/sendrecv.hpp>
#include <utility>

HybridDecomposition::HybridDecomposition(boost::mpi::communicator comm,
double n_square_cutoff,
const BoxGeometry &box_geo,
const LocalBox<double> &local_box,
std::set<int> n_square_types)
: m_comm(std::move(comm)), m_box(box_geo),
m_domain_decomposition(DomainDecomposition(
m_comm, n_square_cutoff + skin, m_box, local_box)),
m_domain_decomposition(DomainDecomposition(m_comm, n_square_cutoff + skin,
m_box, local_box)),
m_n_square(AtomDecomposition(m_comm, m_box)),
m_n_square_types(std::move(n_square_types)) {

Expand Down Expand Up @@ -86,7 +86,7 @@ void HybridDecomposition::resort(bool global,
for (auto &c : m_domain_decomposition.local_cells()) {
for (auto it = c->particles().begin(); it != c->particles().end();) {
/* Particle is in the right decomposition, i.e. has no n_square type */
if (m_n_square_types.find(it->p.type) == m_n_square_types.end()) {
if (not is_n_square_type(it->p.type)) {
std::advance(it, 1);
continue;
}
Expand All @@ -108,7 +108,7 @@ void HybridDecomposition::resort(bool global,
for (auto &c : m_n_square.local_cells()) {
for (auto it = c->particles().begin(); it != c->particles().end();) {
/* Particle is of n_square type */
if (m_n_square_types.find(it->p.type) != m_n_square_types.end()) {
if (is_n_square_type(it->p.type)) {
std::advance(it, 1);
continue;
}
Expand Down Expand Up @@ -142,13 +142,14 @@ void HybridDecomposition::resort(bool global,
m_n_square.resort(global, diff);
}

Utils::Vector<std::size_t, 2> HybridDecomposition::parts_per_decomposition_local() const {
Utils::Vector<std::size_t, 2>
HybridDecomposition::parts_per_decomposition_local() const {
std::size_t parts_in_domain_dec = 0;
std::size_t parts_in_n_square = 0;
for (auto &c : m_domain_decomposition.get_local_cells()) {
parts_in_domain_dec += c->particles().size();
}
for (auto &c : m_n_square.get_local_cells()) {
for (auto &c : m_n_square.get_local_cells()) {
parts_in_n_square += c->particles().size();
}
return {parts_in_domain_dec, parts_in_n_square};
Expand Down
14 changes: 8 additions & 6 deletions src/core/HybridDecomposition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#include <vector>

namespace Utils{
using Vector2i = Vector<std::size_t, 2>;
using Vector2i = Vector<std::size_t, 2>;
}

class HybridDecomposition : public ParticleDecomposition {
Expand All @@ -60,6 +60,10 @@ class HybridDecomposition : public ParticleDecomposition {
/** Set containing the types that should be handled using n_square */
std::set<int> const m_n_square_types;

bool is_n_square_type(int type_id) {
return (m_n_square_types.find(type_id) != m_n_square_types.end());
}

public:
HybridDecomposition(boost::mpi::communicator comm, double n_square_cutoff,
const BoxGeometry &box_geo,
Expand Down Expand Up @@ -95,12 +99,10 @@ class HybridDecomposition : public ParticleDecomposition {
}

Cell *particle_to_cell(Particle const &p) override {
/* if not a n_square type ... */
if (m_n_square_types.find(p.p.type) == m_n_square_types.end()) {
return m_domain_decomposition.particle_to_cell(p);
if (is_n_square_type(p.p.type)) {
return m_n_square.particle_to_cell(p);
}
/* ... else: */
return m_n_square.particle_to_cell(p);
return m_domain_decomposition.particle_to_cell(p);
}

Utils::Vector3d max_cutoff() const override {
Expand Down
21 changes: 11 additions & 10 deletions src/core/cells.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,10 @@ void set_atom_decomposition() {
on_cell_structure_change();
}

void set_hybrid_decomposition(
std::set<int> n_square_types, double n_square_cutoff) {
cell_structure.set_hybrid_decomposition(comm_cart, n_square_cutoff,
box_geo, local_geo, n_square_types);
void set_hybrid_decomposition(std::set<int> n_square_types,
double n_square_cutoff) {
cell_structure.set_hybrid_decomposition(comm_cart, n_square_cutoff, box_geo,
local_geo, n_square_types);
on_cell_structure_change();
}

Expand All @@ -231,8 +231,8 @@ REGISTER_CALLBACK(set_hybrid_decomposition)

void mpi_set_domain_decomposition() { mpi_call_all(set_domain_decomposition); }
void mpi_set_atom_decomposition() { mpi_call_all(set_atom_decomposition); }
void mpi_set_hybrid_decomposition(
std::set<int> n_square_types, double n_square_cutoff) {
void mpi_set_hybrid_decomposition(std::set<int> n_square_types,
double n_square_cutoff) {
mpi_call_all(set_hybrid_decomposition, n_square_types, n_square_cutoff);
}

Expand All @@ -244,17 +244,18 @@ static Utils::Vector<std::size_t, 2> hybrid_parts_per_decomposition_local() {
Utils::as_const(cell_structure).decomposition());

Utils::Vector<std::size_t, 2> parts_per_decomposition;
boost::mpi::reduce(comm_cart, current_hybrid_decomposition.parts_per_decomposition_local(),
parts_per_decomposition, std::plus<>{}, 0);
boost::mpi::reduce(
comm_cart, current_hybrid_decomposition.parts_per_decomposition_local(),
parts_per_decomposition, std::plus<>{}, 0);

return parts_per_decomposition;
}

REGISTER_CALLBACK_MASTER_RANK(hybrid_parts_per_decomposition_local)

std::pair<std::size_t, std::size_t> hybrid_parts_per_decomposition() {
auto const parts_per_decomposition =
mpi_call(Communication::Result::master_rank, hybrid_parts_per_decomposition_local);
auto const parts_per_decomposition = mpi_call(
Communication::Result::master_rank, hybrid_parts_per_decomposition_local);
return std::make_pair(parts_per_decomposition[0], parts_per_decomposition[1]);
}

Expand Down
8 changes: 4 additions & 4 deletions src/core/cells.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ void set_atom_decomposition();
/** Initialize cell structure HybridDecomposition
* @param n_square_types Set of particle types that will use n_square.
*/
void set_hybrid_decomposition(
std::set<int> n_square_types, double n_square_cutoff);
void set_hybrid_decomposition(std::set<int> n_square_types,
double n_square_cutoff);

/** Change cell structure to DomainDecomposition on all nodes. */
void mpi_set_domain_decomposition();
Expand All @@ -89,8 +89,8 @@ void mpi_set_atom_decomposition();
/** Change cell structure to HybridDecomposition on all nodes.
* @param n_square_types Set of particle types that will use n_square.
*/
void mpi_set_hybrid_decomposition(
std::set<int> n_square_types, double n_square_cutoff);
void mpi_set_hybrid_decomposition(std::set<int> n_square_types,
double n_square_cutoff);

/**
* @brief Number of parts in child decompositions of a HybridDecomposition.
Expand Down
2 changes: 1 addition & 1 deletion src/python/espressomd/cellsystem.pxd
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ cdef extern from "cells.hpp":
void mpi_set_atom_decomposition()
void mpi_set_hybrid_decomposition(cpp_set[int] n_square_types, double n_square_cutoff)
void mpi_set_use_verlet_lists(bool use_verlet_lists)

pair[size_t, size_t] hybrid_parts_per_decomposition()

cdef extern from "tuning.hpp":
Expand Down
4 changes: 2 additions & 2 deletions src/python/espressomd/cellsystem.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ cdef class CellSystem:
self.resort()
n_domain_dec, n_n_square = hybrid_parts_per_decomposition()
s["parts_per_decomposition"] = {
"domain" : n_domain_dec,
"n_square" : n_n_square
"domain": n_domain_dec,
"n_square": n_n_square
}

s["verlet_reuse"] = get_verlet_reuse()
Expand Down

0 comments on commit 869f8b5

Please sign in to comment.