Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
7a29e92
Adding func to return mem capacity/usage of fabs within a box
jessdagostini Aug 27, 2025
20d8658
Adding functions to return mem capacity/usage from particles within a…
jessdagostini Aug 27, 2025
b615a4e
Update: update CapacityOfFabs parameters based on #4629 PR discussion
jessdagostini Aug 29, 2025
db786f3
Moving capacityOfFabs function from MultiFab to FabArray
jessdagostini Sep 3, 2025
1bbf3ca
Adding assertion on capacityOfFabs
jessdagostini Sep 4, 2025
5f0f788
Fixing reference
jessdagostini Sep 4, 2025
a390353
Removing reference to capacityOfFabs function on MultiFabUtil
jessdagostini Sep 4, 2025
7fb20d4
Change capacity function on particles to have similar signature as Fa…
jessdagostini Sep 4, 2025
fb94457
Update Src/Base/AMReX_FabArray.H
jessdagostini Sep 5, 2025
6c0e6e2
Fixing reference to CellEqual func
jessdagostini Sep 5, 2025
6b231b7
Pushing tests for memory capturing (based on amrex-tutorials)
jessdagostini Sep 5, 2025
bad61d0
Fixing pipeline issues
jessdagostini Sep 5, 2025
8034c87
Update Src/Base/AMReX_FabArray.H
jessdagostini Sep 11, 2025
2d2ddd0
Update Src/Base/AMReX_FabArray.H
jessdagostini Sep 11, 2025
6cf35fa
Update Src/Base/AMReX_FabArray.H
jessdagostini Sep 11, 2025
327a241
Update Src/Particle/AMReX_ParticleContainerI.H
jessdagostini Sep 11, 2025
6c0d68e
Update Src/Particle/AMReX_ParticleContainerI.H
jessdagostini Sep 11, 2025
58114a0
Update Src/Particle/AMReX_ParticleContainer.H
jessdagostini Sep 11, 2025
84bbf37
Updating template signature for FabArray capacity func
jessdagostini Sep 12, 2025
55d4a34
Updating Particles function signature and testing
jessdagostini Sep 12, 2025
64e1e84
Finishing reorganization of tests
jessdagostini Sep 16, 2025
2b01097
Including HeatEquation test on CMakeLists
jessdagostini Sep 16, 2025
c399f60
Merge branch 'development' into development
jessdagostini Sep 16, 2025
63b21a5
Update Tests/CMakeLists.txt
WeiqunZhang Sep 17, 2025
11dd878
Merge branch 'development' into jessdagostini/development
WeiqunZhang Sep 17, 2025
30ec777
cat doxygen.out
WeiqunZhang Sep 17, 2025
d648a26
workaround doxygen issue
WeiqunZhang Sep 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions Src/Base/AMReX_FabArray.H
Original file line number Diff line number Diff line change
Expand Up @@ -817,6 +817,10 @@ public:
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
void setDomainBndry (value_type val, int strt_comp, int ncomp, const Geometry& geom);

// Get capacity of the FabArray
template <class F=FAB, std::enable_if_t<IsBaseFab<F>::value,int> = 0>
Copy link
Member

@WeiqunZhang WeiqunZhang Sep 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For flexibility, we could also make the integer type a template typename here and for in particle containers. For example,

template <typename I, class F=FAB, std::enable_if_t<IsBaseFab<F>::value && std::is_integral_v<I> && sizeof(I) >= sizeof(Long), int> = 0>
void capacityOfFabs (LayoutData<I>& mem) const;

And in the implementation, we also want to do explicit static_cast before adding the values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok! Working on the update for this!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, do you think it's worth doing it? Because I know that it is a best practice in C++ to use std::size_t for memory-related math (size_t was created for holding sizeof returns https://en.cppreference.com/w/cpp/types/size_t.html)

Copy link
Member

@WeiqunZhang WeiqunZhang Sep 11, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually the best practice is proably to avoid unsigned integers in almost all cases.

Even Stroustrup does not like unsigned integers. https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2019/p1428r0.pdf Stroustrup said,

Unfortunately, sizeof yields an unsigned (and it would be hard to change that), but we don’t have to
follow that for all types with something to do with sizes

Java does not even have build-in unsigned integer types. https://www.artima.com/articles/james-gosling-on-java-may-2001 Goshling said,

In programming language design, one of the standard problems is that the language grows so complex that nobody can understand it. One of the little experiments I tried was asking people about the rules for unsigned arithmetic in C. It turns out nobody understands how unsigned arithmetic in C works. There are a few obvious things that people understand, but many people don't understand it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, got it! Interesting that the unsigned is such unknown territory. Will start working on including the template you suggested in both functions

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just update both function signatures with the new template 55d4a34

void capacityOfFabs (LayoutData<std::size_t>& mem);

/**
* \brief Returns the sum of component "comp"
*
Expand Down Expand Up @@ -2506,6 +2510,17 @@ FabArray<FAB>::setDomainBndry (value_type val,
}
}

template <class FAB>
template <class F, std::enable_if_t<IsBaseFab<F>::value,int> FOO>
void
FabArray<FAB>::capacityOfFabs(LayoutData<std::size_t>& mem) {
AMREX_ASSERT(*this.CellEqual(mem.boxArray()) &&
this->DistributionMap() == mem.DistributionMap());
for (MFIter mfi(*this, MFItInfo{}.DisableDeviceSync()); mfi.isValid(); ++mfi) {
mem[mfi] += (*this)[mfi].nBytesOwned();
}
}

template <class FAB>
template <class F, std::enable_if_t<IsBaseFab<F>::value,int> FOO>
typename F::value_type
Expand Down
4 changes: 4 additions & 0 deletions Src/Base/AMReX_MultiFabUtil.H
Original file line number Diff line number Diff line change
Expand Up @@ -1070,6 +1070,10 @@ void average_down_faces (const FabArray<FAB>& fine, FabArray<FAB>& crse,
crse.ParallelCopy(ctmp,0,0,crse.nComp(),0,0,crse_geom.periodicity());
}

// Compute the memory capacity (in bytes) used by a Box
// We have tried to work with more templated version, but it didn't work. What is the most appropriate way to do it?
LayoutData<std::size_t> CapacityOfFabs (const Vector<const MultiFab*>& mfs);

template <typename MF, std::enable_if_t<IsFabArray<MF>::value,int> FOO>
Vector<typename MF::value_type> get_cell_data (MF const& mf, IntVect const& cell)
{
Expand Down
2 changes: 2 additions & 0 deletions Src/Particle/AMReX_ParIter.H
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ public:

[[nodiscard]] int numNeighborParticles () const { return GetParticleTile().numNeighborParticles(); }

[[nodiscard]] Long capacity () const { return GetParticleTile().capacity(); }

[[nodiscard]] int GetLevel () const { return m_level; }

[[nodiscard]] std::pair<int, int> GetPairIndex () const { return std::make_pair(this->index(), this->LocalTileIndex()); }
Expand Down
6 changes: 6 additions & 0 deletions Src/Particle/AMReX_ParticleContainer.H
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,12 @@ public:

Vector<Long> NumberOfParticlesInGrid (int level, bool only_valid = true, bool only_local = false) const;

/**
* \brief Return capacity of memory for particles at specific grid
*/

LayoutData<std::size_t> CapacityOfParticlesInGrid (int lev) const;

/**
* \brief Returns # of particles at all levels
*
Expand Down
19 changes: 19 additions & 0 deletions Src/Particle/AMReX_ParticleContainerI.H
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,25 @@ Long ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, Cell
return nparticles;
}

template <typename ParticleType, int NArrayReal, int NArrayInt,
template<class> class Allocator, class CellAssignor>
LayoutData<std::size_t>
ParticleContainer_impl<ParticleType, NArrayReal, NArrayInt, Allocator, CellAssignor>::CapacityOfParticlesInGrid (int lev) const
{
AMREX_ASSERT(lev >= 0 && lev < int(m_particles.size()));

LayoutData<std::size_t> mem_per_grid_local(ParticleBoxArray(lev),
ParticleDistributionMap(lev));

for (ParConstIterType pti(*this, lev); pti.isValid(); ++pti)
{
int gid = pti.index();
mem_per_grid_local[gid] += (std::size_t)pti.capacity();
}

return mem_per_grid_local;
}

//
// This includes both valid and invalid particles since invalid particles still take up space.
//
Expand Down
Loading