Skip to content

Commit

Permalink
Make header files self-contained (#3990)
Browse files Browse the repository at this point in the history
Fixes #3977, closes #3905 (ESPResSo 4.2-dev now compiles on GCC 11)

Explicitly include used header files to make source files self-contained and improve portability (see C++ Core Guidelines: [SF.11: Header files should be self-contained](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#sf11-header-files-should-be-self-contained), [SF.10: Avoid dependencies on implicitly #included names](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#sf10-avoid-dependencies-on-implicitly-included-names)).

Description of changes:
* apply suggestions from IWYU 10
* add missing includes revealed by an implementation of the `compile_commands.json`-based algorithm outlined in #3977
* remove unused includes and reduce visibility of large header files:
   * `Particle.hpp`: from 332 includes to 245
   * `particle_data.hpp`: from 36 includes to 28
* address several issues:
   * remove a broken ifdef
   * register a unit test in CMake so it can run
   * remove unnecessary static globals in MMM1D GPU
   * dependency inversion for DPD interaction
  • Loading branch information
kodiakhq[bot] committed Nov 13, 2020
2 parents 4f04a5b + 633302b commit 78bf03d
Show file tree
Hide file tree
Showing 446 changed files with 2,540 additions and 873 deletions.
6 changes: 4 additions & 2 deletions src/core/AtomDecomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,13 @@

#include "AtomDecomposition.hpp"

#include <utils/Vector.hpp>

#include <boost/mpi/collectives/all_to_all.hpp>
#include <boost/serialization/vector.hpp>

#include <cassert>
#include <cstddef>
#include <limits>
#include <vector>

void AtomDecomposition::configure_neighbors() {
std::vector<Cell *> red_neighbors;
Expand Down
5 changes: 5 additions & 0 deletions src/core/AtomDecomposition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,17 @@
#ifndef ESPRESSO_ATOM_DECOMPOSITION_HPP
#define ESPRESSO_ATOM_DECOMPOSITION_HPP

#include "Particle.hpp"
#include "ParticleDecomposition.hpp"
#include "ghosts.hpp"

#include <utils/Span.hpp>
#include <utils/Vector.hpp>

#include <boost/mpi/communicator.hpp>
#include <boost/optional.hpp>

#include <utility>
#include <vector>

/**
Expand Down
2 changes: 2 additions & 0 deletions src/core/BondList.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
#include <boost/serialization/access.hpp>
#include <boost/serialization/array.hpp>
#include <boost/version.hpp>

#include <cstddef>
#include <type_traits>

/**
Expand Down
20 changes: 20 additions & 0 deletions src/core/CudaDeviceAllocator.hpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/*
* Copyright (C) 2010-2020 The ESPResSo project
*
* This file is part of ESPResSo.
*
* ESPResSo is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ESPResSo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ESPRESSO_CUDA_DEVICE_ALLOCATOR_HPP
#define ESPRESSO_CUDA_DEVICE_ALLOCATOR_HPP

Expand All @@ -12,6 +30,8 @@
#include <thrust/device_ptr.h>
#include <thrust/device_reference.h>

#include <cstddef>

/**
* @brief Allocator that uses CUDA to allocate GPU memory.
*
Expand Down
19 changes: 19 additions & 0 deletions src/core/CudaHostAllocator.cu
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
/*
* Copyright (C) 2010-2020 The ESPResSo project
*
* This file is part of ESPResSo.
*
* ESPResSo is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ESPResSo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "CudaHostAllocator.hpp"

#include <cuda.h>

#include <cstddef>
#include <stdexcept>

void cuda_malloc_host(void **p, std::size_t n) {
Expand Down
19 changes: 19 additions & 0 deletions src/core/CudaHostAllocator.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,25 @@
/*
* Copyright (C) 2010-2020 The ESPResSo project
*
* This file is part of ESPResSo.
*
* ESPResSo is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ESPResSo is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef ESPRESSO_CUDA_HOST_ALLOCATOR_HPP
#define ESPRESSO_CUDA_HOST_ALLOCATOR_HPP

#include <cstddef>
#include <type_traits>
#include <vector>

Expand Down
10 changes: 10 additions & 0 deletions src/core/DomainDecomposition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,10 @@

#include "DomainDecomposition.hpp"

#include "RuntimeErrorStream.hpp"
#include "errorhandling.hpp"

#include <utils/Vector.hpp>
#include <utils/index.hpp>
#include <utils/mpi/cart_comm.hpp>
#include <utils/mpi/sendrecv.hpp>
Expand All @@ -31,6 +33,14 @@
#include <boost/range/algorithm/reverse.hpp>
#include <boost/range/numeric.hpp>

#include <algorithm>
#include <array>
#include <cmath>
#include <cstddef>
#include <functional>
#include <iterator>
#include <utility>

/** Returns pointer to the cell which corresponds to the position if the
* position is in the nodes spatial domain otherwise a nullptr pointer.
*/
Expand Down
12 changes: 12 additions & 0 deletions src/core/DomainDecomposition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@
#include "BoxGeometry.hpp"
#include "LocalBox.hpp"

#include "Cell.hpp"
#include "Particle.hpp"
#include "ParticleList.hpp"
#include "ghosts.hpp"

#include <utils/Span.hpp>
#include <utils/Vector.hpp>

#include <boost/optional.hpp>

#include <vector>

/** @brief Structure containing the information about the cell grid used for
* domain decomposition.
*
Expand Down
4 changes: 2 additions & 2 deletions src/core/EspressoSystemInterface_cuda.cu
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,13 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#include <cuda.h>

#include "EspressoSystemInterface.hpp"
#include "cuda_interface.hpp"
#include "cuda_utils.hpp"
#include "errorhandling.hpp"

#include <cuda.h>

#if defined(OMPI_MPI_H) || defined(_MPI_H)
#error CU-file includes mpi.h! This should not happen!
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/core/MpiCallbacks.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,14 @@
#include <boost/mpi/collectives/all_reduce.hpp>
#include <boost/mpi/collectives/broadcast.hpp>
#include <boost/mpi/communicator.hpp>
#include <boost/optional.hpp>
#include <boost/range/algorithm/remove_if.hpp>

#include <functional>
#include <initializer_list>
#include <memory>
#include <tuple>
#include <type_traits>
#include <utility>

namespace Communication {
Expand Down
4 changes: 4 additions & 0 deletions src/core/Observable_stat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@

#include "bonded_interactions/bonded_interaction_data.hpp"

#include <utils/Span.hpp>

#include <cstddef>

Observable_stat::Observable_stat(size_t chunk_size) : m_chunk_size(chunk_size) {
// number of chunks for different interaction types
auto constexpr n_coulomb = 2;
Expand Down
4 changes: 3 additions & 1 deletion src/core/Observable_stat.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@
#include <utils/index.hpp>

#include <algorithm>
#include <utility>
#include <cassert>
#include <cstddef>
#include <functional>
#include <vector>

/** Observable for the pressure and energy. */
Expand Down
5 changes: 5 additions & 0 deletions src/core/PartCfg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@
#include "grid.hpp"
#include "particle_data.hpp"

#include <utils/Span.hpp>

#include <boost/algorithm/clamp.hpp>

#include <algorithm>
#include <cstddef>

void PartCfg::update() {
if (m_valid)
return;
Expand Down
1 change: 1 addition & 0 deletions src/core/PartCfg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include "Particle.hpp"

#include <cstddef>
#include <vector>

/**
Expand Down
13 changes: 13 additions & 0 deletions src/core/Particle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,19 @@ enum : uint8_t {
ROTATION_Z = 4u
};

#ifdef EXTERNAL_FORCES
/**
* \ref ParticleProperties::ext_flag "ext_flag" value for fixed coordinate
* @c coord.
*/
#define COORD_FIXED(coord) (2u << (coord))
/** \ref ParticleProperties::ext_flag "ext_flag" mask to check whether any of
* the coordinates is fixed. */
#define COORDS_FIX_MASK (COORD_FIXED(0) | COORD_FIXED(1) | COORD_FIXED(2))
#else
#define COORD_FIXED(coord) (0)
#endif

struct ParticleParametersSwimming {
bool swimming = false;
double f_swim = 0.;
Expand Down
3 changes: 3 additions & 0 deletions src/core/ParticleDecomposition.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@
#include <utils/Span.hpp>
#include <utils/Vector.hpp>

#include <boost/optional.hpp>
#include <boost/variant.hpp>

#include <vector>

struct RemovedParticle {
int id;
};
Expand Down
1 change: 1 addition & 0 deletions src/core/RuntimeError.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

#include <iostream>
#include <sstream>
#include <string>

namespace ErrorHandling {

Expand Down
3 changes: 2 additions & 1 deletion src/core/RuntimeErrorCollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,12 @@
*/
#include "RuntimeErrorCollector.hpp"

#include "communication.hpp"
#include <utils/mpi/gather_buffer.hpp>

#include <boost/mpi/collectives.hpp>

#include <algorithm>
#include <functional>
#include <iostream>
#include <sstream>
#include <utility>
Expand Down
8 changes: 4 additions & 4 deletions src/core/RuntimeErrorCollector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@
#ifndef ERROR_HANDLING_RUNTIMEERRORCOLLECTOR_HPP
#define ERROR_HANDLING_RUNTIMEERRORCOLLECTOR_HPP

#include <sstream>
#include <string>
#include <vector>
#include "RuntimeError.hpp"

#include <boost/mpi/communicator.hpp>

#include "RuntimeError.hpp"
#include <sstream>
#include <string>
#include <vector>

namespace ErrorHandling {

Expand Down
4 changes: 2 additions & 2 deletions src/core/RuntimeErrorStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@
#ifndef ERROR_HANDLING_RUNTIME_ERROR_STREAM_HPP
#define ERROR_HANDLING_RUNTIME_ERROR_STREAM_HPP

#include "RuntimeError.hpp"

#include <sstream>
#include <string>

#include "RuntimeError.hpp"

namespace ErrorHandling {

class RuntimeErrorCollector;
Expand Down
1 change: 0 additions & 1 deletion src/core/SystemInterface.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include "config.hpp"
#include <utils/Vector.hpp>
#include <vector>

/** @todo: Turn needsXY in getter/setter **/

Expand Down
2 changes: 2 additions & 0 deletions src/core/accumulators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
#include <boost/range/algorithm/remove_if.hpp>
#include <boost/range/numeric.hpp>

#include <algorithm>
#include <cassert>
#include <limits>
#include <vector>

namespace Accumulators {
Expand Down
14 changes: 11 additions & 3 deletions src/core/accumulators/Correlator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "Correlator.hpp"

#include "integrate.hpp"

#include <utils/Vector.hpp>
#include <utils/math/sqr.hpp>
#include <utils/serialization/multi_array.hpp>

#include <boost/archive/binary_iarchive.hpp>
Expand All @@ -29,10 +32,15 @@
#include <boost/serialization/string.hpp>
#include <boost/serialization/vector.hpp>

#include <utils/math/sqr.hpp>

#include <algorithm>
#include <limits>
#include <array>
#include <cassert>
#include <cmath>
#include <cstddef>
#include <functional>
#include <numeric>
#include <sstream>
#include <stdexcept>

namespace {
int min(int i, unsigned int j) { return std::min(i, static_cast<int>(j)); }
Expand Down
Loading

0 comments on commit 78bf03d

Please sign in to comment.