Skip to content

Commit

Permalink
add check for warnings on gcc as well as clang
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahm-LANL committed Nov 29, 2024
1 parent 20e9661 commit 5b90563
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 33 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/warnings.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Warnings

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
warnings-gcc:
name: Ensure no warnings from gcc
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v3
with:
submodules: recursive
- name: Set system to non-interactive mode
run: export DEBIAN_FRONTEND=noninteractive
- name: install dependencies
run: |
sudo apt-get update -y -qq
sudo apt-get install -y --allow-downgrades --allow-remove-essential --allow-change-held-packages -qq build-essential
- name: build and run tests
run: |
mkdir -p bin
cd bin
cmake -DCMAKE_BUILD_TYPE=Debug \
-DSINGULARITY_STRICT_WARNINGS=ON \
-DSINGULARITY_USE_FORTRAN=OFF \
-DSINGULARITY_BUILD_FORTRAN_BACKEND=ON \
-DSINGULARITY_BUILD_TESTS=ON \
-DSINGULARITY_FORCE_SUBMODULE_MODE=ON \
-DSINGULARITY_USE_KOKKOS=ON \
..
make -j4
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ target_compile_options(
)
if (SINGULARITY_STRICT_WARNINGS)
target_compile_options(singularity-eos_Interface INTERFACE
-Wall -Werror)
-Wall -Werror -Wno-unknown-pragmas)
endif()

if(TARGET singularity-eos_Library)
Expand Down
50 changes: 25 additions & 25 deletions singularity-eos/base/root-finding-1d/root_finding.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,45 +70,45 @@ enum class Status { SUCCESS = 0, FAIL = 1 };
*/
class RootCounts {
private:
static constexpr int nbins_{15};
static constexpr std::size_t nbins_{15};
mutable Real counts_[nbins_];

public:
PORTABLE_INLINE_FUNCTION
RootCounts() {
for (int i{0}; i < nbins_; ++i)
for (std::size_t i{0}; i < nbins_; ++i)
counts_[i] = 0;
}
PORTABLE_INLINE_FUNCTION void reset() {
for (int i{0}; i < nbins_; ++i)
for (std::size_t i{0}; i < nbins_; ++i)
counts_[i] = 0;
}
PORTABLE_INLINE_FUNCTION void increment(int i) const {
PORTABLE_INLINE_FUNCTION void increment(std::size_t i) const {
assert(i < nbins_ && i >= 0);
#ifdef PORTABILITY_STRATEGY_NONE
counts_[i] += 1;
#endif // PORTABILITY_STRATEGY_NONE
}
PORTABLE_INLINE_FUNCTION Real total() const {
Real tot{1.e-20};
for (int i{0}; i < nbins_; ++i)
for (std::size_t i{0}; i < nbins_; ++i)
tot += counts_[i];
return tot;
}
PORTABLE_INLINE_FUNCTION const Real &operator[](const int i) const {
PORTABLE_INLINE_FUNCTION const Real &operator[](const std::size_t i) const {
assert(i < nbins_ && i >= 0);
return counts_[i];
}
PORTABLE_INLINE_FUNCTION Real &operator[](const int i) {
PORTABLE_INLINE_FUNCTION Real &operator[](const std::size_t i) {
assert(i < nbins_ && i >= 0);
return counts_[i];
}
PORTABLE_INLINE_FUNCTION void print_counts() const {
for (int i{0}; i < nbins_; ++i)
for (std::size_t i{0}; i < nbins_; ++i)
printf("%e\n", counts_[i]);
}
PORTABLE_INLINE_FUNCTION int nBins() const { return nbins_; }
PORTABLE_INLINE_FUNCTION int more() const { return nbins_ - 1; }
PORTABLE_INLINE_FUNCTION std::size_t nBins() const { return nbins_; }
PORTABLE_INLINE_FUNCTION std::size_t more() const { return nbins_ - 1; }
};

PORTABLE_INLINE_FUNCTION bool check_bracket(const Real ya, const Real yb) {
Expand All @@ -119,11 +119,11 @@ template <typename T>
PORTABLE_INLINE_FUNCTION bool set_bracket(const T &f, Real &a, const Real guess, Real &b,
Real &ya, const Real yg, Real &yb,
const bool &verbose = false) {
constexpr int max_search_depth = 6;
constexpr std::size_t max_search_depth = 6;
Real dx = b - a;
for (int level = 0; level < max_search_depth; level++) {
const int nlev = (1 << level);
for (int i = 0; i < nlev; i++) {
for (std::size_t level = 0; level < max_search_depth; level++) {
const std::size_t nlev = (1 << level);
for (std::size_t i = 0; i < nlev; i++) {
const Real x = a + (i + 0.5) * dx;
const Real yx = f(x);
if (check_bracket(yx, yg)) {
Expand Down Expand Up @@ -158,7 +158,7 @@ PORTABLE_INLINE_FUNCTION Status regula_falsi(const T &f, const Real ytarget,
Real &xroot,
const RootCounts *counts = nullptr,
const bool &verbose = false) {
constexpr int max_iter = SECANT_NITER_MAX;
constexpr std::size_t max_iter = SECANT_NITER_MAX;
auto func = [&](const Real x) { return f(x) - ytarget; };
Real ya = func(a);
Real yg = func(guess);
Expand Down Expand Up @@ -187,9 +187,9 @@ PORTABLE_INLINE_FUNCTION Status regula_falsi(const T &f, const Real ytarget,
ya *= sign;
yb *= sign;

int b1 = 0;
int b2 = 0;
int iteration_count = 0;
std::size_t b1 = 0;
std::size_t b2 = 0;
std::size_t iteration_count = 0;
while (b - a > 2.0 * xtol && (std::abs(ya) > ytol || std::abs(yb) > ytol) &&
iteration_count < max_iter) {
Real c = (a * yb - b * ya) / (yb - ya);
Expand Down Expand Up @@ -251,15 +251,15 @@ PORTABLE_INLINE_FUNCTION Status newton_raphson(const T &f, const Real ytarget,
const bool &verbose = false,
const bool &fail_on_bound_root = true) {

constexpr int max_iter = NEWTON_RAPHSON_NITER_MAX;
constexpr std::size_t max_iter = NEWTON_RAPHSON_NITER_MAX;
Real _x = guess;
Real _xold = 0.0;
auto status = Status::SUCCESS;

Real yg;
Real dfunc;

int iter;
std::size_t iter;

for (iter = 0; iter < max_iter; iter++) {
std::tie(yg, dfunc) = f(_x); // C++11 tuple unpacking
Expand Down Expand Up @@ -383,7 +383,7 @@ PORTABLE_INLINE_FUNCTION Status secant(const T &f, const Real ytarget, const Rea
Real x_last, y, yp, ym, dyNum, dyDen, dy;

Real x = xguess;
unsigned int iter{0};
std::size_t iter{0};
for (iter = 0; iter < SECANT_NITER_MAX; ++iter) {
x_last = x;
dx = fabs(1.e-7 * x) + xtol;
Expand Down Expand Up @@ -490,7 +490,7 @@ PORTABLE_INLINE_FUNCTION Status bisect(const T &f, const Real ytarget, const Rea
x += 2. * xtol;
}
// do { // Try to find reasonable region for bisection
for (int i{0}; i < BISECT_REG_MAX; ++i) {
for (std::size_t i{0}; i < BISECT_REG_MAX; ++i) {
dx = fabs(grow * x);
xl = x - dx;
xr = x + dx;
Expand Down Expand Up @@ -547,10 +547,10 @@ PORTABLE_INLINE_FUNCTION Status bisect(const T &f, const Real ytarget, const Rea
"\til = %.10e\n"
"\tir = %.10e\n",
xguess, ytarget, xl, xr, fl, fr, il, ir);
int nx = 300;
std::size_t nx = 300;
Real dx = (xmax - xmin) / (nx - 1);
fprintf(stderr, "Area map:\nx\ty\n");
for (int i = 0; i < nx; i++) {
for (std::size_t i = 0; i < nx; i++) {
fprintf(stderr, "%.4f\t%.4e\n", x + i * dx, f(x + i * dx));
}
#endif
Expand All @@ -559,7 +559,7 @@ PORTABLE_INLINE_FUNCTION Status bisect(const T &f, const Real ytarget, const Rea
}
}

for (int i{0}; i < BISECT_NITER_MAX; ++i) {
for (std::size_t i{0}; i < BISECT_NITER_MAX; ++i) {
Real xm = 0.5 * (xl + xr);
Real fm = f(xm) - ytarget;
if (fl * fm <= 0) {
Expand Down
7 changes: 4 additions & 3 deletions singularity-eos/eos/eos_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,18 @@ constexpr std::size_t MAX_NUM_CHARS = 121;
// Cuda doesn't have strcat, so we implement it ourselves
PORTABLE_FORCEINLINE_FUNCTION
char *StrCat(char *destination, const char *source) {
int i, j; // not in loops because they're re-used.
std::size_t i, j; // not in loops because they're re-used.

// specifically avoid strlen, which isn't on GPU
for (i = 0; destination[i] != '\0'; i++) {
}
// assumes destination has enough memory allocated
for (j = 0; source[j] != '\0'; j++) {
// MAX_NUM_CHARS-1 to leave room for null terminator
PORTABLE_REQUIRE((i + j) < MAX_NUM_CHARS - 1,
std::size_t ipj = i + j;
PORTABLE_REQUIRE(ipj < MAX_NUM_CHARS - 1,
"Concat string must be within allowed size");
destination[i + j] = source[j];
destination[ipj] = source[j];
}
// null terminate destination string
destination[i + j] = '\0';
Expand Down
2 changes: 1 addition & 1 deletion singularity-eos/eos/get_sg_eos_p_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void get_sg_eos_p_t(const char *name, int ncell, int nmat, indirection_v &offset
const int32_t token{tokens.acquire()};
const int32_t tid{small_loop ? iloop : token};
// need to initialize the scratch before it's used to avoid undefined behavior
for (int idx = 0; idx < solver_scratch.extent(1); ++idx) {
for (std::size_t idx = 0; idx < solver_scratch.extent(1); ++idx) {
solver_scratch(tid, idx) = 0.0;
}
// caching mechanism
Expand Down
2 changes: 1 addition & 1 deletion singularity-eos/eos/get_sg_eos_rho_e.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void get_sg_eos_rho_e(const char *name, int ncell, indirection_v &offsets_v,
// initialize values for solver / lookup
i_func(i, tid, mass_sum, npte, vfrac_sum, 0.0, 1.0, 0.0);
// need to initialize the scratch before it's used to avoid undefined behavior
for (int idx = 0; idx < solver_scratch.extent(1); ++idx) {
for (std::size_t idx = 0; idx < solver_scratch.extent(1); ++idx) {
solver_scratch(tid, idx) = 0.0;
}
// get cache from offsets into scratch
Expand Down
2 changes: 1 addition & 1 deletion singularity-eos/eos/get_sg_eos_rho_p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void get_sg_eos_rho_p(const char *name, int ncell, indirection_v &offsets_v,
i_func(i, tid, mass_sum, npte, vfrac_sum, 0.0, 0.0, 1.0);
Real sie_tot_true{0.0};
// need to initialize the scratch before it's used to avoid undefined behavior
for (int idx = 0; idx < solver_scratch.extent(1); ++idx) {
for (std::size_t idx = 0; idx < solver_scratch.extent(1); ++idx) {
solver_scratch(tid, idx) = 0.0;
}
const int neq = npte + 1;
Expand Down
2 changes: 1 addition & 1 deletion singularity-eos/eos/get_sg_eos_rho_t.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void get_sg_eos_rho_t(const char *name, int ncell, indirection_v &offsets_v,
// calculate pte condition (lookup for 1 mat cell)
Real sie_tot_true{0.0};
// need to initialize the scratch before it's used to avoid undefined behavior
for (int idx = 0; idx < solver_scratch.extent(1); ++idx) {
for (std::size_t idx = 0; idx < solver_scratch.extent(1); ++idx) {
solver_scratch(tid, idx) = 0.0;
}
const int neq = npte;
Expand Down
3 changes: 3 additions & 0 deletions singularity-eos/eos/modifiers/eos_unitsystem.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,15 @@ namespace singularity {
using namespace eos_base;

// tag dispatch for constructors for UnitSystem
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-variable"
namespace eos_units_init {
static struct ThermalUnitsInit {
} thermal_units_init_tag;
static struct LengthTimeUnitsInit {
} length_time_units_init_tag;
} // namespace eos_units_init
#pragma GCC diagnostic pop

template <typename T>
class UnitSystem : public EosBase<UnitSystem<T>> {
Expand Down

0 comments on commit 5b90563

Please sign in to comment.