Debian Codegraph @

pymusic/examples/receivers.py

raw
1 #! /usr/bin/env python3
2
3 import music
4
5 import sys
6 import numpy
7 from itertools import takewhile, dropwhile
8
9 setup = music.Setup()
10 stoptime = setup.config("stoptime")
11 timestep = setup.config("timestep")
12
13 comm = setup.comm
14 rank = comm.Get_rank()
15
16 pin = setup.publishContInput("in")
17 data = numpy.array([-2], dtype=numpy.int)
18 pin.map(data, base=rank)
19
20 runtime = setup.runtime(timestep)
21 mintime = timestep
22 maxtime = stoptime+timestep
23 start = dropwhile(lambda t: t < mintime, runtime)
24 times = takewhile(lambda t: t < maxtime, start)
25 for time in times:
26 srank = data[0]
27 sys.stdout.write(
28 "t={}\treceiver {}: received Hello from sender {}\n".
29 format(time, rank, srank))
30
31 runtime.finalize()