Skip to content

Commit 949f81b

Browse files
authored
update to C++20 (#3097)
1 parent 06729c3 commit 949f81b

File tree

9 files changed

+33
-41
lines changed

9 files changed

+33
-41
lines changed

.clang-tidy

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Checks: >
2626
-misc-redundant-expression,
2727
modernize-*,
2828
-modernize-avoid-c-arrays,
29+
-modernize-use-designated-initializers,
2930
-modernize-use-trailing-return-type,
3031
performance-*,
3132
-performance-avoid-endl,

.github/workflows/dependencies/dependencies_nvcc.sh

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ sudo apt-get install -y \
2525
wget
2626

2727
VERSION_DOTTED=${1-12.0} && VERSION_DASHED=$(sed 's/\./-/' <<< $VERSION_DOTTED)
28-
curl -O https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64/cuda-keyring_1.0-1_all.deb
29-
sudo dpkg -i cuda-keyring_1.0-1_all.deb
28+
curl -O https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2404/x86_64/cuda-keyring_1.1-1_all.deb
29+
sudo dpkg -i cuda-keyring_1.1-1_all.deb
3030
sudo apt-get update
3131
sudo apt-get install -y \
3232
cuda-command-line-tools-$VERSION_DASHED \
@@ -39,4 +39,7 @@ sudo apt-get install -y \
3939
libcufft-dev-$VERSION_DASHED \
4040
libcurand-dev-$VERSION_DASHED \
4141
libcusparse-dev-$VERSION_DASHED
42+
43+
sudo apt-get install -y --no-install-recommends libnvjitlink-dev-$VERSION_DASHED || true
44+
4245
sudo ln -s cuda-$VERSION_DOTTED /usr/local/cuda

.github/workflows/gpu_action.yml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ concurrency:
88

99
jobs:
1010
gpu-compilation:
11-
runs-on: ubuntu-22.04
11+
runs-on: ubuntu-24.04
1212
steps:
1313
- uses: actions/checkout@v6
1414
with:
@@ -29,14 +29,14 @@ jobs:
2929
sudo apt-get -qq -y install curl cmake jq clang g++>=9.3.0
3030
3131
- name: Install CUDA
32-
run: .github/workflows/dependencies/dependencies_nvcc.sh 11.8
32+
run: .github/workflows/dependencies/dependencies_nvcc.sh 12.9
3333

3434
- name: Install hypre
3535
run: |
36-
wget -q https://github.com/hypre-space/hypre/archive/refs/tags/v2.28.0.tar.gz
37-
tar xfz v2.28.0.tar.gz
38-
cd hypre-2.28.0/src
39-
CUDA_HOME=/usr/local/cuda HYPRE_CUDA_SM=60 ./configure --with-cxxstandard=17 --with-cuda --enable-unified-memory --without-MPI
36+
wget -q https://github.com/hypre-space/hypre/archive/refs/tags/v2.33.0.tar.gz
37+
tar xfz v2.33.0.tar.gz
38+
cd hypre-2.33.0/src
39+
CUDA_HOME=/usr/local/cuda HYPRE_CUDA_SM=60 ./configure --with-cxxstandard=20 --with-cuda --enable-unified-memory --without-MPI
4040
make -j 4
4141
make install
4242
cd ../../
@@ -56,5 +56,5 @@ jobs:
5656
- name: Compile problems for GPU
5757
run: |
5858
export PATH=$PATH:/usr/local/cuda/bin
59-
export AMREX_HYPRE_HOME=${PWD}/hypre-2.28.0/src/hypre
59+
export AMREX_HYPRE_HOME=${PWD}/hypre-2.33.0/src/hypre
6060
python3 external/cpp-linter-action/run_on_changed_files.py ${{ github.event.pull_request.base.sha }} ${{ github.event.pull_request.head.sha }} -header-filter=Castro -ignore-files="amrex|Microphysics" -gpu

Docs/source/getting_started.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ Getting Started
1414
The compilation process is managed by AMReX and its build system. The
1515
general requirements to build Castro are:
1616

17-
* A C++17 (or later) compiler (for GCC, we need >= 9.0 for CUDA compilation)
17+
* A C++20 (or later) compiler (for GCC, we need >= 13.1)
1818

1919
* python (>= 3.10)
2020

@@ -24,7 +24,7 @@ GCC is the main compiler suite used by the developers.
2424

2525
For running in parallel, an MPI library is required. For running on GPUs:
2626

27-
* CUDA 11 or later is required for NVIDIA GPUs
27+
* CUDA 12 or later is required for NVIDIA GPUs
2828

2929
* ROCM 6.3.1 or later is required for AMD GPUs (earlier versions have a register allocation bug)
3030

Exec/Make.Castro

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ ifeq ("$(wildcard $(AMREX_HOME)/Tools/GNUMake/Make.defs)","")
5252
$(error AMReX has not been downloaded. Please run "git submodule update --init" from the top level of the code)
5353
endif
5454

55-
# Require C++17
56-
CXXSTD := c++17
55+
# Require C++20
56+
CXXSTD := c++20
5757

5858
# Use Lazy QueueReduction for the timing outputs
5959
LAZY := TRUE

Source/driver/main.cpp

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include <new>
33
#include <cstdio>
44
#include <cstring>
5+
#include <format>
56
#include <iostream>
67
#include <iomanip>
78

@@ -255,14 +256,8 @@ main (int argc,
255256
//
256257
// It's actually the high water mark of heap space required by FABs.
257258
//
258-
char buf[256];
259-
260-
sprintf(buf,
261-
"CPU(%d): Heap Space (bytes) used by Coalescing FAB Arena: %ld",
262-
ParallelDescriptor::MyProc(),
263-
arena->heap_space_used());
264-
265-
std::cout << buf << std::endl;
259+
std::cout << std::format("CPU({}): Heap Space (bytes) used by Coalescing FAB Arena: {}\n",
260+
ParallelDescriptor::MyProc(), arena->heap_space_used());
266261
}
267262

268263
BL_PROFILE_VAR_STOP(pmain);

Source/gravity/Gravity.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1771,7 +1771,7 @@ Gravity::init_multipole_grav() const
17711771
maxWidth = amrex::max(maxWidth, probhi[2] - problo[2]);
17721772
}
17731773

1774-
multipole::rmax = 0.5_rt * maxWidth * std::sqrt(static_cast<Real>(AMREX_SPACEDIM));
1774+
multipole::rmax = 0.5_rt * maxWidth * std::sqrt(static_cast<Real>(AMREX_SPACEDIM)); // NOLINT(modernize-use-std-numbers)
17751775
}
17761776

17771777
void

Source/radiation/Radiation.cpp

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,13 @@
77

88
#include <opacity.H>
99

10+
#include <format>
1011
#include <iostream>
1112

1213
#ifdef _OPENMP
1314
#include <omp.h>
1415
#endif
1516

16-
#include <sstream>
17-
1817
using namespace amrex;
1918

2019
Radiation::Solver_Type Radiation::SolverType = Radiation::InvalidSolver;
@@ -647,27 +646,23 @@ void Radiation::checkPoint(int level,
647646
//
648647
if (ParallelDescriptor::IOProcessor()) {
649648
int oldprec = os.precision(20);
650-
sprintf(buf, "delta_e_rat_level[%d]= ", level);
651-
std::string DeltaString = buf;
649+
auto DeltaString = std::format("delta_e_rat_level[{}]= ", level);
652650
os << DeltaString << delta_e_rat_level[level] << '\n';
653-
sprintf(buf, "delta_T_rat_level[%d]= ", level);
654-
DeltaString = buf;
651+
DeltaString = std::format("delta_T_rat_level[{}]= ", level);
655652
os << DeltaString << delta_T_rat_level[level] << '\n';
656653
os.precision(oldprec);
657654
}
658655

659656
// Path name construction stolen from AmrLevel::checkPoint
660657

661-
sprintf(buf, "Level_%d", level);
662-
std::string Level = buf;
658+
std::string Level = std::format("Level_{}", level);
663659

664660
//
665661
// Write name of conservation flux register to header.
666662
//
667-
sprintf(buf, "/RadFlux");
668663

669664
std::string PathNameInHeader = Level;
670-
PathNameInHeader += buf;
665+
PathNameInHeader += "/RadFlux";
671666
if (ParallelDescriptor::IOProcessor()) {
672667
os << PathNameInHeader;
673668
}
@@ -691,7 +686,7 @@ void Radiation::checkPoint(int level,
691686
FullPathName += '/';
692687
}
693688
FullPathName += Level;
694-
FullPathName += buf;
689+
FullPathName += "/RadFlux";
695690
//
696691
// Output conservation flux register.
697692
//

Util/model_parser/model_parser.H

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
#include <fstream>
66
#include <vector>
77
#include <algorithm>
8+
#include <ranges>
9+
810
#include <network.H>
911
#include <model_parser_data.H>
1012
#include <AMReX_Print.H>
@@ -60,20 +62,16 @@ namespace model_string
6062
{
6163
inline std::string& ltrim(std::string& s)
6264
{
63-
auto it = std::find_if(s.begin(), s.end(),
64-
[](int c) {
65-
return !std::isspace(c);
66-
});
65+
auto it = std::ranges::find_if(s,
66+
[] (int c) {return !std::isspace(c);});
6767
s.erase(s.begin(), it);
6868
return s;
6969
}
7070

7171
inline std::string& rtrim(std::string& s)
7272
{
73-
auto it = std::find_if(s.rbegin(), s.rend(),
74-
[](int c) {
75-
return !std::isspace(c);
76-
});
73+
auto it = std::ranges::find_if(std::ranges::reverse_view(s),
74+
[] (int c) {return !std::isspace(c);});
7775
s.erase(it.base(), s.end());
7876
return s;
7977
}

0 commit comments

Comments
 (0)