Skip to content

Commit

Permalink
Merge pull request #310 from helenarichie/dev-clang-naming
Browse files Browse the repository at this point in the history
Turn on clang-tidy check for function naming and change function names to pass check
  • Loading branch information
evaneschneider authored Sep 22, 2023
2 parents 8c555b6 + 1c2fb85 commit c345d17
Show file tree
Hide file tree
Showing 35 changed files with 872 additions and 828 deletions.
11 changes: 7 additions & 4 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ Checks: "*,
google-readability-avoid-underscore-in-googletest-name,
google-upgrade-googletest-case,
-*,
readability-identifier-naming,
-bugprone-implicit-widening-of-multiplication-result,
-bugprone-narrowing-conversions,
-cert-env33-c,
Expand Down Expand Up @@ -147,11 +150,11 @@ CheckOptions:
# - aNy_CasE

# readability-identifier-naming.VariableCase: 'lower_case'
# readability-identifier-naming.FunctionCase: 'Camel_Snake_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.MacroDefinitionCase: 'UPPER_CASE'
# readability-identifier-naming.TypedefCase: 'CamelCase'
# readability-identifier-naming.TypeAliasCase: 'CamelCase'
readability-identifier-naming.EnumCase: 'CamelCase'
# readability-identifier-naming.ConstantCase: 'lower_case'

Expand Down
23 changes: 23 additions & 0 deletions clang-tidy-runner.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash

# Description:
# Run clang-tidy on all build types in parallel. Note that this spawns 2x the
# number of build types threads since each type has a thread for the CPU code
# and a thread for the GPU code

# If ctrl-c is sent trap it and kill all clang-tidy processes
trap "kill -- -$$" EXIT

# cd into the Cholla directory. Default to ${HOME}/Code/cholla
cholla_path=${1:-${HOME}/Code/cholla}
cd ${cholla_path}

# Run all clang-tidy build types in parallel
builds=( hydro gravity disk particles cosmology mhd dust)
for build in "${builds[@]}"
do
make tidy TYPE=$build &
done

# Wait for clang-tidy to finish
wait
6 changes: 3 additions & 3 deletions src/analysis/feedback_analysis_gpu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
#define MIN_DENSITY (0.01 * MP * MU * LENGTH_UNIT * LENGTH_UNIT * LENGTH_UNIT / MASS_UNIT) // 148279.7
#define TPB_ANALYSIS 1024

__device__ void warpReduce(volatile Real *buff, size_t tid)
__device__ void Warp_Reduce(volatile Real *buff, size_t tid)
{
if (TPB_ANALYSIS >= 64) {
buff[tid] += buff[tid + 32];
Expand Down Expand Up @@ -125,8 +125,8 @@ void __global__ Reduce_Tubulence_kernel_2(Real *input_m, Real *input_v, Real *ou
}

if (tid < 32) {
warpReduce(s_mass, tid);
warpReduce(s_vel, tid);
Warp_Reduce(s_mass, tid);
Warp_Reduce(s_vel, tid);
}
__syncthreads();

Expand Down
36 changes: 18 additions & 18 deletions src/global/global.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ void Set_Gammas(Real gamma_in)
CHOLLA_ASSERT(gama > 1.0, "Gamma must be greater than one.");
}

/*! \fn double get_time(void)
/*! \fn double Get_Time(void)
* \brief Returns the current clock time. */
double get_time(void)
double Get_Time(void)
{
struct timeval timer;
gettimeofday(&timer, NULL);
return timer.tv_sec + 1.0e-6 * timer.tv_usec;
}

/*! \fn int sgn
/*! \fn int Sgn
* \brief Mathematical sign function. Returns sign of x. */
int sgn(Real x)
int Sgn(Real x)
{
if (x < 0) {
return -1;
Expand All @@ -60,7 +60,7 @@ int sgn(Real x)
#ifndef CUDA
/*! \fn Real calc_eta(Real cW[], Real gamma)
* \brief Calculate the eta value for the H correction. */
Real calc_eta(Real cW[], Real gamma)
Real Calc_Eta(Real cW[], Real gamma)
{
Real pl, pr, al, ar;

Expand All @@ -76,9 +76,9 @@ Real calc_eta(Real cW[], Real gamma)
}
#endif // NO CUDA

/*! \fn char trim(char *s)
/*! \fn char Trim(char *s)
* \brief Gets rid of trailing and leading whitespace. */
char *trim(char *s)
char *Trim(char *s)
{
/* Initialize start, end pointers */
char *s1 = s, *s2 = &s[strlen(s) - 1];
Expand All @@ -105,10 +105,10 @@ const std::set<const char *> optionalParams = {
"delta", "nzr", "nxr", "H0", "Omega_M", "Omega_L", "Init_redshift",
"End_redshift", "tile_length", "n_proc_x", "n_proc_y", "n_proc_z"};

/*! \fn int is_param_valid(char *name);
/*! \fn int Is_Param_Valid(char *name);
* \brief Verifies that a param is valid (even if not needed). Avoids
* "warnings" in output. */
int is_param_valid(const char *param_name)
int Is_Param_Valid(const char *param_name)
{
// for (auto optionalParam = optionalParams.begin(); optionalParam != optionalParams.end(); ++optionalParam) {
for (const auto *optionalParam : optionalParams) {
Expand All @@ -119,11 +119,11 @@ int is_param_valid(const char *param_name)
return 0;
}

void parse_param(char *name, char *value, struct parameters *parms);
void Parse_Param(char *name, char *value, struct parameters *parms);

/*! \fn void parse_params(char *param_file, struct parameters * parms);
/*! \fn void Parse_Params(char *param_file, struct parameters * parms);
* \brief Reads the parameters in the given file into a structure. */
void parse_params(char *param_file, struct parameters *parms, int argc, char **argv)
void Parse_Params(char *param_file, struct parameters *parms, int argc, char **argv)
{
int buf;
char *s, buff[256];
Expand Down Expand Up @@ -160,8 +160,8 @@ void parse_params(char *param_file, struct parameters *parms, int argc, char **a
} else {
strncpy(value, s, MAXLEN);
}
trim(value);
parse_param(name, value, parms);
Trim(value);
Parse_Param(name, value, parms);
}
/* Close file */
fclose(fp);
Expand All @@ -181,14 +181,14 @@ void parse_params(char *param_file, struct parameters *parms, int argc, char **a
} else {
strncpy(value, s, MAXLEN);
}
parse_param(name, value, parms);
Parse_Param(name, value, parms);
chprintf("Override with %s=%s\n", name, value);
}
}

/*! \fn void parse_param(char *name,char *value, struct parameters *parms);
/*! \fn void Parse_Param(char *name,char *value, struct parameters *parms);
* \brief Parses and sets a single param based on name and value. */
void parse_param(char *name, char *value, struct parameters *parms)
void Parse_Param(char *name, char *value, struct parameters *parms)
{
/* Copy into correct entry in parameters struct */
if (strcmp(name, "nx") == 0) {
Expand Down Expand Up @@ -437,7 +437,7 @@ void parse_param(char *name, char *value, struct parameters *parms)
strncpy(parms->skewersdir, value, MAXLEN);
#endif
#endif
} else if (!is_param_valid(name)) {
} else if (!Is_Param_Valid(name)) {
chprintf("WARNING: %s/%s: Unknown parameter/value pair!\n", name, value);
}
}
10 changes: 5 additions & 5 deletions src/global/global.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,16 +162,16 @@ extern void Set_Gammas(Real gamma_in);

/*! \fn double get_time(void)
* \brief Returns the current clock time. */
extern double get_time(void);
extern double Get_Time(void);

/*! \fn int sgn
* \brief Mathematical sign function. Returns sign of x. */
extern int sgn(Real x);
extern int Sgn(Real x);

#ifndef CUDA
/*! \fn Real calc_eta(Real cW[], Real gamma)
* \brief Calculate the eta value for the H correction. */
extern Real calc_eta(Real cW[], Real gamma);
extern Real Calc_Eta(Real cW[], Real gamma);
#endif

struct parameters {
Expand Down Expand Up @@ -327,11 +327,11 @@ struct parameters {

/*! \fn void parse_params(char *param_file, struct parameters * parms);
* \brief Reads the parameters in the given file into a structure. */
extern void parse_params(char *param_file, struct parameters *parms, int argc, char **argv);
extern void Parse_Params(char *param_file, struct parameters *parms, int argc, char **argv);

/*! \fn int is_param_valid(char *name);
* \brief Verifies that a param is valid (even if not needed). Avoids
* "warnings" in output. */
extern int is_param_valid(const char *name);
extern int Is_Param_Valid(const char *name);

#endif // GLOBAL_H
20 changes: 10 additions & 10 deletions src/gravity/paris/ParisPeriodic.cu
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "ParisPeriodic.hpp"

__host__ __device__ static inline double sqr(const double x) { return x * x; }
__host__ __device__ static inline double Sqr(const double x) { return x * x; }

ParisPeriodic::ParisPeriodic(const int n[3], const double lo[3], const double hi[3], const int m[3], const int id[3])
: ni_(n[0]),
Expand All @@ -16,9 +16,9 @@ ParisPeriodic::ParisPeriodic(const int n[3], const double lo[3], const double hi
ddk_(2.0 * double(n[2] - 1) / (hi[2] - lo[2])),
#elif defined PARIS_5PT
nk_(n[2]),
ddi_(sqr(double(n[0] - 1) / (hi[0] - lo[0])) / 6.0),
ddj_(sqr(double(n[1] - 1) / (hi[1] - lo[1])) / 6.0),
ddk_(sqr(double(n[2] - 1) / (hi[2] - lo[2])) / 6.0),
ddi_(Sqr(double(n[0] - 1) / (hi[0] - lo[0])) / 6.0),
ddj_(Sqr(double(n[1] - 1) / (hi[1] - lo[1])) / 6.0),
ddk_(Sqr(double(n[2] - 1) / (hi[2] - lo[2])) / 6.0),
#else
ddi_{2.0 * M_PI * double(n[0] - 1) / (double(n[0]) * (hi[0] - lo[0]))},
ddj_{2.0 * M_PI * double(n[1] - 1) / (double(n[1]) * (hi[1] - lo[1]))},
Expand Down Expand Up @@ -52,9 +52,9 @@ void ParisPeriodic::solve(const size_t bytes, double *const density, double *con
[=] __device__(const int i, const int j, const int k, const cufftDoubleComplex b) {
if (i || j || k) {
#ifdef PARIS_3PT
const double i2 = sqr(sin(double(min(i, ni - i)) * si) * ddi);
const double j2 = sqr(sin(double(min(j, nj - j)) * sj) * ddj);
const double k2 = sqr(sin(double(k) * sk) * ddk);
const double i2 = Sqr(sin(double(min(i, ni - i)) * si) * ddi);
const double j2 = Sqr(sin(double(min(j, nj - j)) * sj) * ddj);
const double k2 = Sqr(sin(double(k) * sk) * ddk);
#elif defined PARIS_5PT
const double ci = cos(double(min(i, ni - i)) * si);
const double cj = cos(double(min(j, nj - j)) * sj);
Expand All @@ -63,9 +63,9 @@ void ParisPeriodic::solve(const size_t bytes, double *const density, double *con
const double j2 = ddj * (2.0 * cj * cj - 16.0 * cj + 14.0);
const double k2 = ddk * (2.0 * ck * ck - 16.0 * ck + 14.0);
#else
const double i2 = sqr(double(min(i, ni - i)) * ddi);
const double j2 = sqr(double(min(j, nj - j)) * ddj);
const double k2 = sqr(double(k) * ddk);
const double i2 = Sqr(double(min(i, ni - i)) * ddi);
const double j2 = Sqr(double(min(j, nj - j)) * ddj);
const double k2 = Sqr(double(k) * ddk);
#endif
const double d = -1.0 / (i2 + j2 + k2);
return cufftDoubleComplex{d * b.x, d * b.y};
Expand Down
28 changes: 14 additions & 14 deletions src/gravity/paris/PoissonZero3DBlockedGPU.cu
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

static constexpr double sqrt2 = 0.4142135623730950488016887242096980785696718753769480731766797379;

static inline __host__ __device__ double sqr(const double x) { return x * x; }
static inline __host__ __device__ double Sqr(const double x) { return x * x; }

PoissonZero3DBlockedGPU::PoissonZero3DBlockedGPU(const int n[3], const double lo[3], const double hi[3], const int m[3],
const int id[3])
Expand All @@ -20,9 +20,9 @@ PoissonZero3DBlockedGPU::PoissonZero3DBlockedGPU(const int n[3], const double lo
ddj_(2.0 * double(n[1] - 1) / (hi[1] - lo[1])),
ddk_(2.0 * double(n[2] - 1) / (hi[2] - lo[2])),
#elif defined PARIS_GALACTIC_5PT
ddi_(sqr(double(n[0] - 1) / (hi[0] - lo[0])) / 6.0),
ddj_(sqr(double(n[1] - 1) / (hi[1] - lo[1])) / 6.0),
ddk_(sqr(double(n[2] - 1) / (hi[2] - lo[2])) / 6.0),
ddi_(Sqr(double(n[0] - 1) / (hi[0] - lo[0])) / 6.0),
ddj_(Sqr(double(n[1] - 1) / (hi[1] - lo[1])) / 6.0),
ddk_(Sqr(double(n[2] - 1) / (hi[2] - lo[2])) / 6.0),
#else
ddi_{M_PI * double(n[0] - 1) / (double(n[0]) * (hi[0] - lo[0]))},
ddj_{M_PI * double(n[1] - 1) / (double(n[1]) * (hi[1] - lo[1]))},
Expand All @@ -38,7 +38,7 @@ PoissonZero3DBlockedGPU::PoissonZero3DBlockedGPU(const int n[3], const double lo
nj_(n[1]),
nk_(n[2])
{
mq_ = int(round(sqrt(mk_)));
mq_ = int(round(Sqr(mk_)));
while (mk_ % mq_) {
mq_--;
}
Expand Down Expand Up @@ -110,7 +110,7 @@ PoissonZero3DBlockedGPU::~PoissonZero3DBlockedGPU()
MPI_Comm_free(&commK_);
}

void print(const char *const title, const int ni, const int nj, const int nk, const double *const v)
void Print(const char *const title, const int ni, const int nj, const int nk, const double *const v)
{
printf("%s:\n", title);
for (int i = 0; i < ni; i++) {
Expand Down Expand Up @@ -302,15 +302,15 @@ void PoissonZero3DBlockedGPU::solve(const long bytes, double *const density, dou
const double si = M_PI / double(ni + ni);
const double sj = M_PI / double(nj + nj);
const double sk = M_PI / double(nk + nk);
const double iin = sqr(sin(double(ni) * si) * ddi);
const double iin = Sqr(sin(double(ni) * si) * ddi);
#elif defined PARIS_GALACTIC_5PT
const double si = M_PI / double(ni);
const double sj = M_PI / double(nj);
const double sk = M_PI / double(nk);
const double cin = cos(double(ni) * si);
const double iin = ddi * (2.0 * cin * cin - 16.0 * cin + 14.0);
#else
const double iin = sqr(double(ni) * ddi);
const double iin = Sqr(double(ni) * ddi);
#endif
const int jLo = (idi * mp + idp) * djp;
const int kLo = (idj * mq + idq) * dkq;
Expand All @@ -319,7 +319,7 @@ void PoissonZero3DBlockedGPU::solve(const long bytes, double *const density, dou
const int kj = (k * djp + j) * ni;
const int kj2 = (k * djp + j) * ni2;
#ifdef PARIS_GALACTIC_3PT
const double jjkk = sqr(sin(double(jLo + j + 1) * sj) * ddj) + sqr(sin(double(kLo + k + 1) * sk) * ddk);
const double jjkk = Sqr(sin(double(jLo + j + 1) * sj) * ddj) + Sqr(sin(double(kLo + k + 1) * sk) * ddk);
#elif defined PARIS_GALACTIC_5PT
const double cj = cos(double(jLo + j + 1) * sj);
const double jj = ddj * (2.0 * cj * cj - 16.0 * cj + 14.0);
Expand All @@ -328,18 +328,18 @@ void PoissonZero3DBlockedGPU::solve(const long bytes, double *const density, dou
const double jjkk = jj + kk;
#else
const double jjkk =
sqr(double(jLo + j + 1) * ddj) + sqr(double(kLo + k + 1) * ddk);
Sqr(double(jLo + j + 1) * ddj) + Sqr(double(kLo + k + 1) * ddk);
#endif
if (i == 0) {
ua[kj] = -2.0 * ub[kj2] / (iin + jjkk);
} else {
#ifdef PARIS_GALACTIC_3PT
const double ii = sqr(sin(double(i) * si) * ddi);
const double ii = Sqr(sin(double(i) * si) * ddi);
#elif defined PARIS_GALACTIC_5PT
const double ci = cos(double(i) * si);
const double ii = ddi * (2.0 * ci * ci - 16.0 * ci + 14.0);
#else
const double ii = sqr(double(i) * ddi);
const double ii = Sqr(double(i) * ddi);
#endif
if (i + i == ni) {
ua[kj + ni / 2] = -2.0 * ub[kj2 + ni] / (ii + jjkk);
Expand All @@ -349,12 +349,12 @@ void PoissonZero3DBlockedGPU::solve(const long bytes, double *const density, dou
double wa, wb;
sincospi(double(i) / double(ni + ni), &wb, &wa);
#ifdef PARIS_GALACTIC_3PT
const double nii = sqr(sin(double(ni - i) * si) * ddi);
const double nii = t(sin(double(ni - i) * si) * ddi);
#elif defined PARIS_GALACTIC_5PT
const double cni = cos(double(ni - i) * si);
const double nii = ddi * (2.0 * cni * cni - 16.0 * cni + 14.0);
#else
const double nii = sqr(double(ni - i) * ddi);
const double nii = Sqr(double(ni - i) * ddi);
#endif
const double aai = -(wa * ai + wb * bi) / (nii + jjkk);
const double bbi = (wa * bi - wb * ai) / (ii + jjkk);
Expand Down
4 changes: 2 additions & 2 deletions src/gravity/potential_paris_3D.cu
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
#include "../io/io.h"
#include "../utils/gpu.hpp"

static void __attribute__((unused))
printDiff(const Real *p, const Real *q, const int ng, const int nx, const int ny, const int nz, const bool plot = false)
static void __attribute__((unused)) Print_Diff(const Real *p, const Real *q, const int ng, const int nx, const int ny,
const int nz, const bool plot = false)
{
Real dMax = 0, dSum = 0, dSum2 = 0;
Real qMax = 0, qSum = 0, qSum2 = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/hydro/hydro_cuda_tests.cu
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ TEST(tHYDROHydroInverseCrossingTime, CorrectInputExpectCorrectOutput)
velocityZ, cellSizeX, cellSizeY, cellSizeZ, gamma);

// Check results
testing_utilities::checkResults(fiducialInverseCrossingTime, testInverseCrossingTime, "inverse crossing time");
testing_utilities::Check_Results(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
testing_utilities::checkResults(fiducialInverseCrossingTime, testInverseCrossingTime, "inverse crossing time");
testing_utilities::Check_Results(fiducialInverseCrossingTime, testInverseCrossingTime, "inverse crossing time");
}
// =============================================================================
// End of tests for the mhdInverseCrossingTime function
Expand Down
Loading

0 comments on commit c345d17

Please sign in to comment.