Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
3 changes: 2 additions & 1 deletion bindings/Python/py11Engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,8 @@ std::vector<std::map<std::string, std::string>> Engine::BlocksInfo(std::string &
MinVarInfo *minBlocksInfo = nullptr;

auto Variable = itVariable->second.get();
minBlocksInfo = m_Engine->MinBlocksInfo(*Variable, 0);
size_t s = (m_Engine->m_OpenMode == Mode::ReadRandomAccess ? step : 0);
minBlocksInfo = m_Engine->MinBlocksInfo(*Variable, s);
if (minBlocksInfo)
{
for (auto &info : minBlocksInfo->BlocksInfo)
Expand Down
2 changes: 1 addition & 1 deletion python/adios2/stream.py
Original file line number Diff line number Diff line change
Expand Up @@ -315,7 +315,7 @@ def _(self, name, content, shape=[], start=[], count=[], operations=None):
if shape != [] and not variable.single_value():
variable.set_shape(shape)

if start != [] and count != []:
if start != [] or count != []:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought start and count need to match in length

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For local arrays, start is empty, just like shape.

variable.set_selection([start, count])

if operations:
Expand Down
106 changes: 86 additions & 20 deletions testing/adios2/python/TestBPWriteTypesHighLevelAPILocal.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,30 @@ def check_array(np1, np2, hint):

# Test data
data = SmallTestData(rank)
nx = data.Nx

shape = []
start = []
count = [nx]


# Writer
with Stream("types_np_local.bp", "w", comm=comm) as s:
for step in s.steps(5):
data.update(rank, step.current_step(), size)
for _ in s.steps(5):
step = s.current_step()
nx = data.Nx - rank - step
if nx < 1:
nx = data.Nx
shape = []
start = []
count = [nx]

if step == 0 and size > 1 and rank == size - 1:
continue

data.update(rank, step, size)
s.write("varI8", data.i8, shape, start, count)
s.write("varI16", data.i16, shape, start, count)
v = s.inquire_variable("varI16")
print(
f"step {step} rank {rank} nx {nx} count = {v.count()} data.I16 = {data.i16[:nx]}",
flush=True,
)

s.write("varI32", data.i32, shape, start, count)
s.write("varI64", data.i64, shape, start, count)
s.write("varU8", data.u8, shape, start, count)
Expand All @@ -53,9 +64,21 @@ def check_array(np1, np2, hint):
# Reader
data = SmallTestData(rank)

if rank == 0:
print("====================================", flush=True)
print("Read data block by block", flush=True)
comm.Barrier()

with Stream("types_np_local.bp", "r", comm=comm) as s:
for fr_step in s.steps():
step = fr_step.current_step()
nx = data.Nx - rank - step
if nx < 1:
nx = data.Nx

if step == 0 and size > 1 and rank == size - 1:
continue

data.update(rank, step, size)
indataI8 = fr_step.read("varI8", block_id=rank)
indataI16 = fr_step.read("varI16", block_id=rank)
Expand All @@ -70,15 +93,58 @@ def check_array(np1, np2, hint):

in_int_list = fr_step.read("an_int_list", block_id=rank)

print(f"step {step} rank {rank} I16={indataI16} data.I16 = {data.i16}", flush=True)

check_array(indataI8, data.i8, "i8")
check_array(indataI16, data.i16, "i16")
check_array(indataI32, data.i32, "i32")
check_array(indataI64, data.i64, "i64")
check_array(indataU8, data.u8, "u8")
check_array(indataU16, data.u16, "u16")
check_array(indataU32, data.u32, "u32")
check_array(indataU64, data.u64, "u64")
check_array(indataR32, data.r32, "r32")
check_array(indataR64, data.r64, "r64")
print(
f"step {step} rank {rank} nx {nx} I16={indataI16} data.I16 = {data.i16[:nx]}",
flush=True,
)

check_array(indataI8, data.i8[:nx], "i8")
check_array(indataI16, data.i16[:nx], "i16")
check_array(indataI32, data.i32[:nx], "i32")
check_array(indataI64, data.i64[:nx], "i64")
check_array(indataU8, data.u8[:nx], "u8")
check_array(indataU16, data.u16[:nx], "u16")
check_array(indataU32, data.u32[:nx], "u32")
check_array(indataU64, data.u64[:nx], "u64")
check_array(indataR32, data.r32[:nx], "r32")
check_array(indataR64, data.r64[:nx], "r64")

if rank == 0:
print("====================================", flush=True)
print("Test blocks_info", flush=True)
with Stream("types_np_local.bp", "rra") as f:
v = f.inquire_variable("varI16")
for step in range(v.steps()):
bis = f.engine.blocks_info("varI16", step)
expected_num_blocks = size
if step == 0 and size > 1:
expected_num_blocks = size - 1
print(
f"step {step} rank {rank} number of blocks expected = {expected_num_blocks}"
f", reported = {len(bis)}",
flush=True,
)
if len(bis) != expected_num_blocks:
raise ValueError(
f"Expected number of blocks in step {step} "
f"is {expected_num_blocks} but we found "
f"only {len(bis)} blocks."
)

for r in range(size):
nx = data.Nx - r - step
if nx < 1:
nx = data.Nx
if step == 0 and size > 1 and r == size - 1:
continue
cnt = int(bis[r]["Count"])
print(f" block {r} size expected = {nx}, reported = {cnt}", flush=True)
if nx != cnt:
raise ValueError(
f"Expected size of block in step {step}, rank {r} "
f"is {nx} but we got reported to have "
f"{cnt} elements."
)


comm.Barrier()