Skip to content

Commit

Permalink
[cpp] Apply clang-tidy auto fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
tobiashienzsch committed Sep 17, 2024
1 parent 8bdc805 commit a8afa87
Show file tree
Hide file tree
Showing 7 changed files with 271 additions and 221 deletions.
47 changes: 32 additions & 15 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,58 @@
Checks: >
*-,
-bugprone-*,
-bugprone-macro-parentheses,
bugprone-*,
-bugprone-branch-clone,
-bugprone-easily-swappable-parameters,
-bugprone-exception-escape,
-bugprone-macro-parentheses,
-bugprone-narrowing-conversions,
-bugprone-signed-char-misuse,
-cert-*,
cert-*,
-cert-dcl03-c,
-cert-err33-c,
-cert-err58-cpp,
-cert-oop54-cpp,
-cert-str34-c,
-clang-analyzer-*,
-clang-diagnostics-*,
-concurrency-*,
clang-analyzer-*,
clang-diagnostics-*,
concurrency-*,
-cppcoreguidelines-*,
cppcoreguidelines-*,
-cppcoreguidelines-avoid-magic-numbers,
-cppcoreguidelines-avoid-const-or-ref-data-members,
-cppcoreguidelines-pro-type-cstyle-cast,
-cppcoreguidelines-narrowing-conversions,
-cppcoreguidelines-pro-bounds-array-to-pointer-decay,
-cppcoreguidelines-pro-bounds-constant-array-index,
-cppcoreguidelines-pro-bounds-pointer-arithmetic,
-cppcoreguidelines-owning-memory,
-hicpp-*,
hicpp-*,
-hicpp-no-array-decay,
-hicpp-signed-bitwise,
-misc-*,
-modernize-*,
misc-*,
-misc-include-cleaner,
-misc-use-anonymous-namespace,
modernize-*,
performance-*,
-readability-*,
-readability-identifier-naming,
-readability-const-return-type,
readability-*,
-readability-function-cognitive-complexity,
-readability-identifier-length,
-readability-identifier-naming,
-readability-magic-numbers,
-*-avoid-c-arrays,
-*-no-malloc,
-*-non-private-member-variables-in-classes,
-*-special-member-functions,
-*-static-assert,
-*-vararg,
WarningsAsErrors: "*"
FormatStyle: none
Expand Down
11 changes: 6 additions & 5 deletions src/cpp/main_2d/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

struct Arguments {
std::string engine{"native"};
std::string simDir{};
std::string simDir;
std::string out{"out.h5"};
};

int main(int argc, char** argv) {
auto main(int argc, char** argv) -> int {
auto app = CLI::App{"pffdtd-2d"};
auto args = Arguments{};
app.add_option("-e,--engine", args.engine);
Expand All @@ -42,17 +42,18 @@ int main(int argc, char** argv) {
fmt::println("Using engine: NATIVE");
auto const engine = pffdtd::EngineNative{};
return engine(sim);
} else if (args.engine == "sycl") {
}
if (args.engine == "sycl") {
#if defined(PFFDTD_HAS_SYCL)
fmt::println("Using engine: SYCL");
auto const engine = pffdtd::EngineSYCL{};
return engine(sim);
#else
pffdtd::raisef<std::runtime_error>("pffdtd built without SYCL support");
#endif
} else {
pffdtd::raisef<std::runtime_error>("invalid engine '{}'", args.engine);
}

pffdtd::raisef<std::runtime_error>("invalid engine '{}'", args.engine);
}();

auto results = pffdtd::H5FWriter{simDir / args.out};
Expand Down
134 changes: 68 additions & 66 deletions src/cpp/main_3d/engine_cpu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,25 @@ namespace {
// function that does freq-dep RLC boundaries. See 2016 ISMRA paper and
// accompanying webpage (slightly improved here)
template<typename Float>
double process_bnl_pts_fd(
auto process_bnl_pts_fd(
Float* u0b,
Float const* u2b,
Float const* ssaf_bnl,
int8_t const* mat_bnl,
int64_t Nbl,
int8_t* Mb,
int8_t const* Mb,
Float lo2,
Float* vh1,
Float* gh1,
MatQuad<Float> const* mat_quads,
Float const* mat_beta
) {
) -> double {
auto const start = omp_get_wtime();
#pragma omp parallel for schedule(static)
for (int64_t nb = 0; nb < Nbl; nb++) {
Float _1 = 1.0;
Float _2 = 2.0;
int32_t k = mat_bnl[nb];
Float _1 = 1.0;
Float _2 = 2.0;
int32_t const k = mat_bnl[nb];

Float lo2Kbg = lo2 * ssaf_bnl[nb] * mat_beta[k];
Float fac = _2 * lo2 * ssaf_bnl[nb] / (_1 + lo2Kbg);
Expand All @@ -52,8 +52,8 @@ double process_bnl_pts_fd(

Float vh1nb[MMb];
for (int8_t m = 0; m < Mb[k]; m++) {
int64_t nbm = nb * MMb + m;
int32_t mbk = k * MMb + m;
int64_t const nbm = nb * MMb + m;
int32_t const mbk = k * MMb + m;
MatQuad<Float> const* tm = &(mat_quads[mbk]);
vh1nb[m] = vh1[nbm];
u0bint -= fac * (_2 * (tm->bDh) * vh1nb[m] - (tm->bFh) * gh1[nbm]);
Expand All @@ -62,8 +62,8 @@ double process_bnl_pts_fd(
Float du = u0bint - u2bint;

for (int8_t m = 0; m < Mb[k]; m++) {
int64_t nbm = nb * MMb + m;
int32_t mbk = k * MMb + m;
int64_t const nbm = nb * MMb + m;
int32_t const mbk = k * MMb + m;
MatQuad<Float> const* tm = &(mat_quads[mbk]);
Float vh0nbm = (tm->b) * du + (tm->bd) * vh1nb[m] - _2 * (tm->bFh) * gh1[nbm];
gh1[nbm] += (vh0nbm + vh1nb[m]) / _2;
Expand All @@ -79,17 +79,17 @@ double process_bnl_pts_fd(

auto run(Simulation3D& sd) -> double {
// keep local ints, scalars
int64_t Ns = sd.Ns;
int64_t Nr = sd.Nr;
int64_t Nt = sd.Nt;
int64_t Npts = sd.Npts;
int64_t Nx = sd.Nx;
int64_t Ny = sd.Ny;
int64_t Nz = sd.Nz;
int64_t Nb = sd.Nb;
int64_t Nbl = sd.Nbl;
int64_t Nba = sd.Nba;
int8_t* Mb = sd.Mb;
int64_t const Ns = sd.Ns;
int64_t const Nr = sd.Nr;
int64_t const Nt = sd.Nt;
int64_t const Npts = sd.Npts;
int64_t const Nx = sd.Nx;
int64_t const Ny = sd.Ny;
int64_t const Nz = sd.Nz;
int64_t const Nb = sd.Nb;
int64_t const Nbl = sd.Nbl;
int64_t const Nba = sd.Nba;
int8_t* Mb = sd.Mb;

// keep local copies of pointers (style choice)
int64_t* bn_ixyz = sd.bn_ixyz;
Expand Down Expand Up @@ -128,28 +128,28 @@ auto run(Simulation3D& sd) -> double {
Real* gh1 = gh1_buf.data();

// sim coefficients
Real lo2 = sd.lo2;
Real sl2 = sd.sl2;
Real l = sd.l;
Real a1 = sd.a1;
Real a2 = sd.a2;
Real const lo2 = sd.lo2;
Real const sl2 = sd.sl2;
Real const l = sd.l;
Real const a1 = sd.a1;
Real const a2 = sd.a2;

// can control outside with OMP_NUM_THREADS env variable
int numWorkers = omp_get_max_threads();
int const numWorkers = omp_get_max_threads();

fmt::println("ENGINE: fcc_flag={}", fcc_flag);
fmt::println("{}", (fcc_flag > 0) ? "fcc=true" : "fcc=false");

// for timing
double timeElapsed;
double timeElapsedAir = 0.0;
double timeElapsedBn = 0.0;
double timeElapsedSample;
double timeElapsed = NAN;
double timeElapsedAir = 0.0;
double timeElapsedBn = 0.0;
double timeElapsedSample = NAN;
double timeElapsedSample_air = 0.0;
double timeElapsedSampleBn = 0.0;
double startTime = omp_get_wtime();
double const startTime = omp_get_wtime();

int64_t NzNy = Nz * Ny;
int64_t const NzNy = Nz * Ny;
for (int64_t n = 0; n < Nt; n++) {
auto const sampleStartTime = omp_get_wtime();

Expand Down Expand Up @@ -203,8 +203,8 @@ auto run(Simulation3D& sd) -> double {
for (int64_t ix = 1; ix < Nx - 1; ix++) {
for (int64_t iy = 1; iy < Ny - 1; iy++) {
for (int64_t iz = 1; iz < Nz - 1; iz++) { // contiguous
int64_t ii = ix * NzNy + iy * Nz + iz;
if (!(GET_BIT(bn_mask[ii >> 3], ii % 8))) {
int64_t const ii = ix * NzNy + iy * Nz + iz;
if ((GET_BIT(bn_mask[ii >> 3], ii % 8)) == 0) {
Real partial = a1 * u1[ii] - u0[ii];
partial += a2 * u1[ii + NzNy];
partial += a2 * u1[ii - NzNy];
Expand All @@ -224,8 +224,8 @@ auto run(Simulation3D& sd) -> double {
// while loop iterates iterates over both types of FCC grids
int64_t iz = (fcc_flag == 1) ? 2 - (ix + iy) % 2 : 1;
while (iz < Nz - 1) {
int64_t ii = ix * NzNy + iy * Nz + iz;
if (!(GET_BIT(bn_mask[ii >> 3], ii % 8))) {
int64_t const ii = ix * NzNy + iy * Nz + iz;
if ((GET_BIT(bn_mask[ii >> 3], ii % 8)) == 0) {
Real partial = a1 * u1[ii] - u0[ii];
partial += a2 * u1[ii + NzNy + Nz];
partial += a2 * u1[ii - NzNy - Nz];
Expand All @@ -248,9 +248,9 @@ auto run(Simulation3D& sd) -> double {
}
// ABC loss (2nd-order accurate first-order Engquist-Majda)
for (int64_t nb = 0; nb < Nba; nb++) {
Real lQ = l * Q_bna[nb];
int64_t ib = bna_ixyz[nb];
u0[ib] = (u0[ib] + lQ * u2ba[nb]) / (1.0 + lQ);
Real const lQ = l * Q_bna[nb];
int64_t const ib = bna_ixyz[nb];
u0[ib] = (u0[ib] + lQ * u2ba[nb]) / (1.0 + lQ);
}

// rigid boundary nodes, using adj data
Expand All @@ -259,19 +259,20 @@ auto run(Simulation3D& sd) -> double {
if (fcc_flag == 0) {
#pragma omp parallel for
for (int64_t nb = 0; nb < Nb; nb++) {
int64_t ii = bn_ixyz[nb];
uint8_t Kint;
uint16_t v = adj_bn[nb];
for (Kint = 0; v; Kint++)
int64_t const ii = bn_ixyz[nb];
uint8_t Kint = 0;
uint16_t v = adj_bn[nb];
for (Kint = 0; v != 0U; Kint++) {
v &= v - 1; // clear the least significant bit set
}

Real _2 = 2.0;
Real K = Kint;
Real b2 = a2;
Real b1 = (_2 - sl2 * K);
Real const _2 = 2.0;
Real const K = Kint;
Real const b2 = a2;
Real const b1 = (_2 - sl2 * K);

Real partial = b1 * u1[ii] - u0[ii];
uint16_t adj = adj_bn[nb];
Real partial = b1 * u1[ii] - u0[ii];
uint16_t const adj = adj_bn[nb];
partial += b2 * (Real)GET_BIT(adj, 0) * u1[ii + NzNy];
partial += b2 * (Real)GET_BIT(adj, 1) * u1[ii - NzNy];
partial += b2 * (Real)GET_BIT(adj, 2) * u1[ii + Nz];
Expand All @@ -283,19 +284,20 @@ auto run(Simulation3D& sd) -> double {
} else if (fcc_flag > 0) {
#pragma omp parallel for
for (int64_t nb = 0; nb < Nb; nb++) {
int64_t ii = bn_ixyz[nb];
uint8_t Kint;
uint16_t v = adj_bn[nb];
for (Kint = 0; v; Kint++)
int64_t const ii = bn_ixyz[nb];
uint8_t Kint = 0;
uint16_t v = adj_bn[nb];
for (Kint = 0; v != 0U; Kint++) {
v &= v - 1; // clear the least significant bit set
}

Real _2 = 2.0;
Real K = Kint;
Real b2 = a2;
Real b1 = (_2 - sl2 * K);
Real const _2 = 2.0;
Real const K = Kint;
Real const b2 = a2;
Real const b1 = (_2 - sl2 * K);

Real partial = b1 * u1[ii] - u0[ii];
uint16_t adj = adj_bn[nb];
Real partial = b1 * u1[ii] - u0[ii];
uint16_t const adj = adj_bn[nb];
partial += b2 * (Real)GET_BIT(adj, 0) * u1[ii + NzNy + Nz];
partial += b2 * (Real)GET_BIT(adj, 1) * u1[ii - NzNy - Nz];
partial += b2 * (Real)GET_BIT(adj, 2) * u1[ii + Nz + 1];
Expand Down Expand Up @@ -328,21 +330,21 @@ auto run(Simulation3D& sd) -> double {

// read output at current sample
for (int64_t nr = 0; nr < Nr; nr++) {
int64_t ii = out_ixyz[nr];
int64_t const ii = out_ixyz[nr];
u_out[nr * Nt + n] = (double)u1[ii];
}

// add current sample to next (as per update)
for (int64_t ns = 0; ns < Ns; ns++) {
int64_t ii = in_ixyz[ns];
int64_t const ii = in_ixyz[ns];
u0[ii] += (Real)in_sigs[ns * Nt + n];
}

// swap pointers
Real* tmp_ptr;
tmp_ptr = u1;
u1 = u0;
u0 = tmp_ptr;
Real* tmp_ptr = nullptr;
tmp_ptr = u1;
u1 = u0;
u0 = tmp_ptr;

// using extra state here for simplicity
tmp_ptr = u2b;
Expand Down
Loading

0 comments on commit a8afa87

Please sign in to comment.