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 all 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
76 changes: 76 additions & 0 deletions .github/workflows/clang.yml
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,82 @@ jobs:
ccache -s
du -hs ~/.cache/ccache

test_openpmd:
name: openPMD I/O Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Dependencies
run: |
.github/workflows/dependencies/dependencies_clang.sh 15
.github/workflows/dependencies/dependencies_clang-tidy.sh 15
.github/workflows/dependencies/dependencies_ccache.sh
- name: Set Up Cache
uses: actions/cache@v4
with:
path: ~/.cache/ccache
key: ccache-${{ github.workflow }}-${{ github.job }}-git-${{ github.sha }}
restore-keys: |
ccache-${{ github.workflow }}-${{ github.job }}-git-
- name: Install openPMD
run: |
export CCACHE_COMPRESS=1
export CCACHE_COMPRESSLEVEL=10
export CCACHE_MAXSIZE=40M

sudo apt-get install -y --no-install-recommends libhdf5-mpi-dev
wget -q https://github.com/openPMD/openPMD-api/archive/refs/tags/0.15.2.tar.gz
tar xfz 0.15.2.tar.gz
cd openPMD-api-0.15.2
mkdir build
cd build
cmake .. \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache \
-DopenPMD_BUILD_EXAMPLES=OFF \
-DopenPMD_BUILD_CLI_TOOLS=OFF \
-DopenPMD_BUILD_TESTING=OFF \
-DopenPMD_USE_PYTHON=OFF \
make -j4
sudo make install
- name: Build & Test
env: {CXXFLAGS: "-fno-operator-names -Werror -Wall -Wextra -Wpedantic -Wnull-dereference -Wfloat-conversion -Wshadow -Woverloaded-virtual -Wextra-semi -Wunreachable-code -Wnon-virtual-dtor"}
run: |
export CCACHE_COMPRESS=1
export CCACHE_COMPRESSLEVEL=10
export CCACHE_MAXSIZE=40M
export CCACHE_EXTRAFILES=${{ github.workspace }}/.clang-tidy
export CCACHE_LOGFILE=${{ github.workspace }}/ccache.log.txt
ccache -z

mkdir build
cd build
cmake .. \
-DAMReX_OPENPMD=ON \
-DCMAKE_VERBOSE_MAKEFILE=ON \
-DAMReX_ENABLE_TESTS=ON \
-DAMReX_SPACEDIM=3 \
-DAMReX_MPI=ON \
-DAMReX_OMP=OFF \
-DAMReX_FORTRAN=OFF \
-DAMReX_EB=OFF \
-DAMReX_LINEAR_SOLVERS=OFF \
-DAMReX_AMRLEVEL=OFF \
-DAMReX_PARTICLES=ON \
-DCMAKE_C_COMPILER=$(which clang-15) \
-DCMAKE_CXX_COMPILER=$(which clang++-15) \
-DCMAKE_CXX_COMPILER_LAUNCHER=ccache
make -j 4

${{github.workspace}}/Tools/C_scripts/mmclt.py --input ${{github.workspace}}/ccache.log.txt
make -j4 -k -f clang-tidy-ccache-misses.mak \
CLANG_TIDY=clang-tidy-15 \
CLANG_TIDY_ARGS="--config-file=${{github.workspace}}/.clang-tidy --warnings-as-errors=*"

ctest --output-on-failure

ccache -s
du -hs ~/.cache/ccache

save_pr_number:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
Expand Down
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
#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)
add_subdirectory(Extern/openPMD-api)
endif()

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

/** @file This file is included from AMReX_ParticleCounter.H
* 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;

[[nodiscard]] unsigned long long GetTotalNumParticles () const { return m_Total;}

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 long& numParticles,
unsigned long long& offset,
unsigned long long& sum) -> void
{
std::vector<long 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<int(result.size()); i++) {
sum += result[i];
if ( i < m_PtlCounter.m_MPIRank) {
offset += result[i];
}
}
};

for (auto currentLevel = 0; currentLevel <= this->finestLevel(); currentLevel++)
{
// numParticles in this processor
auto numParticles = static_cast<long long>(this->NumberOfParticlesAtLevel(currentLevel, true, true));

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
Loading