forked from openPMD/openPMD-api
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Parallelize 10_streaming_write.py example
- Loading branch information
1 parent
2e246cc
commit 3176468
Showing
1 changed file
with
10 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
import json | ||
import sys | ||
|
||
from mpi4py import MPI | ||
import numpy as np | ||
import openpmd_api as io | ||
|
||
|
@@ -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") | ||
|
||
|
@@ -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()` | ||
|