Skip to content

Commit 6311d4f

Browse files
authored
Changes to compile for single precision (#616)
* Use amrex max and min. * Changes for single precision. * Update PelePhysics. * Actually test the single precision build. * Use amrex clamp. * Fix CI file. * Formatting. * Try to fix test_masscons.py. * Fix clamp. * Fix narrowing conversions.
1 parent 8852118 commit 6311d4f

31 files changed

+300
-182
lines changed

.github/workflows/ci.yml

Lines changed: 109 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -83,10 +83,12 @@ jobs:
8383
needs: Formatting
8484
runs-on: ${{matrix.os}}
8585
strategy:
86+
fail-fast: false
8687
matrix:
8788
os: [ubuntu-24.04, macos-latest]
8889
build_type: [Release, Debug]
8990
enable_eb: [EB-OFF, EB-ON]
91+
dim: [2, 3]
9092
include:
9193
- os: macos-latest
9294
install_deps: brew install open-mpi automake ccache
@@ -150,35 +152,28 @@ jobs:
150152
uses: actions/cache@v4
151153
with:
152154
path: ${{matrix.ccache_cache}}
153-
key: ccache-${{github.workflow}}-${{github.job}}-${{matrix.os}}-${{matrix.build_type}}-${{matrix.enable_eb}}-git-${{github.sha}}
155+
key: ccache-${{github.workflow}}-${{github.job}}-${{matrix.os}}-${{matrix.dim}}d-${{matrix.build_type}}-${{matrix.enable_eb}}-git-${{github.sha}}
154156
restore-keys: |
155-
ccache-${{github.workflow}}-${{github.job}}-${{matrix.os}}-${{matrix.build_type}}-${{matrix.enable_eb}}-git-
157+
ccache-${{github.workflow}}-${{github.job}}-${{matrix.os}}-${{matrix.dim}}d-${{matrix.build_type}}-${{matrix.enable_eb}}-git-
156158
- name: Configure
157159
run: |
158-
(for DIM in 2 3; do \
159-
printf "\n-------- Configuring ${DIM}D --------\n"; \
160-
cmake -B${{runner.workspace}}/build-${DIM}d-${{matrix.os}}-${{matrix.build_type}}-${{matrix.enable_eb}} \
161-
-DCMAKE_INSTALL_PREFIX:PATH=${{runner.workspace}}/install-${DIM}d-${{matrix.os}}-${{matrix.build_type}}-${{matrix.enable_eb}} \
162-
-DCMAKE_BUILD_TYPE:STRING=${{matrix.build_type}} \
163-
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
164-
-DPELE_DIM:STRING=${DIM} \
165-
-DPELE_ENABLE_MPI:BOOL=ON \
166-
-DMPIEXEC_PREFLAGS:STRING=--oversubscribe \
167-
-DPELE_ENABLE_EB:BOOL=${{matrix.use_eb}} \
168-
-DPELE_ENABLE_FCOMPARE_FOR_TESTS:BOOL=OFF \
169-
-DCMAKE_CXX_COMPILER_LAUNCHER:STRING=ccache \
170-
${{github.workspace}}; \
171-
if [ $? -ne 0 ]; then exit 1; fi \
172-
done)
160+
cmake -B${{runner.workspace}}/build-${{matrix.dim}}d-${{matrix.os}}-${{matrix.build_type}}-${{matrix.enable_eb}} \
161+
-DCMAKE_INSTALL_PREFIX:PATH=${{runner.workspace}}/install-${{matrix.dim}}d-${{matrix.os}}-${{matrix.build_type}}-${{matrix.enable_eb}} \
162+
-DCMAKE_BUILD_TYPE:STRING=${{matrix.build_type}} \
163+
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
164+
-DPELE_DIM:STRING=${{matrix.dim}} \
165+
-DPELE_ENABLE_MPI:BOOL=ON \
166+
-DMPIEXEC_PREFLAGS:STRING=--oversubscribe \
167+
-DPELE_ENABLE_EB:BOOL=${{matrix.use_eb}} \
168+
-DPELE_ENABLE_FCOMPARE_FOR_TESTS:BOOL=OFF \
169+
-DCMAKE_CXX_COMPILER_LAUNCHER:STRING=ccache \
170+
${{github.workspace}}
173171
- name: Build
174172
run: |
175173
ccache -z
176-
(for DIM in 2 3; do \
177-
printf "\n-------- Building ${DIM}D --------\n"; \
178-
cmake --build ${{runner.workspace}}/build-${DIM}d-${{matrix.os}}-${{matrix.build_type}}-${{matrix.enable_eb}} \
179-
--parallel ${{env.NPROCS}} 2>&1 | tee -a ${{runner.workspace}}/build-output.txt; \
180-
if [ ${PIPESTATUS[0]} -ne 0 ]; then exit 1; fi \
181-
done)
174+
cmake --build ${{runner.workspace}}/build-${{matrix.dim}}d-${{matrix.os}}-${{matrix.build_type}}-${{matrix.enable_eb}} \
175+
--parallel ${{env.NPROCS}} 2>&1 | tee -a ${{runner.workspace}}/build-output.txt; \
176+
if [ ${PIPESTATUS[0]} -ne 0 ]; then exit 1; fi \
182177
- name: Ccache Report
183178
run: |
184179
ccache -s
@@ -195,12 +190,95 @@ jobs:
195190
exit ${return}
196191
- name: Test
197192
run: |
198-
(for DIM in 2 3; do \
199-
printf "\n-------- Testing ${DIM}D --------\n"; \
200-
cd ${{runner.workspace}}/build-${DIM}d-${{matrix.os}}-${{matrix.build_type}}-${{matrix.enable_eb}}; \
201-
ctest ${{matrix.ctest_args}} -VV --output-on-failure; \
202-
if [ $? -ne 0 ]; then exit 1; fi \
203-
done)
193+
cd ${{runner.workspace}}/build-${{matrix.dim}}d-${{matrix.os}}-${{matrix.build_type}}-${{matrix.enable_eb}}; \
194+
ctest ${{matrix.ctest_args}} -VV --output-on-failure; \
195+
if [ $? -ne 0 ]; then exit 1; fi \
196+
CPU-CMake-SINGLE:
197+
needs: Formatting
198+
runs-on: ubuntu-24.04
199+
strategy:
200+
fail-fast: false
201+
matrix:
202+
enable_eb: [EB-OFF, EB-ON]
203+
dim: [2, 3]
204+
include:
205+
- enable_eb: EB-OFF
206+
use_eb: "OFF"
207+
- enable_eb: EB-ON
208+
use_eb: "ON"
209+
steps:
210+
- name: Clone
211+
uses: actions/checkout@v4
212+
with:
213+
submodules: recursive
214+
- name: Python
215+
uses: actions/setup-python@v5
216+
with:
217+
python-version: '3.12'
218+
- name: Setup
219+
run: |
220+
echo "NPROCS=$(nproc)" >> $GITHUB_ENV
221+
echo "CCACHE_COMPRESS=1" >> $GITHUB_ENV
222+
echo "CCACHE_COMPRESSLEVEL=10" >> $GITHUB_ENV
223+
echo "CCACHE_LOGFILE=${{github.workspace}}/ccache.log.txt" >> $GITHUB_ENV
224+
echo "CCACHE_MAXSIZE=50M" >> $GITHUB_ENV
225+
cmake -E make_directory ${{runner.workspace}}/deps
226+
- name: Dependencies
227+
run: |
228+
sudo apt-get install -y libopenmpi-dev openmpi-bin
229+
- name: Install Ccache
230+
run: |
231+
wget https://github.com/ccache/ccache/releases/download/v4.8/ccache-4.8-linux-x86_64.tar.xz
232+
tar xvf ccache-4.8-linux-x86_64.tar.xz
233+
sudo cp -f ccache-4.8-linux-x86_64/ccache /usr/local/bin/
234+
- name: Set Up Ccache
235+
uses: actions/cache@v4
236+
with:
237+
path: ~/.cache/ccache
238+
key: ccache-${{github.workflow}}-${{github.job}}-${{matrix.dim}}d-${{matrix.enable_eb}}-single-git-${{github.sha}}
239+
restore-keys: |
240+
ccache-${{github.workflow}}-${{github.job}}-${{matrix.dim}}d-${{matrix.enable_eb}}-single-git-
241+
- name: Configure
242+
run: |
243+
cmake -B${{runner.workspace}}/build-${{matrix.dim}}d-${{matrix.enable_eb}}-single \
244+
-DCMAKE_INSTALL_PREFIX:PATH=${{runner.workspace}}/install-${{matrix.dim}}d-${{matrix.enable_eb}}-single \
245+
-DCMAKE_BUILD_TYPE:STRING=Release \
246+
-DCMAKE_VERBOSE_MAKEFILE:BOOL=ON \
247+
-DPELE_DIM:STRING=${{matrix.dim}} \
248+
-DPELE_PRECISION:STRING=SINGLE \
249+
-DCMAKE_CXX_FLAGS:STRING=-Wno-float-conversion \
250+
-DPELE_ENABLE_MPI:BOOL=ON \
251+
-DMPIEXEC_PREFLAGS:STRING=--oversubscribe \
252+
-DPELE_ENABLE_EB:BOOL=${{matrix.use_eb}} \
253+
-DPELE_ENABLE_FCOMPARE_FOR_TESTS:BOOL=OFF \
254+
-DCMAKE_CXX_COMPILER_LAUNCHER:STRING=ccache \
255+
${{github.workspace}}
256+
- name: Build
257+
run: |
258+
ccache -z
259+
cmake --build ${{runner.workspace}}/build-${{matrix.dim}}d-${{matrix.enable_eb}}-single \
260+
--parallel ${{env.NPROCS}} 2>&1 | tee -a ${{runner.workspace}}/build-output.txt; \
261+
if [ ${PIPESTATUS[0]} -ne 0 ]; then exit 1; fi
262+
- name: Ccache Report
263+
run: |
264+
ccache -s
265+
du -hs ~/.cache/ccache
266+
- name: Report
267+
run: |
268+
echo "::add-matcher::.github/problem-matchers/gcc.json"
269+
egrep "Warning:|Error:|warning:|error:" ${{runner.workspace}}/build-output.txt \
270+
| egrep -v "Submodules/amrex|Submodules/sundials|Submodules/AMReX-Hydro" \
271+
| egrep -v "ld: warning:" | egrep -v "lto-wrapper: warning:" | sort | uniq \
272+
| awk 'BEGIN{i=0}{print $0}{i++}END{print "Warnings: "i}' > ${{runner.workspace}}/build-output-warnings.txt
273+
cat ${{runner.workspace}}/build-output-warnings.txt
274+
export return=$(tail -n 1 ${{runner.workspace}}/build-output-warnings.txt | awk '{print $2}')
275+
exit ${return}
276+
#- name: Test
277+
# run: |
278+
# cd ${{runner.workspace}}/build-${{matrix.dim}}d-${{matrix.enable_eb}}-single; \
279+
# ctest -LE no-ci -VV --output-on-failure; \
280+
# if [ $? -ne 0 ]; then exit 1; fi
281+
204282
GPU-Nvidia:
205283
name: GPU-CUDA
206284
needs: [Formatting, CPU-GNUmake]
@@ -247,9 +325,9 @@ jobs:
247325
uses: actions/cache@v4
248326
with:
249327
path: ~/.cache/ccache
250-
key: ccache-${{github.workflow}}-${{github.job}}-git-${{github.sha}}
328+
key: ccache-${{github.workflow}}-${{github.job}}-${{matrix.enable_eb}}-git-${{github.sha}}
251329
restore-keys: |
252-
ccache-${{github.workflow}}-${{github.job}}-git-
330+
ccache-${{github.workflow}}-${{github.job}}-${{matrix.enable_eb}}-git-
253331
- name: Configure
254332
run: |
255333
export PATH=/usr/local/nvidia/bin:/usr/local/cuda-12.6/bin:${PATH}

CMake/SetPeleCompileFlags.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ if(CMAKE_CXX_COMPILER_ID STREQUAL "IntelLLVM")
2525
"-Wno-unused-variable")
2626
endif()
2727

28+
list(APPEND PELE_CXX_FLAGS "${CMAKE_CXX_FLAGS}")
2829
separate_arguments(PELE_CXX_FLAGS)
2930
target_compile_options(${pele_physics_lib_name} PUBLIC $<$<COMPILE_LANGUAGE:CXX>:${PELE_CXX_FLAGS}>)
3031

Exec/Production/ChallengeProblem/pelelmex_prob.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ time_eta(
6969
eta_time = 0.5 * (std::tanh((time - start) / (duration * tau)) *
7070
std::tanh((-time + start + duration) / (duration * tau)) +
7171
1.0);
72-
eta_time = std::min(std::max(eta_time, 0.0), 1.0);
72+
eta_time = amrex::Clamp(eta_time, 0.0, 1.0);
7373
return eta_time;
7474
}
7575

Exec/Production/NormalJet_OpenDomain/pelelmex_prob.H

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ time_func(
2020
eta_time = 0.5 * (std::tanh((time - start) / (duration * tau)) *
2121
std::tanh((-time + start + duration) / (duration * tau)) +
2222
1.0);
23-
eta_time = std::min(std::max(eta_time, 0.0), 1.0);
23+
eta_time = amrex::Clamp(eta_time, 0.0, 1.0);
2424
return eta_time;
2525
}
2626

Exec/RegTests/HIT/pelelmex_prob.H

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,16 @@
44
#include <AMReX_Geometry.H>
55
#include <AMReX_FArrayBox.H>
66
#include <AMReX_SPACE.H>
7+
#include <AMReX_REAL.H>
78

89
#include <PeleLMeX_ProblemSpecificFunctions.H>
910
#include <PeleLMeX_Index.H>
1011
#include <PMFData.H>
1112
#include <PelePhysics.H>
1213
#include <Utilities.H>
1314

15+
using namespace amrex::literals;
16+
1417
namespace m2c = pele::physics::utilities::mks2cgs;
1518
namespace c2m = pele::physics::utilities::cgs2mks;
1619

@@ -101,9 +104,9 @@ struct MyProblemSpecificFunctions : public DefaultProblemSpecificFunctions
101104
const amrex::Real* dx = geomdata.CellSize();
102105

103106
amrex::Real x[3] = {
104-
prob_lo[0] + static_cast<amrex::Real>(i + 0.5) * dx[0] * 100.0,
105-
prob_lo[1] + static_cast<amrex::Real>(j + 0.5) * dx[1] * 100.0,
106-
prob_lo[2] + static_cast<amrex::Real>(k + 0.5) * dx[2] * 100.0};
107+
prob_lo[0] + static_cast<amrex::Real>(i + 0.5_rt) * dx[0] * 100.0_rt,
108+
prob_lo[1] + static_cast<amrex::Real>(j + 0.5_rt) * dx[1] * 100.0_rt,
109+
prob_lo[2] + static_cast<amrex::Real>(k + 0.5_rt) * dx[2] * 100.0_rt};
107110

108111
if (prob_parm.doing_turbulent_forcing) {
109112
AMREX_ALWAYS_ASSERT(is_incompressible != 0);

Exec/RegTests/HIT/pelelmex_prob.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ read_csv(
5454
const size_t nx,
5555
const size_t ny,
5656
const size_t nz,
57-
amrex::Vector<amrex::Real>& data)
57+
amrex::Vector<double>& data) // needs to be double
5858
{
5959
std::ifstream infile(iname, std::ios::in);
6060
const std::string memfile = read_file(infile);
@@ -132,8 +132,7 @@ PeleLM::readProbParm() // NOLINT(readability-make-member-function-const)
132132
const size_t nx = PeleLM::prob_parm->input_resolution;
133133
const size_t ny = PeleLM::prob_parm->input_resolution;
134134
const size_t nz = PeleLM::prob_parm->input_resolution;
135-
amrex::Vector<amrex::Real> data(
136-
nx * ny * nz * 6); /* this needs to be double */
135+
amrex::Vector<double> data(nx * ny * nz * 6); // needs to be double
137136
if (binfmt != 0) {
138137
read_binary(datafile, nx, ny, nz, 6, data);
139138
} else {

Exec/RegTests/PassiveScalar/pelelmex_prob.H

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,15 @@
44
#include <AMReX_Geometry.H>
55
#include <AMReX_FArrayBox.H>
66
#include <AMReX_SPACE.H>
7+
#include <AMReX_REAL.H>
78

89
#include <PeleLMeX_ProblemSpecificFunctions.H>
910
#include <PeleLMeX_Index.H>
1011
#include <PMFData.H>
1112
#include <PelePhysics.H>
1213

14+
using namespace amrex::literals;
15+
1316
struct MyProbParm : public ProbParmDefault
1417
{
1518
pele::physics::eos::EosParm<pele::physics::PhysicsType::eos_type> const*
@@ -69,10 +72,11 @@ struct MyProblemSpecificFunctions : public DefaultProblemSpecificFunctions
6972
#endif
7073
// find the centre of the domain
7174
const amrex::Real cen[AMREX_SPACEDIM] = {AMREX_D_DECL(
72-
prob_lo[0] + 0.5 * Lx, prob_lo[1] + 0.5 * Ly, prob_lo[2] + 0.5 * Lz)};
75+
prob_lo[0] + 0.5_rt * Lx, prob_lo[1] + 0.5_rt * Ly,
76+
prob_lo[2] + 0.5_rt * Lz)};
7377
const amrex::Real x[AMREX_SPACEDIM] = {AMREX_D_DECL(
74-
prob_lo[0] + (i + 0.5) * dx[0], prob_lo[1] + (j + 0.5) * dx[1],
75-
prob_lo[2] + (k + 0.5) * dx[2])};
78+
prob_lo[0] + (i + 0.5_rt) * dx[0], prob_lo[1] + (j + 0.5_rt) * dx[1],
79+
prob_lo[2] + (k + 0.5_rt) * dx[2])};
7680
// radius from centre
7781
const amrex::Real r = std::sqrt(AMREX_D_TERM(
7882
(x[0] - cen[0]) * (x[0] - cen[0]), +(x[1] - cen[1]) * (x[1] - cen[1]),

Exec/RegTests/SootRadTest/pelelmex_prob.H

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include <AMReX_Geometry.H>
55
#include <AMReX_FArrayBox.H>
66
#include <AMReX_ParmParse.H>
7+
#include <AMReX_REAL.H>
78

89
#include <PeleLMeX_ProblemSpecificFunctions.H>
910
#include <PMF.H>
@@ -13,6 +14,8 @@
1314
#include <PelePhysics.H>
1415
#include "SootModel.H"
1516

17+
using namespace amrex::literals;
18+
1619
struct MyProbParm : public ProbParmDefault
1720
{
1821
amrex::GpuArray<amrex::Real, NUM_SOOT_MOMENTS + 1> soot_vals;
@@ -47,7 +50,7 @@ struct MyProblemSpecificFunctions : public DefaultProblemSpecificFunctions
4750
state(i, j, k, TEMP) = pmf_vals[1];
4851
amrex::Real norm = 0.;
4952
for (int n = 0; n < NUM_SPECIES; n++) {
50-
massfrac[n] = amrex::max(0., amrex::min(1., pmf_vals[3 + n]));
53+
massfrac[n] = amrex::Clamp(pmf_vals[3 + n], 0.0_rt, 1.0_rt);
5154
norm += massfrac[n];
5255
}
5356
for (int n = 0; n < NUM_SPECIES; ++n) {

Exec/RegTests/TripleFlame/pelelmex_prob.H

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ void
5252
set_Y_from_Ksi(
5353
MyProbParm const& prob_parm, const amrex::Real& ksi_in, amrex::Real Y[])
5454
{
55-
amrex::Real phi = ksi_in / (1.0 - amrex::min(ksi_in, 0.999999)) *
55+
amrex::Real phi = ksi_in / (1.0 - amrex::min<amrex::Real>(ksi_in, 0.999999)) *
5656
(1.0 - prob_parm.Zst) / prob_parm.Zst;
5757

5858
set_Y_from_Phi(prob_parm, phi, Y);
@@ -100,7 +100,8 @@ struct MyProblemSpecificFunctions : public DefaultProblemSpecificFunctions
100100

101101
amrex::Real rad = std::sqrt(
102102
(x - prob_parm.splitx) * (x - prob_parm.splitx) +
103-
(amrex::min(y, y_lo) - y_lo) * (amrex::min(y, y_lo) - y_lo));
103+
(amrex::min<amrex::Real>(y, y_lo) - y_lo) *
104+
(amrex::min<amrex::Real>(y, y_lo) - y_lo));
104105

105106
amrex::Real Gaussian_T = std::exp(
106107
-(rad * rad) / (2.0 * (Gauss_T_width * (1.0 + (y - y_lo) / 0.03)) *

Source/PeleLMeX_BC.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ PeleLM::setBoundaryConditions()
124124

125125
// Initialize the BCRecs
126126
m_bcrec_state.resize(NVAR);
127-
constexpr int sizeForceBC = amrex::max(AMREX_SPACEDIM, NUM_SPECIES + 2);
127+
constexpr int sizeForceBC = amrex::max<int>(AMREX_SPACEDIM, NUM_SPECIES + 2);
128128
m_bcrec_force.resize(sizeForceBC);
129129
m_bcrec_aux.resize(m_nAux);
130130

0 commit comments

Comments
 (0)