Skip to content

Commit

Permalink
MFIter::Finalize (AMReX-Codes#2983)
Browse files Browse the repository at this point in the history
Add a Finalize function to MFIter.

The idea about this is, that we can call this already before destruction
in Python, where `for` loops do not create scope.

This function must be robust enough to be called again in the
constructor (or we need to add an extra bool to guard that it is not
called again in the destructor).

Co-authored-by: Weiqun Zhang <[email protected]>
  • Loading branch information
ax3l and WeiqunZhang authored Oct 11, 2022
1 parent 53e34d1 commit 5acfe07
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Src/Base/AMReX_MFIter.H
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ protected:
IndexType typ;

bool dynamic;
bool finalized = false;

struct DeviceSync {
DeviceSync () = default;
Expand All @@ -201,6 +202,7 @@ protected:
static AMREX_EXPORT int allow_multiple_mfiters;

void Initialize ();
void Finalize ();
};

//! Is it safe to have these two MultiFabs in the same MFiter?
Expand Down
9 changes: 9 additions & 0 deletions Src/Base/AMReX_MFIter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,15 @@ MFIter::MFIter (const FabArrayBase& fabarray_, const MFItInfo& info)

MFIter::~MFIter ()
{
Finalize();
}

void
MFIter::Finalize ()
{
if (finalized) return;
finalized = true;

#ifdef AMREX_USE_OMP
#pragma omp master
#endif
Expand Down

0 comments on commit 5acfe07

Please sign in to comment.