diff --git a/CMakeLists.txt b/CMakeLists.txt index 7a47427941e..eed1e0844f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -347,6 +347,7 @@ target_compile_options( INTERFACE -Wall -Wextra $<$:-Werror> + $<$:-Wno-unknown-cuda-version> # add extra warnings $<$:-Wextern-initializer> $<$:-Wrange-loop-analysis> diff --git a/src/core/accumulators/Correlator.cpp b/src/core/accumulators/Correlator.cpp index 326827edcfd..e6f493af842 100644 --- a/src/core/accumulators/Correlator.cpp +++ b/src/core/accumulators/Correlator.cpp @@ -273,6 +273,8 @@ void Correlator::initialize() { compressB_name + "' for second observable"); } + using index_type = decltype(result)::index; + A.resize(std::array{{m_hierarchy_depth, m_tau_lin + 1}}); std::fill_n(A.data(), A.num_elements(), std::vector(dim_A, 0)); B.resize(std::array{{m_hierarchy_depth, m_tau_lin + 1}}); @@ -287,11 +289,9 @@ void Correlator::initialize() { n_vals = std::vector(m_hierarchy_depth, 0); result.resize(std::array{{n_result, m_dim_corr}}); - - for (std::size_t i = 0; i < n_result; i++) { - for (std::size_t j = 0; j < m_dim_corr; j++) { - // and initialize the values - result[i][j] = 0; + for (index_type i = 0; i < static_cast(n_result); i++) { + for (index_type j = 0; j < static_cast(m_dim_corr); j++) { + result[i][j] = 0.; } } @@ -377,6 +377,7 @@ void Correlator::update() { B_accumulated_average[k] += B[0][newest[0]][k]; } + using index_type = decltype(result)::index; // Now update the lowest level correlation estimates for (long j = 0; j < min(m_tau_lin + 1, n_vals[0]); j++) { auto const index_new = newest[0]; @@ -386,7 +387,7 @@ void Correlator::update() { assert(temp.size() == m_dim_corr); n_sweeps[j]++; - for (std::size_t k = 0; k < m_dim_corr; k++) { + for (index_type k = 0; k < static_cast(m_dim_corr); k++) { result[j][k] += temp[k]; } } @@ -403,7 +404,7 @@ void Correlator::update() { assert(temp.size() == m_dim_corr); n_sweeps[index_res]++; - for (std::size_t k = 0; k < m_dim_corr; k++) { + for (index_type k = 0; k < static_cast(m_dim_corr); k++) { result[index_res][k] += temp[k]; } } @@ -411,6 +412,7 @@ void Correlator::update() { } int Correlator::finalize() { + using index_type = decltype(result)::index; if (finalized) { throw std::runtime_error("Correlator::finalize() can only be called once."); } @@ -479,7 +481,7 @@ int Correlator::finalize() { assert(temp.size() == m_dim_corr); n_sweeps[index_res]++; - for (std::size_t k = 0; k < m_dim_corr; k++) { + for (index_type k = 0; k < static_cast(m_dim_corr); k++) { result[index_res][k] += temp[k]; } } @@ -490,14 +492,16 @@ int Correlator::finalize() { } std::vector Correlator::get_correlation() { + using index_type = decltype(result)::index; auto const n_result = n_values(); std::vector res(n_result * m_dim_corr); for (std::size_t i = 0; i < n_result; i++) { - auto const index = m_dim_corr * i; - for (std::size_t k = 0; k < m_dim_corr; k++) { + auto const index = static_cast(m_dim_corr * i); + for (index_type k = 0; k < static_cast(m_dim_corr); k++) { if (n_sweeps[i]) { - res[index + k] = result[i][k] / static_cast(n_sweeps[i]); + res[index + k] = result[static_cast(i)][k] / + static_cast(n_sweeps[i]); } } } diff --git a/src/core/cell_system/AtomDecomposition.hpp b/src/core/cell_system/AtomDecomposition.hpp index 97d675869c3..3b6a1c2e7c4 100644 --- a/src/core/cell_system/AtomDecomposition.hpp +++ b/src/core/cell_system/AtomDecomposition.hpp @@ -51,6 +51,7 @@ * * For a more detailed discussion please see @cite plimpton95a. */ +// NOLINTNEXTLINE(bugprone-exception-escape) class AtomDecomposition : public ParticleDecomposition { boost::mpi::communicator comm; std::vector cells; diff --git a/src/core/cell_system/CellStructure.hpp b/src/core/cell_system/CellStructure.hpp index 7d03b8d865c..ca3d8bfedd4 100644 --- a/src/core/cell_system/CellStructure.hpp +++ b/src/core/cell_system/CellStructure.hpp @@ -111,7 +111,9 @@ struct Distance { Utils::Vector3d vec21; double dist2; }; + namespace detail { +// NOLINTNEXTLINE(bugprone-exception-escape) struct MinimalImageDistance { const BoxGeometry box; diff --git a/src/core/cell_system/RegularDecomposition.hpp b/src/core/cell_system/RegularDecomposition.hpp index 56c2ab5d98f..4408079b356 100644 --- a/src/core/cell_system/RegularDecomposition.hpp +++ b/src/core/cell_system/RegularDecomposition.hpp @@ -65,6 +65,7 @@ * communication! For single sided ghost communication one would need * some ghost-ghost cell interaction as well, which we do not need! */ +// NOLINTNEXTLINE(bugprone-exception-escape) struct RegularDecomposition : public ParticleDecomposition { /** Grid dimensions per node. */ Utils::Vector3i cell_grid = {}; diff --git a/src/core/cells.cpp b/src/core/cells.cpp index dd0216ce5c5..da16a519296 100644 --- a/src/core/cells.cpp +++ b/src/core/cells.cpp @@ -172,6 +172,7 @@ get_pairs_of_types(double const distance, std::vector const &types) { detail::search_distance_sanity_check(distance); auto pairs = get_pairs_filtered(distance, [types](Particle const &p) { return std::any_of(types.begin(), types.end(), + // NOLINTNEXTLINE(bugprone-exception-escape) [p](int const type) { return p.type() == type; }); }); Utils::Mpi::gather_buffer(pairs, comm_cart); diff --git a/src/core/cuda_interface.cpp b/src/core/cuda_interface.cpp index b2d82518474..d4293801ab1 100644 --- a/src/core/cuda_interface.cpp +++ b/src/core/cuda_interface.cpp @@ -130,16 +130,18 @@ static void add_forces_and_torques(ParticleRange particles, void cuda_mpi_send_forces(const ParticleRange &particles, Utils::Span host_forces, Utils::Span host_torques) { - auto const n_elements = 3 * particles.size(); + + auto const size = 3 * particles.size(); + auto const n_elements = static_cast(size); if (this_node > 0) { static std::vector buffer_forces; static std::vector buffer_torques; - buffer_forces.resize(n_elements); + buffer_forces.resize(size); Utils::Mpi::scatter_buffer(buffer_forces.data(), n_elements, comm_cart); #ifdef ROTATION - buffer_torques.resize(n_elements); + buffer_torques.resize(size); Utils::Mpi::scatter_buffer(buffer_torques.data(), n_elements, comm_cart); #endif add_forces_and_torques(particles, buffer_forces, buffer_torques); diff --git a/src/core/energy.cpp b/src/core/energy.cpp index daa720cb737..8804d140911 100644 --- a/src/core/energy.cpp +++ b/src/core/energy.cpp @@ -114,6 +114,7 @@ static std::shared_ptr calculate_energy_local() { obs_energy.mpi_reduce(); return obs_energy_ptr; + // NOLINTNEXTLINE(clang-analyzer-cplusplus.NewDeleteLeaks) } REGISTER_CALLBACK_MAIN_RANK(calculate_energy_local) diff --git a/src/core/grid_based_algorithms/electrokinetics_cuda.cu b/src/core/grid_based_algorithms/electrokinetics_cuda.cu index 20515f2fda5..c6dc10144e5 100644 --- a/src/core/grid_based_algorithms/electrokinetics_cuda.cu +++ b/src/core/grid_based_algorithms/electrokinetics_cuda.cu @@ -3612,10 +3612,10 @@ void ek_print_lbpar() { printf(" float agrid = %f;\n", lbpar_gpu.agrid); printf(" float tau = %f;\n", lbpar_gpu.tau); printf(" float bulk_viscosity = %f;\n", lbpar_gpu.bulk_viscosity); - printf(" unsigned int dim_x = %d;\n", lbpar_gpu.dim[0]); - printf(" unsigned int dim_y = %d;\n", lbpar_gpu.dim[1]); - printf(" unsigned int dim_z = %d;\n", lbpar_gpu.dim[2]); - printf(" unsigned int number_of_nodes = %d;\n", lbpar_gpu.number_of_nodes); + printf(" unsigned int dim_x = %u;\n", lbpar_gpu.dim[0]); + printf(" unsigned int dim_y = %u;\n", lbpar_gpu.dim[1]); + printf(" unsigned int dim_z = %u;\n", lbpar_gpu.dim[2]); + printf(" unsigned int number_of_nodes = %u;\n", lbpar_gpu.number_of_nodes); printf(" bool external_force_density = %d;\n", static_cast(lbpar_gpu.external_force_density)); printf(" float ext_force_density[3] = {%f, %f, %f};\n", diff --git a/src/core/grid_based_algorithms/lb_boundaries.cpp b/src/core/grid_based_algorithms/lb_boundaries.cpp index b7a71090c15..5239eae9978 100644 --- a/src/core/grid_based_algorithms/lb_boundaries.cpp +++ b/src/core/grid_based_algorithms/lb_boundaries.cpp @@ -181,9 +181,9 @@ void lb_init_boundaries() { std::vector host_boundary_index_list; std::size_t size_of_index; - for (int z = 0; z < int(lbpar_gpu.dim[2]); z++) { - for (int y = 0; y < int(lbpar_gpu.dim[1]); y++) { - for (int x = 0; x < int(lbpar_gpu.dim[0]); x++) { + for (unsigned z = 0; z < lbpar_gpu.dim[2]; z++) { + for (unsigned y = 0; y < lbpar_gpu.dim[1]; y++) { + for (unsigned x = 0; x < lbpar_gpu.dim[0]; x++) { auto const pos = static_cast(lbpar_gpu.agrid) * (Utils::Vector3d{1. * x, 1. * y, 1. * z} + Utils::Vector3d::broadcast(0.5)); @@ -198,12 +198,10 @@ void lb_init_boundaries() { host_boundary_node_list.resize(size_of_index); host_boundary_index_list.resize(size_of_index); host_boundary_node_list[number_of_boundnodes] = - x + lbpar_gpu.dim[0] * y + - lbpar_gpu.dim[0] * lbpar_gpu.dim[1] * z; - auto const boundary_number = - std::distance(lbboundaries.begin(), boundary.base()) - 1; - host_boundary_index_list[number_of_boundnodes] = - boundary_number + 1; + static_cast(x + lbpar_gpu.dim[0] * y + + lbpar_gpu.dim[0] * lbpar_gpu.dim[1] * z); + host_boundary_index_list[number_of_boundnodes] = static_cast( + std::distance(lbboundaries.begin(), boundary.base())); number_of_boundnodes++; } } @@ -257,10 +255,9 @@ void lb_init_boundaries() { [&pos](auto const lbb) { return lbb->shape().is_inside(pos); }); auto const index = get_linear_index(x, y, z, lblattice.halo_grid); if (boundary != boost::rend(lbboundaries)) { - auto const boundary_number = - std::distance(lbboundaries.begin(), boundary.base()) - 1; auto &node = lbfields[index]; - node.boundary = static_cast(boundary_number) + 1; + node.boundary = static_cast( + std::distance(lbboundaries.begin(), boundary.base())); node.slip_velocity = (*boundary)->velocity() * vel_conv; } else { lbfields[index].boundary = 0; diff --git a/src/core/io/writer/h5md_core.cpp b/src/core/io/writer/h5md_core.cpp index 2744f8b47e8..ba9bf5a92b3 100644 --- a/src/core/io/writer/h5md_core.cpp +++ b/src/core/io/writer/h5md_core.cpp @@ -368,7 +368,7 @@ void File::write(const ParticleRange &particles, double time, int step, datasets["particles/atoms/lees_edwards/normal/value"]); } - int const n_part_local = particles.size(); + auto const n_part_local = static_cast(particles.size()); // calculate count and offset int prefix = 0; // calculate prefix for write of the current process @@ -438,10 +438,11 @@ void File::write(const ParticleRange &particles, double time, int step, } void File::write_connectivity(const ParticleRange &particles) { + using index_type = MultiArray3i::index; MultiArray3i bond(boost::extents[0][0][0]); int particle_index = 0; for (auto const &p : particles) { - int nbonds_local = bond.shape()[1]; + auto nbonds_local = static_cast(bond.shape()[1]); for (auto const b : p.bonds()) { auto const partner_ids = b.partner_ids(); if (partner_ids.size() == 1) { @@ -454,7 +455,7 @@ void File::write_connectivity(const ParticleRange &particles) { particle_index++; } - int n_bonds_local = bond.shape()[1]; + auto const n_bonds_local = static_cast(bond.shape()[1]); int prefix_bonds = 0; BOOST_MPI_CHECK_RESULT( MPI_Exscan, (&n_bonds_local, &prefix_bonds, 1, MPI_INT, MPI_SUM, m_comm)); diff --git a/src/script_interface/GlobalContext.hpp b/src/script_interface/GlobalContext.hpp index cf72beb5d8c..1a6c2665cd7 100644 --- a/src/script_interface/GlobalContext.hpp +++ b/src/script_interface/GlobalContext.hpp @@ -90,6 +90,7 @@ class GlobalContext : public Context { std::shared_ptr node_local_context) : m_local_objects(), m_node_local_context(std::move(node_local_context)), m_is_head_node(callbacks.comm().rank() == 0), + // NOLINTNEXTLINE(bugprone-throw-keyword-missing) m_parallel_exception_handler(callbacks.comm()), cb_make_handle(&callbacks, [this](ObjectId id, const std::string &name, diff --git a/src/script_interface/LocalContext.hpp b/src/script_interface/LocalContext.hpp index 617cd321d1b..c925161d34f 100644 --- a/src/script_interface/LocalContext.hpp +++ b/src/script_interface/LocalContext.hpp @@ -49,6 +49,7 @@ class LocalContext : public Context { LocalContext(Utils::Factory factory, boost::mpi::communicator const &comm) : m_factory(std::move(factory)), m_is_head_node(comm.rank() == 0), + // NOLINTNEXTLINE(bugprone-throw-keyword-missing) m_parallel_exception_handler(comm) {} const Utils::Factory &factory() const { return m_factory; } diff --git a/src/shapes/src/Rhomboid.cpp b/src/shapes/src/Rhomboid.cpp index 902ca2416ac..345f1911dc8 100644 --- a/src/shapes/src/Rhomboid.cpp +++ b/src/shapes/src/Rhomboid.cpp @@ -57,7 +57,7 @@ void Rhomboid::calculate_dist(const Utils::Vector3d &pos, double &dist, auto const A = a * d; auto const B = b * d; auto const C = c * d; - if (op1(A, 0) & op2(B, 0) & op3(C, 0)) { + if (op1(A, 0) and op2(B, 0) and op3(C, 0)) { vec = d; dist = m_direction * vec.norm(); return true; @@ -92,7 +92,7 @@ void Rhomboid::calculate_dist(const Utils::Vector3d &pos, double &dist, Utils::Vector3d const &edge) { auto const A = (d * axis1) / dir1_dot_axis1; auto const B = (d * axis2) / dir2_dot_axis2; - if (op1(A, 0) & op2(B, 0)) { + if (op1(A, 0) and op2(B, 0)) { auto const tmp = (d * edge) / edge.norm2(); vec = d - edge * tmp; dist = m_direction * vec.norm(); diff --git a/src/utils/tests/serialization_test.cpp b/src/utils/tests/serialization_test.cpp index 684bf93cacb..d9271faf951 100644 --- a/src/utils/tests/serialization_test.cpp +++ b/src/utils/tests/serialization_test.cpp @@ -137,7 +137,9 @@ auto to_vector(std::stringstream &buffer_in) { std::vector buffer_out; buffer_in.seekg(0); while (!buffer_in.eof()) { - buffer_out.push_back(buffer_in.get()); + std::stringstream::char_type c = '\0'; + buffer_in.get(c); + buffer_out.push_back(c); } return buffer_out; } @@ -241,7 +243,8 @@ BOOST_AUTO_TEST_CASE(serialization_level_test) { for (std::size_t i = 0; i < Testing::N; ++i) { auto constexpr N = sizeof(Testing::T); auto const offset = sizeof(std::size_t) + i * N; - auto const array_data = sorted_view(buffer.begin() + offset); + auto const array_data = + sorted_view(buffer.begin() + static_cast(offset)); auto const array_data_ref = std::array{ {static_cast(Testing::values[i])}}; BOOST_TEST(array_data == array_data_ref, boost::test_tools::per_element());