Note
Go to the end to download the full example code
Music example receiver scriptΒΆ
Run this example as a Jupyter notebook:
See our guide for more information and troubleshooting.
import sys
from itertools import dropwhile, takewhile
import music
import numpy
setup = music.Setup()
stoptime = setup.config("stoptime")
timestep = setup.config("timestep")
comm = setup.comm
rank = comm.Get_rank()
pin = setup.publishContInput("in")
data = numpy.array([0.0, 0.0], dtype=numpy.double)
pin.map(data, interpolate=False)
runtime = setup.runtime(timestep)
mintime = timestep
maxtime = stoptime + timestep
start = dropwhile(lambda t: t < mintime, runtime)
times = takewhile(lambda t: t < maxtime, start)
for time in times:
val = data
sys.stdout.write(f"t={time}\treceiver {rank}: received {val}\n")