Skip to content

Commit

Permalink
Add UB sanitizer CI test (ECP-WarpX#4783)
Browse files Browse the repository at this point in the history
* add UB sanitizer CI test

* fix bug

* use fno-sanitize-recover=all

* fix bug

* rename sanitizers -> UB sanitizer

* fix issue found with UB sanitizer

* change compilation options

* return early if np <= 0
  • Loading branch information
lucafedeli88 authored Mar 19, 2024
1 parent 6610e47 commit 0531910
Show file tree
Hide file tree
Showing 2 changed files with 61 additions and 2 deletions.
55 changes: 55 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,61 @@ jobs:
export OMP_NUM_THREADS=1
mpirun -n 2 Examples/Physics_applications/laser_acceleration/PICMI_inputs_3d.py
build_UB_sanitizer:
name: Clang UB sanitizer
runs-on: ubuntu-22.04
if: github.event.pull_request.draft == false
env:
CC: clang
CXX: clang++
# On CI for this test, Ninja is slower than the default:
#CMAKE_GENERATOR: Ninja
steps:
- uses: actions/checkout@v4
- name: install dependencies
run: |
.github/workflows/dependencies/clang15.sh
- name: CCache Cache
uses: actions/cache@v4
with:
path: ~/.cache/ccache
key: ccache-${{ github.workflow }}-${{ github.job }}-git-${{ github.sha }}
restore-keys: |
ccache-${{ github.workflow }}-${{ github.job }}-git-
- name: build WarpX
run: |
export CCACHE_COMPRESS=1
export CCACHE_COMPRESSLEVEL=10
export CCACHE_MAXSIZE=100M
ccache -z
export CXX=$(which clang++-15)
export CC=$(which clang-15)
export CXXFLAGS="-fsanitize=undefined -fno-sanitize-recover=all"
cmake -S . -B build \
-GNinja \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DWarpX_DIMS="RZ;1;2;3" \
-DWarpX_PSATD=ON \
-DWarpX_QED=ON \
-DWarpX_QED_TABLE_GEN=ON \
-DWarpX_OPENPMD=ON \
-DWarpX_PRECISION=SINGLE \
-DWarpX_PARTICLE_PRECISION=SINGLE
cmake --build build -j 4
ccache -s
du -hs ~/.cache/ccache
- name: run with UB sanitizer
run: |
export OMP_NUM_THREADS=2
mpirun -n 2 ./build/bin/warpx.rz Examples/Physics_applications/laser_acceleration/inputs_rz
mpirun -n 2 ./build/bin/warpx.1d Examples/Physics_applications/laser_acceleration/inputs_1d
mpirun -n 2 ./build/bin/warpx.2d Examples/Physics_applications/laser_acceleration/inputs_2d
mpirun -n 2 ./build/bin/warpx.3d Examples/Physics_applications/laser_acceleration/inputs_3d
save_pr_number:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,10 @@ FieldProbeParticleContainer::AddNParticles (int lev,

// number of particles to add
auto const np = static_cast<int>(x.size());
if (np <= 0){
Redistribute();
return;
}

// have to resize here, not in the constructor because grids have not
// been built when constructor was called.
Expand Down Expand Up @@ -122,8 +126,8 @@ FieldProbeParticleContainer::AddNParticles (int lev,
pinned_tile.push_back_real(FieldProbePIdx::Bz, np, 0.0);
pinned_tile.push_back_real(FieldProbePIdx::S, np, 0.0);

auto old_np = particle_tile.numParticles();
auto new_np = old_np + pinned_tile.numParticles();
const auto old_np = particle_tile.numParticles();
const auto new_np = old_np + pinned_tile.numParticles();
particle_tile.resize(new_np);
amrex::copyParticles(
particle_tile, pinned_tile, 0, old_np, pinned_tile.numParticles());
Expand Down

0 comments on commit 0531910

Please sign in to comment.