File: sstWriter-bindings.py

package info (click to toggle)
adios2 2.10.2%2Bdfsg1-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,804 kB
  • sloc: cpp: 175,964; ansic: 160,510; f90: 14,630; yacc: 12,668; python: 7,275; perl: 7,126; sh: 2,850; lisp: 1,106; xml: 1,049; makefile: 583; lex: 557
file content (44 lines) | stat: -rw-r--r-- 1,304 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from mpi4py import MPI
import numpy as np
from time import sleep
import adios2.bindings as adios2

# MPI
comm = MPI.COMM_WORLD
rank = comm.Get_rank()
size = comm.Get_size()

# ADIOS MPI Communicator
adios = adios2.ADIOS(comm)

# ADIOS IO
sstIO = adios.DeclareIO("myIO")
sstIO.SetEngine("Sst")

# Python MPI is usually not compatible with MPI used to build ADIOS
# Must use TCP based data transport, or RDMA (ucx, libfabric) if available
sstIO.SetParameter("DataTransport", "WAN")

# note: we need to use np.float32 to be compatible with data from C++ writer
# using "float" works in Python only but leads to type mismatch with C++
myArray = np.array([0.0, 1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0], dtype=np.float32)
myArray = 10.0 * rank + myArray
nx = len(myArray)
increment = nx * size * 1.0

# ADIOS Variable
ioArray = sstIO.DefineVariable(
    "bpFloats", myArray, [size * nx], [rank * nx], [nx], adios2.ConstantDims
)

sstWriter = sstIO.Open("helloSst", adios2.Mode.Write)
for i in range(4):
    print("Rank=", rank, "loop index =", i, "data =", myArray, flush=True)
    sstWriter.BeginStep()
    sstWriter.Put(ioArray, myArray, adios2.Mode.Sync)
    myArray += increment
    # Warning: the data is not published until EndStep is called
    sstWriter.EndStep()
    sleep(1.0)

sstWriter.Close()