forked from AMReX-Codes/amrex
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
29 changed files
with
3,531 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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;} | ||
|
||
std::vector<unsigned long long> m_ParticleOffsetAtRank; | ||
std::vector<unsigned long long> m_ParticleSizeAtRank; | ||
}; | ||
|
||
|
||
void CountParticles() | ||
{ | ||
|
||
m_PtlCounter.m_MPISize = amrex::ParallelDescriptor::NProcs(); | ||
m_PtlCounter.m_MPIRank = amrex::ParallelDescriptor::MyProc(); | ||
|
||
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++) { | ||
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 | ||
|
||
//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; | ||
#endif // AMREX_PTL_OPENPMD_API_H | ||
|
||
|
Oops, something went wrong.