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

added openPMD-api support for I/O #3666

Open
wants to merge 27 commits into
base: development
Choose a base branch
from
Open
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
dd3c0c9
added openPMD-api support for I/O
guj Dec 13, 2023
082b97d
make AMREX_USE_OPENPMD_API flag visible
guj Dec 14, 2023
77cb149
ordered include file orders (amrex then openpmd then cpp)
guj Dec 14, 2023
7743fe0
fixed spelling errors
guj Dec 14, 2023
04be86b
Added a comment to address namespace
guj Dec 14, 2023
ea95312
attempt to remove trailing whitespace
guj Dec 14, 2023
52bb537
Merge branch 'development' into use_openpmd-api
WeiqunZhang Jan 4, 2024
ed71097
Add GNU Make support
WeiqunZhang Jan 4, 2024
25f4e2e
Add CI test
WeiqunZhang Jan 4, 2024
0bf1636
Fix warnings
WeiqunZhang Jan 3, 2024
f6a8e7d
bug fix
guj Jan 22, 2024
991055b
Added function SetWriter
guj Jan 25, 2024
996b0ca
Merge branch 'development' into use_openpmd-api
WeiqunZhang Feb 13, 2024
819d7cc
Merge branch 'use_openpmd-api' of github.com:guj/amrex into use_openp…
WeiqunZhang Feb 13, 2024
7f3e742
Add a missing file to CMakeLists.txt
WeiqunZhang Feb 13, 2024
963dcac
update CI
WeiqunZhang Feb 13, 2024
4281967
removed setOpenPMDUnit, and it will be handled by applications
guj Feb 14, 2024
3097051
Update .github/workflows/clang.yml
guj Feb 22, 2024
2a25e66
Update Src/Extern/openPMD-api/AMReX_PlotFileUtilOPENPMD_PTLImpl.H
guj Feb 22, 2024
0de2a0c
Update Tools/CMake/AMReX_Config_ND.H.in
guj Feb 22, 2024
7fa311b
Update .github/workflows/clang.yml
guj Feb 22, 2024
5089ffe
Update Tools/GNUMake/packages/Make.openpmd
guj Feb 22, 2024
fe80e2c
Update Src/CMakeLists.txt
guj Feb 22, 2024
84673fc
shorted flags *OPENPMD_API to *OPENPMD
guj Feb 23, 2024
6d206ca
Apply suggestions from code review
WeiqunZhang Mar 18, 2024
a129a8f
Merge branch 'development' into use_openpmd-api
WeiqunZhang Mar 28, 2024
13f7ff5
Merge branch 'use_openpmd-api' of github.com:guj/amrex into use_openp…
WeiqunZhang Mar 28, 2024
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
4 changes: 4 additions & 0 deletions Src/Base/AMReX_PlotFileUtil.H
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
#include <AMReX_PlotFileUtilHDF5.H>
#endif

#ifdef AMREX_USE_OPENPMD_API
guj marked this conversation as resolved.
Show resolved Hide resolved
#include <AMReX_PlotFileUtilOPENPMD.H>
#endif

#include <ostream>
#include <string>
#include <memory>
Expand Down
4 changes: 4 additions & 0 deletions Src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,10 @@ if (AMReX_HDF5)
add_subdirectory(Extern/HDF5)
endif ()

if (AMReX_OPENPMD_API)
guj marked this conversation as resolved.
Show resolved Hide resolved
add_subdirectory(Extern/openPMD-api)
endif()

#
# Print out summary -- do it here so we already linked all
# libs at this point
Expand Down
85 changes: 85 additions & 0 deletions Src/Extern/openPMD-api/AMReX_ParticlesOPENPMD.H
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
#ifndef AMREX_PTL_OPENPMD_API_H
#define AMREX_PTL_OPENPMD_API_H

/**
* This file is included from AMReX_ParticleCounter.H
WeiqunZhang marked this conversation as resolved.
Show resolved Hide resolved
* and belongs to the class ParticleContainer_impl.
* The namespace amrex was already declared.
*
* Therefore all the definitions in this file belongs to namespace amrex
*/

struct AMReX_PtlCounter
{
int m_MPIRank = 0;
int m_MPISize = 1;

unsigned long long m_Total = 0;

std::vector<unsigned long long> m_ParticleCounterByLevel;

unsigned long GetTotalNumParticles () const { return m_Total;}
WeiqunZhang marked this conversation as resolved.
Show resolved Hide resolved

std::vector<unsigned long long> m_ParticleOffsetAtRank;
std::vector<unsigned long long> m_ParticleSizeAtRank;
};


void CountParticles()
WeiqunZhang marked this conversation as resolved.
Show resolved Hide resolved
{

m_PtlCounter.m_MPISize = amrex::ParallelDescriptor::NProcs();
m_PtlCounter.m_MPIRank = amrex::ParallelDescriptor::MyProc();
Comment on lines +30 to +31
Copy link
Member

Choose a reason for hiding this comment

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

AMReX includes for ParallelDescriptor, ParallelGather, <vector> missing in this file.

Copy link
Author

Choose a reason for hiding this comment

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

This file is currently embedded in AMReX_ParticleContainer.H, which has all the included files declared already.


m_PtlCounter.m_ParticleCounterByLevel.resize(this->finestLevel()+1);
m_PtlCounter.m_ParticleOffsetAtRank.resize(this->finestLevel()+1);
m_PtlCounter.m_ParticleSizeAtRank.resize(this->finestLevel()+1);

auto lf_GetParticleOffsetOfProcessor = [&](const long& numParticles,
unsigned long long& offset,
unsigned long long& sum) -> void
{
std::vector<long> result(m_PtlCounter.m_MPISize, 0);
amrex::ParallelGather::Gather (numParticles, result.data(), -1, amrex::ParallelDescriptor::Communicator());

sum = 0;
offset = 0;
for (int i=0; i<result.size(); i++) {
WeiqunZhang marked this conversation as resolved.
Show resolved Hide resolved
sum += result[i];
if ( i < m_PtlCounter.m_MPIRank)
offset += result[i];
}
};

for (auto currentLevel = 0; currentLevel <= this->finestLevel(); currentLevel++)
{
long numParticles = 0; // numParticles in this processor
WeiqunZhang marked this conversation as resolved.
Show resolved Hide resolved

//for (ParIter pti(*this, currentLevel); pti.isValid(); ++pti) {
for (ParConstIterType pti(*this, currentLevel); pti.isValid(); ++pti) {
auto numParticleOnTile = pti.numParticles();
numParticles += numParticleOnTile;
}

unsigned long long offset=0; // offset of this level
unsigned long long sum=0; // numParticles in this level (sum from all processors)
lf_GetParticleOffsetOfProcessor(numParticles, offset, sum);

m_PtlCounter.m_ParticleCounterByLevel[currentLevel] = sum;
m_PtlCounter.m_ParticleOffsetAtRank[currentLevel] = offset;
m_PtlCounter.m_ParticleSizeAtRank[currentLevel] = numParticles;

// adjust offset, it should be numbered after particles from previous levels
for (auto lv=0; lv<currentLevel; lv++)
{
m_PtlCounter.m_ParticleOffsetAtRank[currentLevel] += m_PtlCounter.m_ParticleCounterByLevel[lv];
}

m_PtlCounter.m_Total += sum;
}
}

AMReX_PtlCounter m_PtlCounter;
Copy link
Member

Choose a reason for hiding this comment

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

This would result in multiple definitions if this header is included in more than one translation units.

Copy link
Author

Choose a reason for hiding this comment

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

This eventually is a member variable of class ParticleContainer_impl, as this file is included in "AMReX_ParticleContainer.H".

Copy link
Member

Choose a reason for hiding this comment

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

Instead of plain text including this into another class, which will complicate our transition to C++ modules and is a bit surprising in general, consider making this a C++ mixin class:
https://en.wikipedia.org/wiki/Mixin

Simply derive ParticleContainer_impl from this.

Copy link
Author

Choose a reason for hiding this comment

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

The extra code in this file is a function that figures out ptl offsets for each processors. I think using mixin possibly will be an overkill, and clients need to change their code when initialing ParticleContainer_impl related classes.

Since this is only used by openPMD-api, I will move this function into the amex::openpmd_api scope. Leave the AMReX_ParticleContainer.H as is.

#endif // AMREX_PTL_OPENPMD_API_H


Loading