Skip to content

Commit fa6f5e3

Browse files
authored
avoid nullptr deref within TinyProfiler for no mpi (#4568)
## Summary Compiling with TinyProfiler but no MPI results in a warning about a potential nullptr dereference in the TinyProfiler code. This should never actually happen in serial because nprocs is always 1, but the warning can be avoided. ## Additional background To reproduce the error that this avoids: ``` ./configure --dim=2 --with-mpi=no --enable-particle=no --with-fortran=no --enable-linear-solver=no --enable-fortran-api=no --prefix=./ --enable-tiny-profile=yes --comp=gnu --with-cuda=no make -j WARN_ALL=TRUE WARN_ERROR=TRUE XTRA_CXXFLAGS="-fno-operator-names -Wno-unused-parameter" ``` Results in: ``` In file included from /home/bperry/PelePhysics/Submodules/amrex/Src/Base/AMReX_TinyProfiler.cpp:5: In function ‘void amrex::ParallelDescriptor::Gather(const T*, size_t, T1*, size_t, int) [with T = long int; T1 = long int]’, inlined from ‘static void amrex::TinyProfiler::PrintMemStats(std::map<std::__cxx11::basic_string<char>, amrex::MemStat>&, const std::string&, double, double, std::ostream*)’ at /home/bperry/PelePhysics/Submodules/amrex/Src/Base/AMReX_TinyProfiler.cpp:789:39: /home/bperry/PelePhysics/Submodules/amrex/Src/Base/AMReX_ParallelDescriptor.H:1188:38: error: null pointer dereference [-Werror=null-dereference] 1188 | for (int j=0; j<sc; ++j) { t1[j] = t[j]; } | ~~~~~~^~~~ ```
1 parent 653952f commit fa6f5e3

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

Src/Base/AMReX_TinyProfiler.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -775,7 +775,7 @@ TinyProfiler::PrintMemStats (std::map<std::string, MemStat>& memstats,
775775
std::vector<Long> avgmem_vec(nprocs);
776776
std::vector<Long> maxmem_vec(nprocs);
777777

778-
if (nprocs == 1)
778+
if (ParallelDescriptor::NProcs() == 1)
779779
{
780780
nalloc_vec[0] = nalloc;
781781
nfree_vec[0] = nfree;

0 commit comments

Comments
 (0)