Skip to content

Commit

Permalink
Parallelize 10_streaming_write.py example
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Dec 17, 2024
1 parent 2e246cc commit 3176468
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions examples/10_streaming_write.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import json
import sys

from mpi4py import MPI
import numpy as np
import openpmd_api as io

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

comm = MPI.COMM_WORLD

# create a series and specify some global metadata
# change the file extension to .json, .h5 or .bp for regular file writing
series = io.Series("simData.sst", io.Access_Type.create,
json.dumps(config))
series = io.Series(
"simData.bp5", io.Access_Type.create, comm, json.dumps(config)
)
series.set_author("Franz Poeschel <[email protected]>")
series.set_software("openPMD-api-python-examples")

Expand Down Expand Up @@ -54,8 +58,10 @@
dtype=np.dtype("double"))
for dim in ["x", "y", "z"]:
pos = electronPositions[dim]
pos.reset_dataset(io.Dataset(local_data.dtype, [length]))
pos[()] = local_data
pos.reset_dataset(
io.Dataset(local_data.dtype, [comm.size * length])
)
pos[comm.rank * length : (comm.rank + 1) * length] = local_data

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

0 comments on commit 3176468

Please sign in to comment.