AMReX-Codes / amrex

AMReX: Software Framework for Block Structured AMR
https://amrex-codes.github.io/amrex
Other
503 stars 336 forks source link

Segfault using FillPatcher with recent AMReX versions #3940

Closed amg56 closed 1 month ago

amg56 commented 1 month ago

Since commit 1735fd5, I have been getting segfaults in my code when using the FillPatcher class in AmrCore. It happens at this line in FillPatcher.H, currently 393:

cbc(*m_cf_crse_data_tmp, 0, ncomp, nghost, time, cbccomp);

From what I can gather, m_cf_crse_data_tmp doesn't have any ghost cells, so expanding m_cf_crse_data_tmp's validbox by the 'nghost' values of the parent MultiFabs (as per commit 1735fd5) can lead to it trying to fill in boundary conditions of non-existent cells. Which might well be expected to cause segfaults. However, I can't seem to reproduce the segfaults I'm getting with Tests/Amr/Advection_AmrCore, after turning off periodicity and uncommenting the 'walls (Neumann)' BC code lines. So I'm not completely sure that it isn't something I'm doing wrong in my code.

For me, changing nghost in the code above to m_cf_crse_data_tmp->nGrowVect(), i.e. setting nghost to (0,0,0), gets rid of the segfaults. But I'm not sure if this is the correct fix or not.

Would be good to hear what you think. Thanks!

cgilet commented 1 month ago

Could you try this https://github.com/AMReX-Codes/amrex/pull/3941 ; compiling with USE_ASSERTION = TRUE or DEBUG = TRUE

amg56 commented 1 month ago

Yes, that runs fine in my code with DEBUG on, no issues. Unless I revert the changes to FillPatcher, then it correctly flags the problem with Assertion 'nghost <= mf.nGrowVect()' failed.

Thanks for the prompt response!

WeiqunZhang commented 1 month ago

Thanks for reporting!