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

Add support for recent compilers #4715

Merged
merged 3 commits into from
Apr 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions src/core/BondList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,9 +139,9 @@ class BondList {
auto const id_pos = find_end(m_it);
auto const partners_begin = m_it;
auto const partners_end = id_pos;
return {-(*id_pos) - 1,
Utils::make_span(std::addressof(*partners_begin),
std::distance(partners_begin, partners_end))};
auto const dist = std::distance(partners_begin, partners_end);
return {-(*id_pos) - 1, Utils::make_span(std::addressof(*partners_begin),
static_cast<size_type>(dist))};
}
};

Expand Down Expand Up @@ -206,7 +206,9 @@ class BondList {
* @brief Number of bonds.
* @return The number of bonds in the list.
*/
size_type size() const { return std::distance(begin(), end()); }
auto size() const {
return static_cast<size_type>(std::distance(begin(), end()));
}

/**
* @brief Erase all bonds from the list.
Expand Down
17 changes: 11 additions & 6 deletions src/core/BoxGeometry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,8 @@ class BoxGeometry {
Utils::Vector<T, 3> get_mi_vector(const Utils::Vector<T, 3> &a,
const Utils::Vector<T, 3> &b) const {
if (type() == BoxType::LEES_EDWARDS) {
auto const shear_plane_normal = lees_edwards_bc().shear_plane_normal;
auto const shear_plane_normal =
static_cast<unsigned int>(lees_edwards_bc().shear_plane_normal);
auto a_tmp = a;
auto b_tmp = b;
a_tmp[shear_plane_normal] = Algorithm::periodic_fold(
Expand Down Expand Up @@ -226,9 +227,13 @@ class BoxGeometry {
auto ret = u - v;
if (type() == BoxType::LEES_EDWARDS) {
auto const &le = m_lees_edwards_bc;
auto const dy = x[le.shear_plane_normal] - y[le.shear_plane_normal];
if (fabs(dy) > 0.5 * length_half()[le.shear_plane_normal]) {
ret[le.shear_direction] -= Utils::sgn(dy) * le.shear_velocity;
auto const shear_plane_normal =
static_cast<unsigned int>(le.shear_plane_normal);
auto const shear_direction =
static_cast<unsigned int>(le.shear_direction);
auto const dy = x[shear_plane_normal] - y[shear_plane_normal];
if (fabs(dy) > 0.5 * length_half()[shear_plane_normal]) {
ret[shear_direction] -= Utils::sgn(dy) * le.shear_velocity;
}
}
return ret;
Expand Down Expand Up @@ -263,7 +268,7 @@ inline std::pair<double, int> fold_coordinate(double pos, int image_box,
*/
inline void fold_position(Utils::Vector3d &pos, Utils::Vector3i &image_box,
const BoxGeometry &box) {
for (int i = 0; i < 3; i++) {
for (unsigned int i = 0; i < 3; i++) {
if (box.periodic(i)) {
std::tie(pos[i], image_box[i]) =
fold_coordinate(pos[i], image_box[i], box.length()[i]);
Expand All @@ -279,7 +284,7 @@ inline void fold_position(Utils::Vector3d &pos, Utils::Vector3i &image_box,
inline Utils::Vector3d folded_position(const Utils::Vector3d &p,
const BoxGeometry &box) {
Utils::Vector3d p_folded;
for (int i = 0; i < 3; i++) {
for (unsigned int i = 0; i < 3; i++) {
if (box.periodic(i)) {
p_folded[i] = Algorithm::periodic_fold(p[i], box.length()[i]);
} else {
Expand Down
5 changes: 3 additions & 2 deletions src/core/Observable_stat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
#include <functional>
#include <vector>

inline std::size_t max_non_bonded_pairs() {
static auto max_non_bonded_pairs() {
auto const n = static_cast<std::size_t>(max_seen_particle_type);
return (n * (n + 1)) / 2;
}
Expand All @@ -52,7 +52,8 @@ Observable_stat::Observable_stat(std::size_t chunk_size)
#else
constexpr std::size_t n_vs = 0;
#endif
auto const n_bonded = bonded_ia_params.get_next_key();
auto const n_bonded =
static_cast<std::size_t>(bonded_ia_params.get_next_key());
auto const n_non_bonded = max_non_bonded_pairs();
constexpr std::size_t n_ext_fields = 1; // reduction over all fields
constexpr std::size_t n_kinetic = 1; // linear+angular kinetic contributions
Expand Down
16 changes: 7 additions & 9 deletions src/core/Particle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,9 @@
#include <vector>

namespace detail {
inline void check_axis_idx_valid(int const axis) {
assert(axis >= 0 and axis <= 2);
}
inline void check_axis_idx_valid(unsigned int const axis) { assert(axis <= 2); }

inline bool get_nth_bit(uint8_t const bitfield, int const bit_idx) {
inline bool get_nth_bit(uint8_t const bitfield, unsigned int const bit_idx) {
return bitfield & (1u << bit_idx);
}
} // namespace detail
Expand Down Expand Up @@ -463,11 +461,11 @@ struct Particle { // NOLINT(bugprone-exception-escape)
auto const &rotation() const { return p.rotation; }
auto &rotation() { return p.rotation; }
bool can_rotate() const { return static_cast<bool>(p.rotation); }
bool can_rotate_around(int const axis) const {
bool can_rotate_around(unsigned int const axis) const {
detail::check_axis_idx_valid(axis);
return detail::get_nth_bit(p.rotation, axis);
}
void set_can_rotate_around(int const axis, bool const rot_flag) {
void set_can_rotate_around(unsigned int const axis, bool const rot_flag) {
detail::check_axis_idx_valid(axis);
if (rot_flag) {
p.rotation |= static_cast<uint8_t>(1u << axis);
Expand All @@ -492,7 +490,7 @@ struct Particle { // NOLINT(bugprone-exception-escape)
auto calc_director() const { return r.calc_director(); }
#else // ROTATION
auto can_rotate() const { return false; }
auto can_rotate_around(int const axis) const { return false; }
auto can_rotate_around(unsigned int const axis) const { return false; }
#endif // ROTATION
#ifdef DIPOLES
auto const &dipm() const { return p.dipm; }
Expand Down Expand Up @@ -539,7 +537,7 @@ struct Particle { // NOLINT(bugprone-exception-escape)
auto const &fixed() const { return p.ext_flag; }
auto &fixed() { return p.ext_flag; }
bool has_fixed_coordinates() const { return static_cast<bool>(p.ext_flag); }
bool is_fixed_along(int const axis) const {
bool is_fixed_along(unsigned int const axis) const {
detail::check_axis_idx_valid(axis);
return detail::get_nth_bit(p.ext_flag, axis);
}
Expand All @@ -555,7 +553,7 @@ struct Particle { // NOLINT(bugprone-exception-escape)
auto &ext_force() { return p.ext_force; }
#else // EXTERNAL_FORCES
constexpr bool has_fixed_coordinates() const { return false; }
constexpr bool is_fixed_along(int const) const { return false; }
constexpr bool is_fixed_along(unsigned int const) const { return false; }
#endif // EXTERNAL_FORCES
#ifdef ENGINE
auto const &swimming() const { return p.swim; }
Expand Down
2 changes: 1 addition & 1 deletion src/core/bond_breakage/bond_breakage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ static void remove_pair_bonds_to(Particle &p, int other_pid) {
std::vector<std::pair<int, int>> to_delete;
for (auto b : p.bonds()) {
if (b.partner_ids().size() == 1 and b.partner_ids()[0] == other_pid)
to_delete.emplace_back(std::pair<int, int>{b.bond_id(), other_pid});
to_delete.emplace_back(b.bond_id(), other_pid);
}
for (auto const &b : to_delete) {
remove_bond(p, BondView(b.first, {&b.second, 1}));
Expand Down
2 changes: 1 addition & 1 deletion src/core/cell_system/AtomDecomposition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ class AtomDecomposition : public ParticleDecomposition {
/**
* @brief Get the local cell.
*/
Cell &local() { return cells.at(m_comm.rank()); }
Cell &local() { return cells.at(static_cast<unsigned int>(m_comm.rank())); }

void configure_neighbors();
GhostCommunicator prepare_comm();
Expand Down
14 changes: 7 additions & 7 deletions src/core/cell_system/CellStructure.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -166,10 +166,10 @@ struct CellStructure {
// cppcheck-suppress assertWithSideEffect
assert(not p or p->id() == id);

if (id >= m_particle_index.size())
m_particle_index.resize(id + 1);
if (static_cast<unsigned int>(id) >= m_particle_index.size())
m_particle_index.resize(static_cast<unsigned int>(id + 1));

m_particle_index[id] = p;
m_particle_index[static_cast<unsigned int>(id)] = p;
}

/**
Expand Down Expand Up @@ -234,20 +234,20 @@ struct CellStructure {
Particle *get_local_particle(int id) {
assert(id >= 0);

if (id >= m_particle_index.size())
if (static_cast<unsigned int>(id) >= m_particle_index.size())
return nullptr;

return m_particle_index[id];
return m_particle_index[static_cast<unsigned int>(id)];
}

/** @overload */
const Particle *get_local_particle(int id) const {
assert(id >= 0);

if (id >= m_particle_index.size())
if (static_cast<unsigned int>(id) >= m_particle_index.size())
return nullptr;

return m_particle_index[id];
return m_particle_index[static_cast<unsigned int>(id)];
}

template <class InputRange, class OutputIterator>
Expand Down
11 changes: 6 additions & 5 deletions src/core/cell_system/RegularDecomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
Cell *RegularDecomposition::position_to_cell(const Utils::Vector3d &pos) {
Utils::Vector3i cpos;

for (int i = 0; i < 3; i++) {
for (unsigned int i = 0; i < 3; i++) {
cpos[i] = static_cast<int>(std::floor(pos[i] * inv_cell_size[i])) + 1 -
cell_offset[i];

Expand Down Expand Up @@ -266,8 +266,9 @@ void RegularDecomposition::fill_comm_cell_lists(ParticleList **part_lists,
*part_lists++ = &(cells.at(i).particles());
}
}

Utils::Vector3d RegularDecomposition::max_cutoff() const {
auto dir_max_range = [this](int i) {
auto dir_max_range = [this](unsigned int i) {
return std::min(0.5 * m_box.length()[i], m_local_box.length()[i]);
};

Expand Down Expand Up @@ -307,7 +308,7 @@ void RegularDecomposition::create_cell_grid(double range) {
auto const volume = Utils::product(local_box_l);
auto const scale = std::cbrt(RegularDecomposition::max_num_cells / volume);

for (int i = 0; i < 3; i++) {
for (unsigned int i = 0; i < 3; i++) {
/* this is at least 1 */
cell_grid[i] = static_cast<int>(std::ceil(local_box_l[i] * scale));
cell_range[i] = local_box_l[i] / static_cast<double>(cell_grid[i]);
Expand Down Expand Up @@ -370,7 +371,7 @@ void RegularDecomposition::create_cell_grid(double range) {

/* now set all dependent variables */
int new_cells = 1;
for (int i = 0; i < 3; i++) {
for (unsigned int i = 0; i < 3; i++) {
ghost_cell_grid[i] = cell_grid[i] + 2;
new_cells *= ghost_cell_grid[i];
cell_size[i] = m_local_box.length()[i] / static_cast<double>(cell_grid[i]);
Expand All @@ -380,7 +381,7 @@ void RegularDecomposition::create_cell_grid(double range) {

/* allocate cell array and cell pointer arrays */
cells.clear();
cells.resize(new_cells);
cells.resize(static_cast<unsigned int>(new_cells));
m_local_cells.resize(n_local_cells);
m_ghost_cells.resize(new_cells - n_local_cells);
}
Expand Down
28 changes: 14 additions & 14 deletions src/core/collision.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ static bool bind_centers() {
// but does so later in the process. This is needed to guarantee that
// a particle can only be glued once, even if queued twice in a single
// time step
return collision_params.mode != CollisionModeType::OFF &&
return collision_params.mode != CollisionModeType::OFF and
collision_params.mode != CollisionModeType::GLUE_TO_SURF;
}

Expand Down Expand Up @@ -130,7 +130,7 @@ void Collision_parameters::initialize() {
#ifdef VIRTUAL_SITES
// Check vs placement parameter
if (collision_params.mode == CollisionModeType::BIND_VS) {
if ((collision_params.vs_placement < 0.) ||
if ((collision_params.vs_placement < 0.) or
(collision_params.vs_placement > 1.)) {
throw std::domain_error(
"Parameter 'vs_placement' must be between 0 and 1");
Expand All @@ -139,30 +139,30 @@ void Collision_parameters::initialize() {
#endif

// Check if bonded ia exist
if ((collision_params.mode == CollisionModeType::BIND_CENTERS) &&
if ((collision_params.mode == CollisionModeType::BIND_CENTERS) and
!bonded_ia_params.contains(collision_params.bond_centers)) {
throw std::runtime_error(
"Bond in parameter 'bond_centers' was not added to the system");
}

if ((collision_params.mode == CollisionModeType::BIND_VS) &&
if ((collision_params.mode == CollisionModeType::BIND_VS) and
!bonded_ia_params.contains(collision_params.bond_vs)) {
throw std::runtime_error(
"Bond in parameter 'bond_vs' was not added to the system");
}

// If the bond type to bind particle centers is not a pair bond...
// Check that the bonds have the right number of partners
if ((collision_params.mode == CollisionModeType::BIND_CENTERS) &&
if ((collision_params.mode == CollisionModeType::BIND_CENTERS) and
(get_bond_num_partners(collision_params.bond_centers) != 1)) {
throw std::runtime_error("The bond type to be used for binding particle "
"centers needs to be a pair bond");
}

// The bond between the virtual sites can be pair or triple
if ((collision_params.mode == CollisionModeType::BIND_VS) &&
!(get_bond_num_partners(collision_params.bond_vs) == 1 ||
get_bond_num_partners(collision_params.bond_vs) == 2)) {
if ((collision_params.mode == CollisionModeType::BIND_VS) and
(get_bond_num_partners(collision_params.bond_vs) != 1 and
get_bond_num_partners(collision_params.bond_vs) != 2)) {
throw std::runtime_error("The bond type to be used for binding virtual "
"sites needs to be a pair or three-particle bond");
}
Expand Down Expand Up @@ -242,10 +242,10 @@ const Particle &glue_to_surface_calc_vs_pos(const Particle &p1,
const double dist_betw_part = vec21.norm();

// Find out, which is the particle to be glued.
if ((p1.type() == collision_params.part_type_to_be_glued) &&
if ((p1.type() == collision_params.part_type_to_be_glued) and
(p2.type() == collision_params.part_type_to_attach_vs_to)) {
c = 1 - collision_params.dist_glued_part_to_vs / dist_betw_part;
} else if ((p2.type() == collision_params.part_type_to_be_glued) &&
} else if ((p2.type() == collision_params.part_type_to_be_glued) and
(p1.type() == collision_params.part_type_to_attach_vs_to)) {
c = collision_params.dist_glued_part_to_vs / dist_betw_part;
} else {
Expand Down Expand Up @@ -299,8 +299,8 @@ void coldet_do_three_particle_bond(Particle &p, Particle const &p1,
id2 = p2.id()](BondView const &bond) {
auto const partner_ids = bond.partner_ids();

return ((partner_ids[0] == id1) && (partner_ids[1] == id2)) ||
((partner_ids[0] == id2) && (partner_ids[1] == id1));
return ((partner_ids[0] == id1) and (partner_ids[1] == id2)) or
((partner_ids[0] == id2) and (partner_ids[1] == id1));
};

auto const &bonds = p.bonds();
Expand Down Expand Up @@ -450,7 +450,7 @@ void three_particle_binding_domain_decomposition(
for (auto &c : gathered_queue) {
// If we have both particles, at least as ghosts, Get the corresponding cell
// indices
if (cell_structure.get_local_particle(c.pp1) &&
if (cell_structure.get_local_particle(c.pp1) and
cell_structure.get_local_particle(c.pp2)) {
Particle &p1 = *cell_structure.get_local_particle(c.pp1);
Particle &p2 = *cell_structure.get_local_particle(c.pp2);
Expand All @@ -459,7 +459,7 @@ void three_particle_binding_domain_decomposition(

if (cell1)
three_particle_binding_do_search(cell1, p1, p2);
if (cell2 && cell1 != cell2)
if (cell2 and cell1 != cell2)
three_particle_binding_do_search(cell2, p1, p2);

} // If local particles exist
Expand Down
2 changes: 1 addition & 1 deletion src/core/cuda_init.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ std::vector<EspressoGpuDevice> cuda_gather_gpus() {

if (this_node == 0) {
std::set<EspressoGpuDevice, CompareDevices> device_set;
int *n_gpu_array = new int[n_nodes];
int *n_gpu_array = new int[static_cast<unsigned int>(n_nodes)];
MPI_Gather(&n_gpus, 1, MPI_INT, n_gpu_array, 1, MPI_INT, 0, MPI_COMM_WORLD);

/* insert local devices */
Expand Down
4 changes: 2 additions & 2 deletions src/core/cuda_interface.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ void cuda_mpi_get_particles(
static void add_forces_and_torques(ParticleRange particles,
Utils::Span<const float> forces,
Utils::Span<const float> torques) {
int i = 0;
unsigned int i = 0;
for (auto &p : particles) {
for (int j = 0; j < 3; j++) {
for (unsigned int j = 0; j < 3; j++) {
p.force()[j] += static_cast<double>(forces[3 * i + j]);
#ifdef ROTATION
p.torque()[j] += static_cast<double>(torques[3 * i + j]);
Expand Down
Loading