-
Notifications
You must be signed in to change notification settings - Fork 409
added openPMD-api support for I/O #3666
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
base: development
Are you sure you want to change the base?
Changes from 1 commit
dd3c0c9
082b97d
77cb149
7743fe0
04be86b
ea95312
52bb537
ed71097
25f4e2e
0bf1636
f6a8e7d
991055b
996b0ca
819d7cc
7f3e742
963dcac
4281967
3097051
2a25e66
0de2a0c
7fa311b
5089ffe
fe80e2c
84673fc
6d206ca
a129a8f
13f7ff5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
#ifndef AMREX_PTL_OPENPMD_API_H | ||
#define AMREX_PTL_OPENPMD_API_H | ||
|
||
//#include <openPMD/openpmd.hpp> | ||
|
||
|
||
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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. AMReX includes for There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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". There was a problem hiding this comment. Choose a reason for hiding this commentThe 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: Simply derive There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
||
|
Uh oh!
There was an error while loading. Please reload this page.