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

Enable clang-tidy checks #309

Merged
merged 11 commits into from
Sep 22, 2023
28 changes: 12 additions & 16 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ Checks: "*,
-misc-unused-parameters,
-hicpp-multiway-paths-covered,
-cert-err58-cpp,
-cppcoreguidelines-pro-bounds-constant-array-index,

google-readability-avoid-underscore-in-googletest-name,
google-upgrade-googletest-case,
Expand Down Expand Up @@ -71,7 +72,6 @@ Checks: "*,
-cppcoreguidelines-owning-memory,
-cppcoreguidelines-prefer-member-initializer,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-pro-type-cstyle-cast,
-cppcoreguidelines-pro-type-member-init,
Expand All @@ -91,7 +91,6 @@ Checks: "*,
-hicpp-member-init,
-hicpp-no-array-decay,
-hicpp-no-malloc,
-hicpp-signed-bitwise,
-hicpp-special-member-functions,
-hicpp-use-equals-default,
-hicpp-use-noexcept,
Expand All @@ -102,7 +101,6 @@ Checks: "*,
-llvm-header-guard,
-llvm-include-order,
-llvm-namespace-comment,
-misc-confusable-identifiers,
-misc-const-correctness,
-misc-non-private-member-variables-in-classes,
-modernize-avoid-c-arrays,
Expand All @@ -122,7 +120,6 @@ Checks: "*,
-readability-else-after-return,
-readability-function-cognitive-complexity,
-readability-identifier-length,
-readability-identifier-naming,
-readability-implicit-bool-conversion,
-readability-inconsistent-declaration-parameter-name,
-readability-isolate-declaration,
Expand All @@ -148,25 +145,24 @@ CheckOptions:
# - camel_Snake_Back
# - Camel_Snake_Case
# - aNy_CasE
#
# Entries that are commented out probably aren't needed but it should be verified
readability-identifier-naming.VariableCase: 'lower_case'
readability-identifier-naming.FunctionCase: 'Camel_Snake_Case'

# readability-identifier-naming.VariableCase: 'lower_case'
# readability-identifier-naming.FunctionCase: 'Camel_Snake_Case'
readability-identifier-naming.NamespaceCase: 'lower_case'
readability-identifier-naming.MacroDefinitionCase: 'UPPER_CASE'
readability-identifier-naming.TypedefCase: 'CamelCase'
readability-identifier-naming.TypeAliasCase: 'CamelCase'
readability-identifier-naming.EnumCase: 'CamelCase'
readability-identifier-naming.ConstantCase: 'lower_case'
# readability-identifier-naming.ConstantCase: 'lower_case'

readability-identifier-naming.ConstantPrefix: 'k_'
readability-identifier-naming.GlobalVariablePrefix: 'g_'
# readability-identifier-naming.ConstantPrefix: 'k_'
# readability-identifier-naming.GlobalVariablePrefix: 'g_'

readability-identifier-naming.ClassCase: 'CamelCase'
# readability-identifier-naming.MemberCase: 'lower_case'
# readability-identifier-naming.MethodCase: 'CamelCase'
readability-identifier-naming.PrivateMemberSuffix: '_'
readability-identifier-naming.PrivateMethodSuffix: '_'
# readability-identifier-naming.MemberCase: 'lower_case' # This entry might not be needed
# readability-identifier-naming.MethodCase: 'CamelCase' # This entry might not be needed
# readability-identifier-naming.PrivateMemberSuffix: '_'
# readability-identifier-naming.PrivateMethodSuffix: '_'

# readability-identifier-naming.StructCase: 'CamelCase'
hicpp-signed-bitwise.IgnorePositiveIntegerLiterals: 'true'
...
4 changes: 2 additions & 2 deletions src/dust/dust_cuda_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ TEST(tDUSTTestSputteringTimescale,

bool is_true;

is_true = testingUtilities::nearlyEqualDbl(k_fiducial_num, test_num, abs_diff, ulps_diff);
is_true = testing_utilities::nearlyEqualDbl(k_fiducial_num, test_num, abs_diff, ulps_diff);

EXPECT_TRUE(is_true) << "The fiducial value is: " << k_fiducial_num << std::endl
<< "The test value is: " << test_num << std::endl
Expand All @@ -61,7 +61,7 @@ TEST(tDUSTTestSputteringGrowthRate,

bool is_true;

is_true = testingUtilities::nearlyEqualDbl(k_fiducial_num, test_num, abs_diff, ulps_diff);
is_true = testing_utilities::nearlyEqualDbl(k_fiducial_num, test_num, abs_diff, ulps_diff);

EXPECT_TRUE(is_true) << "The fiducial value is: " << k_fiducial_num << std::endl
<< "The test value is: " << test_num << std::endl
Expand Down
2 changes: 1 addition & 1 deletion src/grid/grid3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ void Grid3D::Initialize(struct parameters *P)
#endif

#ifdef COSMOLOGY
H.OUTPUT_SCALE_FACOR = not P->scale_outputs_file[0] == '\0';
H.OUTPUT_SCALE_FACOR = not(P->scale_outputs_file[0] == '\0');
#endif

H.Output_Initial = true;
Expand Down
6 changes: 3 additions & 3 deletions src/hydro/hydro_cuda_tests.cu
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ TEST(tHYDROCalcDt3D, CorrectInputExpectCorrectOutput)
double absoluteDiff;
int64_t ulpsDiff;
bool areEqual;
areEqual = testingUtilities::nearlyEqualDbl(fiducialDt, testData, absoluteDiff, ulpsDiff);
areEqual = testing_utilities::nearlyEqualDbl(fiducialDt, testData, absoluteDiff, ulpsDiff);
EXPECT_TRUE(areEqual) << "The fiducial value is: " << fiducialDt << std::endl
<< "The test value is: " << testData << std::endl
<< "The absolute difference is: " << absoluteDiff << std::endl
Expand Down Expand Up @@ -106,7 +106,7 @@ TEST(tHYDROHydroInverseCrossingTime, CorrectInputExpectCorrectOutput)
velocityZ, cellSizeX, cellSizeY, cellSizeZ, gamma);

// Check results
testingUtilities::checkResults(fiducialInverseCrossingTime, testInverseCrossingTime, "inverse crossing time");
testing_utilities::checkResults(fiducialInverseCrossingTime, testInverseCrossingTime, "inverse crossing time");
}
// =============================================================================
// End of tests for the hydroInverseCrossingTime function
Expand Down Expand Up @@ -140,7 +140,7 @@ TEST(tMHDMhdInverseCrossingTime, CorrectInputExpectCorrectOutput)
magneticZ, cellSizeX, cellSizeY, cellSizeZ, gamma);

// Check results
testingUtilities::checkResults(fiducialInverseCrossingTime, testInverseCrossingTime, "inverse crossing time");
testing_utilities::checkResults(fiducialInverseCrossingTime, testInverseCrossingTime, "inverse crossing time");
}
// =============================================================================
// End of tests for the mhdInverseCrossingTime function
Expand Down
4 changes: 2 additions & 2 deletions src/io/io_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ TEST(tHYDROtMHDReadGridHdf5, RestartSlowWaveExpectCorrectOutput)
int const num_ranks = 4;

// Generate the data to read from
systemTest::SystemTestRunner initializer(false, true, false);
system_test::SystemTestRunner initializer(false, true, false);
initializer.numMpiRanks = num_ranks;
initializer.chollaLaunchParams.append(" tout=0.0 outstep=0.0");
initializer.launchCholla();
std::string const read_directory = initializer.getOutputDirectory() + "/";

// Reload data and run the test
systemTest::SystemTestRunner loadRun(false, true, false);
system_test::SystemTestRunner loadRun(false, true, false);
loadRun.numMpiRanks = num_ranks;
loadRun.chollaLaunchParams.append(" init=Read_Grid nfile=0 indir=" + read_directory);

Expand Down
8 changes: 4 additions & 4 deletions src/main_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#include "utils/testing_utilities.h"

/// This is the global variable to store the path to the root of Cholla
testingUtilities::GlobalString globalChollaRoot;
testingUtilities::GlobalString globalChollaBuild;
testingUtilities::GlobalString globalChollaMachine;
testingUtilities::GlobalString globalMpiLauncher;
testing_utilities::GlobalString globalChollaRoot;
testing_utilities::GlobalString globalChollaBuild;
testing_utilities::GlobalString globalChollaMachine;
testing_utilities::GlobalString globalMpiLauncher;
bool globalRunCholla;
bool globalCompareSystemTestResults;

Expand Down
9 changes: 5 additions & 4 deletions src/mhd/ct_electric_fields_tests.cu
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
* \brief Test fixture for tMHDCalculateCTElectricFields test suite
*
*/
// NOLINTNEXTLINE(readability-identifier-naming)
class tMHDCalculateCTElectricFields : public ::testing::Test
{
public:
Expand Down Expand Up @@ -116,9 +117,9 @@ class tMHDCalculateCTElectricFields : public ::testing::Test
for (size_t i = 0; i < fiducialData.size(); i++) {
int xid, yid, zid;
cuda_utilities::compute3DIndices(i, nx, ny, xid, yid, zid);
testingUtilities::checkResults(fiducialData.at(i), testCTElectricFields.at(i),
"value at i = " + std::to_string(i) + ", xid = " + std::to_string(xid) +
", yid = " + std::to_string(yid) + ", zid = " + std::to_string(zid));
testing_utilities::checkResults(fiducialData.at(i), testCTElectricFields.at(i),
"value at i = " + std::to_string(i) + ", xid = " + std::to_string(xid) +
", yid = " + std::to_string(yid) + ", zid = " + std::to_string(zid));
}
}
};
Expand Down Expand Up @@ -267,7 +268,7 @@ TEST(tMHDCTSlope, CorrectInputExpectCorrectOutput)
ASSERT_EQ(test_data.size(), fiducial_data.size());

for (size_t i = 0; i < test_data.size(); i++) {
testingUtilities::checkResults(fiducial_data.at(i), test_data.at(i), "");
testing_utilities::checkResults(fiducial_data.at(i), test_data.at(i), "");
}
}
// =============================================================================
Expand Down
2 changes: 1 addition & 1 deletion src/mhd/magnetic_divergence_tests.cu
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ TEST(tMHDGrid3DcheckMagneticDivergence, CorrectInputExpectCorrectOutput)
MPI_Finalize();
// Perform Comparison
Real const fiducialDivergence = 3.6318132783263106 / 1E15;
testingUtilities::checkResults(fiducialDivergence, max_magnetic_divergence, "maximum divergence");
testing_utilities::checkResults(fiducialDivergence, max_magnetic_divergence, "maximum divergence");
}
// =============================================================================
// End of tests for the magnetic field divergence functions
Expand Down
7 changes: 4 additions & 3 deletions src/mhd/magnetic_update_tests.cu
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
* \brief Test fixture for tMHDUpdateMagneticField3D test suite
*
*/
// NOLINTNEXTLINE(readability-identifier-naming)
class tMHDUpdateMagneticField3D : public ::testing::Test
{
public:
Expand Down Expand Up @@ -103,9 +104,9 @@ class tMHDUpdateMagneticField3D : public ::testing::Test
for (size_t i = 0; i < fiducialData.size(); i++) {
int xid, yid, zid;
cuda_utilities::compute3DIndices(i, nx, ny, xid, yid, zid);
testingUtilities::checkResults(fiducialData.at(i), destinationGrid.at(i),
"value at i = " + std::to_string(i) + ", xid = " + std::to_string(xid) +
", yid = " + std::to_string(yid) + ", zid = " + std::to_string(zid));
testing_utilities::checkResults(fiducialData.at(i), destinationGrid.at(i),
"value at i = " + std::to_string(i) + ", xid = " + std::to_string(xid) +
", yid = " + std::to_string(yid) + ", zid = " + std::to_string(zid));
}
}
};
Expand Down
2 changes: 1 addition & 1 deletion src/model/disk_ICs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -748,7 +748,7 @@ void Grid3D::Disk_3D(parameters p)
Real r_cool;

// MW model
DiskGalaxy galaxy = Galaxies::MW;
DiskGalaxy galaxy = Galaxies::MW; // NOLINT(cppcoreguidelines-slicing)
// M82 model Galaxies::M82;

M_vir = galaxy.getM_vir(); // viral mass in M_sun
Expand Down
8 changes: 5 additions & 3 deletions src/mpi/mpi_routines.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,23 +542,25 @@ void DomainDecompositionBLOCK(struct parameters *P, struct Header *H, int nx_gin

void Allocate_MPI_DeviceBuffers(struct Header *H)
{
int xbsize = 0, ybsize = 0, zbsize = 0;
int xbsize, ybsize, zbsize;
if (H->ny == 1 && H->nz == 1) {
xbsize = H->n_fields * H->n_ghost;
ybsize = 1;
zbsize = 1;
}
// 2D
if (H->ny > 1 && H->nz == 1) {
else if (H->ny > 1 && H->nz == 1) {
xbsize = H->n_fields * H->n_ghost * (H->ny - 2 * H->n_ghost);
ybsize = H->n_fields * H->n_ghost * (H->nx);
zbsize = 1;
}
// 3D
if (H->ny > 1 && H->nz > 1) {
else if (H->ny > 1 && H->nz > 1) {
xbsize = H->n_fields * H->n_ghost * (H->ny - 2 * H->n_ghost) * (H->nz - 2 * H->n_ghost);
ybsize = H->n_fields * H->n_ghost * (H->nx) * (H->nz - 2 * H->n_ghost);
zbsize = H->n_fields * H->n_ghost * (H->nx) * (H->ny);
} else {
throw std::runtime_error("MPI buffer size failed to set.");
}

x_buffer_length = xbsize;
Expand Down
26 changes: 13 additions & 13 deletions src/particles/feedback_CIC_gpu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,18 @@

#define TPB_FEEDBACK 128
#define FEED_INFO_N 6
#define i_RES 1
#define i_UNRES 2
#define i_ENERGY 3
#define i_MOMENTUM 4
#define i_UNRES_ENERGY 5
#define I_RES 1 // unused
#define I_UNRES 2 // unused
#define I_ENERGY 3 // unused
#define I_MOMENTUM 4 // unused
#define I_UNRES_ENERGY 5 // used

typedef curandStateMRG32k3a_t feedback_prng_t;
// typedef curandStatePhilox4_32_10_t feedback_prng_t;
typedef curandStateMRG32k3a_t FeedbackPrng;
// typedef curandStatePhilox4_32_10_t FeedbackPrng;

namespace supernova
{
feedback_prng_t* randStates;
FeedbackPrng* randStates;
part_int_t n_states;
Real *dev_snr, snr_dt, time_sn_start, time_sn_end;
int snr_n;
Expand All @@ -48,7 +48,7 @@ __device__ double atomicMax(double* address, double val)
}
#endif // O_HIP

__global__ void initState_kernel(unsigned int seed, feedback_prng_t* states)
__global__ void initState_kernel(unsigned int seed, FeedbackPrng* states)
{
int id = blockIdx.x * blockDim.x + threadIdx.x;
curand_init(seed, id, 0, &states[id]);
Expand Down Expand Up @@ -131,7 +131,7 @@ void supernova::initState(struct parameters* P, part_int_t n_local, Real allocat

// Now initialize the poisson random number generator state.
n_states = n_local * allocation_factor;
cudaMalloc((void**)&randStates, n_states * sizeof(feedback_prng_t));
cudaMalloc((void**)&randStates, n_states * sizeof(FeedbackPrng));

int ngrid = (n_states - 1) / TPB_FEEDBACK + 1;
dim3 grid(ngrid);
Expand Down Expand Up @@ -233,7 +233,7 @@ __global__ void Cluster_Feedback_Kernel(part_int_t n_local, part_int_t* id, Real
Real xMax, Real yMax, Real zMax, Real dx, Real dy, Real dz, int nx_g, int ny_g,
int nz_g, int n_ghost, Real t, Real dt, Real* dti, Real* info, Real* density,
Real* gasEnergy, Real* energy, Real* momentum_x, Real* momentum_y,
Real* momentum_z, Real gamma, feedback_prng_t* states, Real* prev_dens,
Real* momentum_z, Real gamma, FeedbackPrng* states, Real* prev_dens,
int* prev_N, short direction, Real* dev_snr, Real snr_dt, Real time_sn_start,
Real time_sn_end, int n_step)
{
Expand Down Expand Up @@ -308,7 +308,7 @@ __global__ void Cluster_Feedback_Kernel(part_int_t n_local, part_int_t* id, Real

// N = (int) (average_num_sn + 0.5);

feedback_prng_t state; // = states[0]; // load initial state
FeedbackPrng state; // = states[0]; // load initial state

curand_init(42, 0, 0, &state);
unsigned long long skip = n_step * 10000 + id[gtid];
Expand Down Expand Up @@ -543,7 +543,7 @@ __global__ void Cluster_Feedback_Kernel(part_int_t n_local, part_int_t* id, Real
// atomicAdd( &energy[indx], e );
// atomicAdd( &density[indx], d );

s_info[FEED_INFO_N * tid + i_UNRES_ENERGY] +=
s_info[FEED_INFO_N * tid + I_UNRES_ENERGY] +=
direction * (px * px + py * py + pz * pz) / 2 / density[indx] * dV;

if (abs(momentum_x[indx] / density[indx]) >= C_L) {
Expand Down
8 changes: 4 additions & 4 deletions src/reconstruction/plmc_cuda_tests.cu
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ TEST(tHYDROPlmcReconstructor, CorrectInputExpectCorrectOutput)
? 0.0
: fiducial_interface_left.at(direction)[i];

testingUtilities::checkResults(
testing_utilities::checkResults(
fiducial_val, test_val,
"left interface at i=" + std::to_string(i) + ", in direction " + std::to_string(direction));

Expand All @@ -161,7 +161,7 @@ TEST(tHYDROPlmcReconstructor, CorrectInputExpectCorrectOutput)
? 0.0
: fiducial_interface_right.at(direction)[i];

testingUtilities::checkResults(
testing_utilities::checkResults(
fiducial_val, test_val,
"right interface at i=" + std::to_string(i) + ", in direction " + std::to_string(direction));
}
Expand Down Expand Up @@ -262,7 +262,7 @@ TEST(tMHDPlmcReconstructor, CorrectInputExpectCorrectOutput)
? 0.0
: fiducial_interface_left.at(direction)[i];

testingUtilities::checkResults(
testing_utilities::checkResults(
fiducial_val, test_val,
"left interface at i=" + std::to_string(i) + ", in direction " + std::to_string(direction));

Expand All @@ -272,7 +272,7 @@ TEST(tMHDPlmcReconstructor, CorrectInputExpectCorrectOutput)
? 0.0
: fiducial_interface_right.at(direction)[i];

testingUtilities::checkResults(
testing_utilities::checkResults(
fiducial_val, test_val,
"right interface at i=" + std::to_string(i) + ", in direction " + std::to_string(direction));
}
Expand Down