Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

25.01: Memory Leak in computePhiIGF #5547

Closed
ax3l opened this issue Jan 9, 2025 · 5 comments
Closed

25.01: Memory Leak in computePhiIGF #5547

ax3l opened this issue Jan 9, 2025 · 5 comments
Assignees
Labels
bug: affects latest release Bug also exists in latest release version bug Something isn't working component: electrostatic electrostatic solver component: spectral Spectral solvers (PSATD, IGF)

Comments

@ax3l
Copy link
Member

ax3l commented Jan 9, 2025

After we updated ImpactX to WarpX & AMReX 25.01, our ASAN plugin shows a memory leak in ablastr::fields::computePhiIGF to the plans of amrex::FFT::OpenBCSolver #4217

Full log:
ECP-WarpX/impactx#790 (comment)

2025-01-09T08:33:18.0346789Z Direct leak of 8616 byte(s) in 359 object(s) allocated from:
2025-01-09T08:33:18.0347482Z     #0 0x7f9355acdff2 in __interceptor_memalign (/usr/lib/clang/14/lib/linux/libclang_rt.asan-x86_64.so+0xcdff2) (BuildId: a6105a816e63299474c1078329a59ed80f244fbf)
2025-01-09T08:33:18.0348508Z     #1 0x7f9350623458 in fftw_malloc_plain (/lib/x86_64-linux-gnu/libfftw3.so.3+0x23458) (BuildId: 540833d2131547e65736d186bbe599fec123ccd4)
2025-01-09T08:33:18.0349291Z     #2 0x7f9350716055 in fftw_mkapiplan (/lib/x86_64-linux-gnu/libfftw3.so.3+0x116055) (BuildId: 540833d2131547e65736d186bbe599fec123ccd4)
2025-01-09T08:33:18.0350065Z     #3 0x7f935071d5b7 in fftw_plan_many_dft_c2r (/lib/x86_64-linux-gnu/libfftw3.so.3+0x11d5b7) (BuildId: 540833d2131547e65736d186bbe599fec123ccd4)
2025-01-09T08:33:18.0351159Z     #4 0x55f19d53f115 in void amrex::FFT::Plan<double>::init_r2c<(amrex::FFT::Direction)1>(amrex::BoxND<3> const&, double*, double (*) [2], bool) /home/runner/work/impactx/impactx/build/_deps/fetchedamrex-src/Src/FFT/AMReX_FFT_Helper.H:287:24
2025-01-09T08:33:18.0352554Z     #5 0x55f19d55856c in amrex::FFT::R2C<double, (amrex::FFT::Direction)2, (amrex::FFT::DomainStrategy)0>::prepare_openbc() /home/runner/work/impactx/impactx/build/_deps/fetchedamrex-src/Src/FFT/AMReX_FFT_R2C.H:496:47
2025-01-09T08:33:18.0354568Z     #6 0x55f19d50cb3a in void amrex::FFT::OpenBCSolver<double>::setGreensFunction<ablastr::fields::computePhiIGF(amrex::MultiFab const&, amrex::MultiFab&, std::array<double, 3ul> const&, amrex::BoxArray const&, bool)::$_1>(ablastr::fields::computePhiIGF(amrex::MultiFab const&, amrex::MultiFab&, std::array<double, 3ul> const&, amrex::BoxArray const&, bool)::$_1 const&) /home/runner/work/impactx/impactx/build/_deps/fetchedamrex-src/Src/FFT/AMReX_FFT_OpenBCSolver.H:156:15
2025-01-09T08:33:18.0356815Z     #7 0x55f19d50cb3a in ablastr::fields::computePhiIGF(amrex::MultiFab const&, amrex::MultiFab&, std::array<double, 3ul> const&, amrex::BoxArray const&, bool) /home/runner/work/impactx/impactx/build/_deps/fetchedablastr-src/Source/ablastr/fields/IntegratedGreenFunctionSolver.cpp:74:21
2025-01-09T08:33:18.0360352Z     #8 0x55f19d4bc90a in void ablastr::fields::computePhi<std::nullopt_t, std::nullopt_t, void>(amrex::Vector<amrex::MultiFab*, std::allocator<amrex::MultiFab*> > const&, amrex::Vector<amrex::MultiFab*, std::allocator<amrex::MultiFab*> > const&, std::array<double, 3ul>, double, double, int, int, amrex::Vector<amrex::Geometry, std::allocator<amrex::Geometry> > const&, amrex::Vector<amrex::DistributionMapping, std::allocator<amrex::DistributionMapping> > const&, amrex::Vector<amrex::BoxArray, std::allocator<amrex::BoxArray> > const&, ablastr::utils::enums::GridType, bool, bool, bool, bool, std::optional<amrex::Vector<amrex::IntVectND<3>, std::allocator<amrex::IntVectND<3> > > >, std::nullopt_t, std::nullopt_t, std::optional<double const>, std::optional<amrex::Vector<void const*, std::allocator<void const*> > >) /home/runner/work/impactx/impactx/build/_deps/fetchedablastr-src/Source/ablastr/fields/PoissonSolver.H:274:17
2025-01-09T08:33:18.0364422Z     #9 0x55f19d4aee98 in impactx::spacecharge::PoissonSolve(impactx::ImpactXParticleContainer const&, std::unordered_map<int, amrex::MultiFab, std::hash<int>, std::equal_to<int>, std::allocator<std::pair<int const, amrex::MultiFab> > >&, std::unordered_map<int, amrex::MultiFab, std::hash<int>, std::equal_to<int>, std::allocator<std::pair<int const, amrex::MultiFab> > >&, amrex::Vector<amrex::IntVectND<3>, std::allocator<amrex::IntVectND<3> > >) /home/runner/work/impactx/impactx/src/particles/spacecharge/PoissonSolve.cpp:86:9
2025-01-09T08:33:18.0366227Z     #10 0x55f19d276755 in impactx::ImpactX::track_particles() /home/runner/work/impactx/impactx/src/ImpactX.cpp:242:25
2025-01-09T08:33:18.0366879Z     #11 0x55f19d274c88 in impactx::ImpactX::evolve() /home/runner/work/impactx/impactx/src/ImpactX.cpp:131:9
2025-01-09T08:33:18.0367410Z     #12 0x55f19d271bc6 in main /home/runner/work/impactx/impactx/src/main.cpp:37:17
2025-01-09T08:33:18.0368095Z     #13 0x7f934f429d8f  (/lib/x86_64-linux-gnu/libc.so.6+0x29d8f) (BuildId: 490fef8403240c91833978d494d39e537409b92e)
2025-01-09T08:33:18.0368789Z     #14 0x7f934f429e3f in __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e3f) (BuildId: 490fef8403240c91833978d494d39e537409b92e)
2025-01-09T08:33:18.0369794Z     #15 0x55f19d270664 in _start (/home/runner/work/impactx/impactx/build/bin/impactx.MPI.OMP.DP.OPMD+0xa40664) (BuildId: b4035fdd12ac949f554cb2377d329f3b313f917f)

I think the issue is that this global variable in WarpX is never deleted?
https://github.com/ECP-WarpX/WarpX/blob/a56ca8d91e359ce2bad970b7017813e83a51fb02/Source/ablastr/fields/IntegratedGreenFunctionSolver.cpp#L56C67-L56C77

attn @WeiqunZhang @aeriforme @RemiLehe

@ax3l ax3l added the bug Something isn't working label Jan 9, 2025
@ax3l ax3l added component: spectral Spectral solvers (PSATD, IGF) component: electrostatic electrostatic solver bug: affects latest release Bug also exists in latest release version labels Jan 9, 2025
@WeiqunZhang
Copy link
Member

It's deleted two lines below. Maybe you can add a print statement there to see if you see it.

@ax3l
Copy link
Member Author

ax3l commented Jan 9, 2025

That makes sense. But is destroy called in ~OpenBCSolver? That might be the part that is missing.

@ax3l
Copy link
Member Author

ax3l commented Jan 9, 2025

Interesting, I do see amrex::ExecOnFinalize once and then destroy() being called a 7x times for the ImpactX test that shows the issue (linac-segment.run). 5x for the Python test of the same setup.

@WeiqunZhang
Copy link
Member

AMReX-Codes/amrex#4290

ax3l pushed a commit to AMReX-Codes/amrex that referenced this issue Jan 9, 2025
We forgot a test to make sure We only build the plans once.

X-Ref:
- ECP-WarpX/impactx#790
- ECP-WarpX/WarpX#5547
@ax3l
Copy link
Member Author

ax3l commented Jan 10, 2025

Will be pulled in with the next weekly update on Monday.

@ax3l ax3l closed this as completed Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug: affects latest release Bug also exists in latest release version bug Something isn't working component: electrostatic electrostatic solver component: spectral Spectral solvers (PSATD, IGF)
Projects
None yet
Development

No branches or pull requests

2 participants