Skip to content

Commit af1c595

Browse files
committed
Parallelize 10_streaming_write.py example
1 parent 12e1bb6 commit af1c595

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

examples/10_streaming_write.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import json
33
import sys
44

5+
from mpi4py import MPI
56
import numpy as np
67
import openpmd_api as io
78

@@ -19,10 +20,13 @@
1920
print("SST engine not available in ADIOS2.")
2021
sys.exit(0)
2122

23+
comm = MPI.COMM_WORLD
24+
2225
# create a series and specify some global metadata
2326
# change the file extension to .json, .h5 or .bp for regular file writing
24-
series = io.Series("simData.sst", io.Access_Type.create,
25-
json.dumps(config))
27+
series = io.Series(
28+
"simData.bp5", io.Access_Type.create, comm, json.dumps(config)
29+
)
2630
series.set_author("Franz Poeschel <f.poeschel@hzdr.de>")
2731
series.set_software("openPMD-api-python-examples")
2832

@@ -54,8 +58,10 @@
5458
dtype=np.dtype("double"))
5559
for dim in ["x", "y", "z"]:
5660
pos = electronPositions[dim]
57-
pos.reset_dataset(io.Dataset(local_data.dtype, [length]))
58-
pos[()] = local_data
61+
pos.reset_dataset(
62+
io.Dataset(local_data.dtype, [comm.size * length])
63+
)
64+
pos[comm.rank * length : (comm.rank + 1) * length] = local_data
5965

6066
# optionally: flush now to clear buffers
6167
iteration.series_flush() # this is a shortcut for `series.flush()`

0 commit comments

Comments
 (0)