Debian Codegraph @

pymusic/examples/testsink.py

raw
1 #!/usr/bin/env python3
2
3 import music
4 import sys
5 from itertools import takewhile
6
7 setup = music.Setup()
8 stoptime = setup.config("stoptime")
9 timestep = setup.config("timestep")
10 buf = setup.config("buffer")
11
12 comm = setup.comm
13 rank = comm.Get_rank()
14 size = comm.Get_size()
15
16 inp = setup.publishEventInput("in")
17
18 width = inp.width()
19 local = width // size
20 rest = width % size
21 firstId = rank * local
22
23 # distribute the rest:
24 firstId += min(rank, rest)
25 if rank < rest: local += 1
26
27 def eventerr(d):
28 if errorAt is None: return
29 if d >= errorAt: raise RuntimeError("Hey")
30
31 time = None
32 def eventfunc(d, t, i):
33 sys.stderr.write(
34 "Receive rank {}: val={}, ind={}, type={}\n".
35 format(rank, d, i, music.Index.tostr(t)))
36
37 inp.map(eventfunc,
38 music.Index.GLOBAL,
39 base=firstId,
40 size=local,
41 maxBuffered=buf)
42
43 runtime = music.Runtime(setup, timestep)
44 times = takewhile(lambda t: t <= stoptime, runtime)
45 for time in times:
46 pass
47
48 runtime.finalize()