Skip to content

Commit

Permalink
added openPMD-api support for I/O
Browse files Browse the repository at this point in the history
  • Loading branch information
guj committed Dec 13, 2023
1 parent 064db4e commit dd3c0c9
Show file tree
Hide file tree
Showing 29 changed files with 3,531 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Src/Base/AMReX_PlotFileUtil.H
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
#include <string>
#include <memory>

#ifdef AMREX_USE_OPENPMD_API
#include <AMReX_PlotFileUtilOPENPMD.H>
#endif

namespace amrex
{
//! return the name of the level directory, e.g., Level_5
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)
add_subdirectory(Extern/openPMD-api)
endif()

#
# Print out summary -- do it here so we already linked all
# libs at this point
Expand Down
80 changes: 80 additions & 0 deletions Src/Extern/openPMD-api/AMReX_ParticlesOPENPMD.H
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


Loading

0 comments on commit dd3c0c9

Please sign in to comment.