Skip to content

Commit dd3c0c9

Browse files
committed
added openPMD-api support for I/O
1 parent 064db4e commit dd3c0c9

29 files changed

+3531
-0
lines changed

Src/Base/AMReX_PlotFileUtil.H

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
#include <string>
1717
#include <memory>
1818

19+
#ifdef AMREX_USE_OPENPMD_API
20+
#include <AMReX_PlotFileUtilOPENPMD.H>
21+
#endif
22+
1923
namespace amrex
2024
{
2125
//! return the name of the level directory, e.g., Level_5

Src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,10 @@ if (AMReX_HDF5)
200200
add_subdirectory(Extern/HDF5)
201201
endif ()
202202

203+
if (AMReX_OPENPMD_API)
204+
add_subdirectory(Extern/openPMD-api)
205+
endif()
206+
203207
#
204208
# Print out summary -- do it here so we already linked all
205209
# libs at this point
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
#ifndef AMREX_PTL_OPENPMD_API_H
2+
#define AMREX_PTL_OPENPMD_API_H
3+
4+
//#include <openPMD/openpmd.hpp>
5+
6+
7+
struct AMReX_PtlCounter
8+
{
9+
int m_MPIRank = 0;
10+
int m_MPISize = 1;
11+
12+
unsigned long long m_Total = 0;
13+
14+
std::vector<unsigned long long> m_ParticleCounterByLevel;
15+
16+
unsigned long GetTotalNumParticles () const { return m_Total;}
17+
18+
std::vector<unsigned long long> m_ParticleOffsetAtRank;
19+
std::vector<unsigned long long> m_ParticleSizeAtRank;
20+
};
21+
22+
23+
void CountParticles()
24+
{
25+
26+
m_PtlCounter.m_MPISize = amrex::ParallelDescriptor::NProcs();
27+
m_PtlCounter.m_MPIRank = amrex::ParallelDescriptor::MyProc();
28+
29+
m_PtlCounter.m_ParticleCounterByLevel.resize(this->finestLevel()+1);
30+
m_PtlCounter.m_ParticleOffsetAtRank.resize(this->finestLevel()+1);
31+
m_PtlCounter.m_ParticleSizeAtRank.resize(this->finestLevel()+1);
32+
33+
auto lf_GetParticleOffsetOfProcessor = [&](const long& numParticles,
34+
unsigned long long& offset,
35+
unsigned long long& sum) -> void
36+
{
37+
std::vector<long> result(m_PtlCounter.m_MPISize, 0);
38+
amrex::ParallelGather::Gather (numParticles, result.data(), -1, amrex::ParallelDescriptor::Communicator());
39+
40+
sum = 0;
41+
offset = 0;
42+
for (int i=0; i<result.size(); i++) {
43+
sum += result[i];
44+
if ( i < m_PtlCounter.m_MPIRank)
45+
offset += result[i];
46+
}
47+
};
48+
49+
for (auto currentLevel = 0; currentLevel <= this->finestLevel(); currentLevel++)
50+
{
51+
long numParticles = 0; // numParticles in this processor
52+
53+
//for (ParIter pti(*this, currentLevel); pti.isValid(); ++pti) {
54+
for (ParConstIterType pti(*this, currentLevel); pti.isValid(); ++pti) {
55+
auto numParticleOnTile = pti.numParticles();
56+
numParticles += numParticleOnTile;
57+
}
58+
59+
unsigned long long offset=0; // offset of this level
60+
unsigned long long sum=0; // numParticles in this level (sum from all processors)
61+
lf_GetParticleOffsetOfProcessor(numParticles, offset, sum);
62+
63+
m_PtlCounter.m_ParticleCounterByLevel[currentLevel] = sum;
64+
m_PtlCounter.m_ParticleOffsetAtRank[currentLevel] = offset;
65+
m_PtlCounter.m_ParticleSizeAtRank[currentLevel] = numParticles;
66+
67+
// adjust offset, it should be numbered after particles from previous levels
68+
for (auto lv=0; lv<currentLevel; lv++)
69+
{
70+
m_PtlCounter.m_ParticleOffsetAtRank[currentLevel] += m_PtlCounter.m_ParticleCounterByLevel[lv];
71+
}
72+
73+
m_PtlCounter.m_Total += sum;
74+
}
75+
}
76+
77+
AMReX_PtlCounter m_PtlCounter;
78+
#endif // AMREX_PTL_OPENPMD_API_H
79+
80+

0 commit comments

Comments
 (0)