Skip to content

Commit 36b116f

Browse files
committed
Python test
1 parent 0dc56ab commit 36b116f

File tree

2 files changed

+63
-19
lines changed

2 files changed

+63
-19
lines changed

examples/5_write_parallel.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@
1414
import numpy as np
1515
import openpmd_api as io
1616

17+
try:
18+
import adios2
19+
from packaging import version
20+
USE_JOINED_DIMENSION = \
21+
version.parse(adios2.__version__) >= version.parse('2.9.0')
22+
except ImportError:
23+
USE_JOINED_DIMENSION = False
1724
if __name__ == "__main__":
1825
# also works with any other MPI communicator
1926
comm = MPI.COMM_WORLD
@@ -29,7 +36,9 @@
2936

3037
# open file for writing
3138
series = io.Series(
32-
"../samples/5_parallel_write_py.h5",
39+
"../samples/5_parallel_write_py.bp"
40+
if USE_JOINED_DIMENSION
41+
else "../samples/5_parallel_write_py.bp",
3342
io.Access.create,
3443
comm
3544
)
@@ -51,7 +60,9 @@
5160
meshes["mymesh"]
5261

5362
# example 1D domain decomposition in first index
54-
global_extent = [comm.size * 10, 300]
63+
global_extent = [io.Dataset.JOINED_DIMENSION, 300] \
64+
if USE_JOINED_DIMENSION else [comm.size * 10, 300]
65+
5566
dataset = io.Dataset(local_data.dtype, global_extent)
5667

5768
if 0 == comm.rank:
@@ -64,7 +75,11 @@
6475
"mymesh in iteration 1")
6576

6677
# example shows a 1D domain decomposition in first index
67-
mymesh[comm.rank*10:(comm.rank+1)*10, :] = local_data
78+
79+
if USE_JOINED_DIMENSION:
80+
mymesh.store_chunk(local_data, [], [10, 300])
81+
else:
82+
mymesh[comm.rank*10:(comm.rank+1)*10, :] = local_data
6883
if 0 == comm.rank:
6984
print("Registered a single chunk per MPI rank containing its "
7085
"contribution, ready to write content to disk")

src/binding/python/RecordComponent.cpp

Lines changed: 45 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -265,23 +265,52 @@ inline void store_chunk(
265265
"in record component (") +
266266
std::to_string(r_shape.size()) + std::string("D)"));
267267

268-
for (auto d = 0; d < a.ndim(); ++d)
268+
if (auto joined_dim = r.joinedDimension(); joined_dim.has_value())
269269
{
270-
// selection causes overflow of r
271-
if (offset.at(d) + extent.at(d) > r_shape.at(d))
272-
throw py::index_error(
273-
std::string("slice ") + std::to_string(offset.at(d)) +
274-
std::string(":") + std::to_string(extent.at(d)) +
275-
std::string(" is out of bounds for axis ") + std::to_string(d) +
276-
std::string(" with size ") + std::to_string(r_shape.at(d)));
277-
// underflow of selection in r for given a
278-
if (s_shape.at(d) != std::uint64_t(a.shape()[d]))
279-
throw py::index_error(
280-
std::string("size of chunk (") + std::to_string(a.shape()[d]) +
281-
std::string(") for axis ") + std::to_string(d) +
282-
std::string(" does not match selection ") +
283-
std::string("size in record component (") +
284-
std::to_string(s_extent.at(d)) + std::string(")"));
270+
for (py::ssize_t d = 0; d < a.ndim(); ++d)
271+
{
272+
// selection causes overflow of r
273+
if (d != py::ssize_t(*joined_dim) && extent.at(d) != r_shape.at(d))
274+
throw py::index_error(
275+
std::string("selection for axis ") + std::to_string(d) +
276+
" of record component with joined dimension " +
277+
std::to_string(*joined_dim) +
278+
" must be equivalent to its global extent " +
279+
std::to_string(extent.at(d)) + ", but was " +
280+
std::to_string(r_shape.at(d)) + ".");
281+
// underflow of selection in r for given a
282+
if (s_shape.at(d) != std::uint64_t(a.shape()[d]))
283+
throw py::index_error(
284+
std::string("size of chunk (") +
285+
std::to_string(a.shape()[d]) + std::string(") for axis ") +
286+
std::to_string(d) +
287+
std::string(" does not match selection ") +
288+
std::string("size in record component (") +
289+
std::to_string(s_extent.at(d)) + std::string(")"));
290+
}
291+
}
292+
else
293+
{
294+
for (auto d = 0; d < a.ndim(); ++d)
295+
{
296+
// selection causes overflow of r
297+
if (offset.at(d) + extent.at(d) > r_shape.at(d))
298+
throw py::index_error(
299+
std::string("slice ") + std::to_string(offset.at(d)) +
300+
std::string(":") + std::to_string(extent.at(d)) +
301+
std::string(" is out of bounds for axis ") +
302+
std::to_string(d) + std::string(" with size ") +
303+
std::to_string(r_shape.at(d)));
304+
// underflow of selection in r for given a
305+
if (s_shape.at(d) != std::uint64_t(a.shape()[d]))
306+
throw py::index_error(
307+
std::string("size of chunk (") +
308+
std::to_string(a.shape()[d]) + std::string(") for axis ") +
309+
std::to_string(d) +
310+
std::string(" does not match selection ") +
311+
std::string("size in record component (") +
312+
std::to_string(s_extent.at(d)) + std::string(")"));
313+
}
285314
}
286315

287316
check_buffer_is_contiguous(a);

0 commit comments

Comments
 (0)