AMReX-Codes / amrex

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

Add std::setfill to PrintMemStats #4147

Closed AlexanderSinn closed 2 months ago

AlexanderSinn commented 2 months ago

Summary

Set the fill in TinyProfiler::PrintMemStats to ' ' instead of '0'.

Additional background

This PR fixes the output looking like this:

Device Memory Usage:
---------------------------------------------------------------------------------
Name00000000000000000000000000000000000000000000Nalloc00Nfree0000AvgMem0000MaxMem
---------------------------------------------------------------------------------
The_Arena::Initialize()00000000000000000000000000000010000001001259 KiB000029 GiB
MultiLaser::InitData()000000000000000000000000000000030000003002948 MiB002948 MiB
Fields::AllocData()000000000000000000000000000000000010000001002820 MiB002821 MiB
PlasmaParticleContainer::InitParticles()000000000000170000017001597 MiB001727 MiB
MultiLaser::AdvanceSliceMG()000000000000000000000000400000040001090 MiB001110 MiB
Hipace::ExplicitMGSolveBxBy()00000000000000000000000400000040000921 MiB000939 MiB
FFTPoissonSolverDirichletFast::define()0000000000000070000007000639 MiB000640 MiB
ResizeRandomSeed000000000000000000000000000000000000010000001000040 MiB000040 MiB
BeamParticleContainer::InSituComputeDiags()000000010000001000002115   B004968 KiB
MultiLaser::InSituComputeDiags()00000000000000000010000001000007572   B001728 KiB
hpmg::MultiGrid::solve2()000000000000000000000000029590002959000045 KiB000432 KiB
hpmg::MultiGrid::solve1()000000000000000000000000021990002199000030 KiB000432 KiB
shiftSlippedParticles()00000000000000000000000000001620000162000011   B000108 KiB
sortBeamParticlesByBox()0000000000000000000000000000040000004000078 KiB000094 KiB
BeamParticleContainer::InitBeamFixedWeight3D()000000010000001000078 KiB000078 KiB
BeamParticleContainer::resize()000000000000000000003380000338000014 KiB000054 KiB
main()0000000000000000000000000000000000000000000000090000009001087   B001088   B
Hipace::InitData()0000000000000000000000000000000000030000003000143   B000144   B
Fields::Copy()00000000000000000000000000000000000000010000001000031   B000032   B
DepositCurrent_PlasmaParticleContainer()000000000010010001001000000   B000016   B
---------------------------------------------------------------------------------

Managed Memory Usage:
----------------------------------------------------------------
Name00000000000000000000000000000Nalloc00Nfree00AvgMem0000MaxMem
----------------------------------------------------------------
The_Managed_Arena::Initialize()0000000100000010010   B008192 KiB
----------------------------------------------------------------

Pinned Memory Usage:
------------------------------------------------------------------------------
Name00000000000000000000000000000000000000000Nalloc00Nfree0000AvgMem0000MaxMem
------------------------------------------------------------------------------
Diagnostic::ResizeFDiagFAB()000000000000000000000020000002001183 MiB001187 MiB
The_Pinned_Arena::Initialize()0000000000000000000010000001000781   B008192 KiB
OpenPMDWriter::InitBeamData()00000000000000000000080000008000576 KiB000625 KiB
Hipace::InitData()0000000000000000000000000000000190000019000015 KiB000015 KiB
main()0000000000000000000000000000000000000000000670000067001087   B001120   B
Hipace::ExplicitMGSolveBxBy()00000000000000000000010000001000753   B000768   B
MultiLaser::AdvanceSliceMG()000000000000000000000010000001000754   B000768   B
BeamParticleContainer::InSituComputeDiags()000010000001000000000   B000192   B
MultiLaser::InSituComputeDiags()00000000000000010000001000000000   B000064   B
Fields::Copy()00000000000000000000000000000000000010000001000031   B000032   B
PlasmaParticleContainer::InitParticles()000000000010000001000000   B000016   B
hpmg::MultiGrid::solve1()000000000000000000000021990002199000001   B000016   B
hpmg::MultiGrid::solve2()000000000000000000000029590002959000002   B000016   B
shiftSlippedParticles()00000000000000000000000001620000162000000   B000016   B
------------------------------------------------------------------------------

Checklist

The proposed changes:

WeiqunZhang commented 2 months ago

Yes, we should fix it. But where is the fill character set to '0'? Is it in Hipace++? If it's in amrex, we need to fix that too.

AlexanderSinn commented 2 months ago

There indeed is a std::setfill('0') in hipace, but searching setfill in amrex also gives some results. 

WeiqunZhang commented 2 months ago

If it's used on a local stream, it's okay.

WeiqunZhang commented 2 months ago

like this one in AMReX_String.cpp

    std::stringstream result;
    result << root << std::setfill('0') << std::setw(mindigits) << num;
AlexanderSinn commented 2 months ago

It was used here https://github.com/Hi-PACE/hipace/blob/40fed7b01b1b985ecd6b417c37ec99d76ef2bc7a/src/Hipace.cpp#L431 https://github.com/Hi-PACE/hipace/pull/1159

WeiqunZhang commented 2 months ago

You can use IOFormatSaver in format_time to remove the side effect.