Skip to content

Commit b093f54

Browse files
committed
Add adios2 dependency and showcase
1 parent b76f755 commit b093f54

4 files changed

Lines changed: 51 additions & 2 deletions

File tree

CMakeLists.txt

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ else()
1515
"For further directions open an issue on GitLab.")
1616
endif()
1717

18-
project(athenaPK LANGUAGES CXX)
18+
project(athenaPK LANGUAGES C CXX)
1919

2020
set(CMAKE_CXX_EXTENSIONS OFF)
2121
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
@@ -63,6 +63,13 @@ if (NOT PARTHENON_DISABLE_MPI)
6363
endif()
6464
endif()
6565

66+
if (NOT ATHENAPK_DISABLE_ADIOS2)
67+
find_package(ADIOS2 REQUIRED)
68+
if (NOT ADIOS2_FOUND)
69+
message(FATAL_ERROR "ADIOS2 requested but couldn't be found. Either set ADIOS2_DIR to the install prefix as hint or disable by setting ATHENAPK_DISABLE_ADIOS2=ON")
70+
endif()
71+
endif()
72+
6673
option(AthenaPK_ENABLE_TESTING "Enable AthenaPK test" ON)
6774
set(PARTHENON_ENABLE_PYTHON_MODULE_CHECK ${AthenaPK_ENABLE_TESTING} CACHE BOOL "Check if local python version contains all modules required for running tests.")
6875

scripts/write_bp.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import numpy as np
2+
from adios2 import Stream
3+
myvar = np.arange(16, dtype=np.float64).reshape(4,4)
4+
nsteps = 1
5+
6+
shape = myvar.shape # .tolist()
7+
start = np.zeros_like(shape).tolist()
8+
count = myvar.shape #.tolist()
9+
10+
with Stream("test.bp", "w") as s:
11+
for _ in s.steps(nsteps):
12+
s.write("myvarname", myvar, shape, start, count)
13+

src/CMakeLists.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,8 @@ add_executable(
2626

2727
add_subdirectory(pgen)
2828

29-
target_link_libraries(athenaPK PRIVATE parthenon)
29+
if (ADIOS2_FOUND)
30+
target_link_libraries(athenaPK PRIVATE parthenon adios2::cxx11_mpi MPI::MPI_C)
31+
else()
32+
target_link_libraries(athenaPK PRIVATE parthenon)
33+
endif()

src/pgen/kh.cpp

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,12 @@
2424
#include <cmath> // log
2525
#include <cstring> // strcmp()
2626

27+
#include <adios2.h>
28+
2729
// Parthenon headers
30+
#include "globals.hpp"
2831
#include "mesh/mesh.hpp"
32+
#include <iostream>
2933
#include <parthenon/driver.hpp>
3034
#include <parthenon/package.hpp>
3135
#include <random>
@@ -57,6 +61,27 @@ void ProblemGenerator(Mesh *pmesh, ParameterInput *pin, MeshData<Real> *md) {
5761
const auto &cons = md->PackVariables(std::vector<std::string>{"cons"});
5862
const auto num_blocks = md->NumBlocks();
5963

64+
// Silly ADIOS2 test
65+
66+
adios2::fstream iStream("test.bp", adios2::fstream::in, MPI_COMM_WORLD);
67+
adios2::fstep iStep;
68+
// There's only a single step in the input file, so there's no issue using the while
69+
// logic here.
70+
while (adios2::getstep(iStream, iStep)) {
71+
// only read row of current rank
72+
const adios2::Dims start{static_cast<unsigned long>(parthenon::Globals::my_rank), 0};
73+
const adios2::Dims count{1, 4};
74+
auto mydata = iStream.read<double>("myvarname", start, count);
75+
std::cerr << "[" << parthenon::Globals::my_rank << "] ";
76+
for (auto var : mydata) {
77+
std::cerr << var << " ";
78+
}
79+
std::cerr << "\n";
80+
// Just to be sure we break (to not read any other steps if present in the bp file)
81+
break;
82+
}
83+
iStream.close();
84+
6085
//--- iprob=1. This was the classic, unresolved K-H test.
6186

6287
//--- iprob=2. Uniform density medium moving at +/-vflow seperated by a single shear

0 commit comments

Comments
 (0)