diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml index cf4b375ce00..dcb975aaa66 100644 --- a/.github/workflows/ubuntu.yml +++ b/.github/workflows/ubuntu.yml @@ -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 diff --git a/Source/Diagnostics/ReducedDiags/FieldProbeParticleContainer.cpp b/Source/Diagnostics/ReducedDiags/FieldProbeParticleContainer.cpp index 7e7aecb9167..dc26de3c1e6 100644 --- a/Source/Diagnostics/ReducedDiags/FieldProbeParticleContainer.cpp +++ b/Source/Diagnostics/ReducedDiags/FieldProbeParticleContainer.cpp @@ -76,6 +76,10 @@ FieldProbeParticleContainer::AddNParticles (int lev, // number of particles to add auto const np = static_cast(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. @@ -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());