Skip to content

Commit a387ba1

Browse files
committed
Parallelize 10_streaming_write.py example
1 parent 0a7e0a7 commit a387ba1

1 file changed

Lines changed: 8 additions & 3 deletions

File tree

examples/10_streaming_write.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/env python
22
import sys
33

4+
from mpi4py import MPI
45
import numpy as np
56
import openpmd_api as io
67

@@ -18,9 +19,11 @@
1819
print("SST engine not available in ADIOS2.")
1920
sys.exit(0)
2021

22+
comm = MPI.COMM_WORLD
23+
2124
# create a series and specify some global metadata
2225
# change the file extension to .json, .h5 or .bp for regular file writing
23-
series = io.Series("simData.sst", io.Access_Type.create, config)
26+
series = io.Series("simData.bp5", io.Access_Type.create, config)
2427
series.set_author("Franz Poeschel <f.poeschel@hzdr.de>")
2528
series.set_software("openPMD-api-python-examples")
2629

@@ -52,8 +55,10 @@
5255
dtype=np.dtype("double"))
5356
for dim in ["x", "y", "z"]:
5457
pos = electronPositions[dim]
55-
pos.reset_dataset(io.Dataset(local_data.dtype, [length]))
56-
pos[()] = local_data
58+
pos.reset_dataset(
59+
io.Dataset(local_data.dtype, [comm.size * length])
60+
)
61+
pos[comm.rank * length : (comm.rank + 1) * length] = local_data
5762

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

0 commit comments

Comments
 (0)