| 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 |
pickled = setup.config("pickled") != 0 |
| 12 |
|
| 13 |
errorAt = setup.config("errorAt") |
| 14 |
if errorAt < 0: errorAt = None |
| 15 |
|
| 16 |
comm = setup.comm |
| 17 |
rank = comm.Get_rank() |
| 18 |
size = comm.Get_size() |
| 19 |
|
| 20 |
def eventerr(d): |
| 21 |
if errorAt is None: return |
| 22 |
if d >= errorAt: raise RuntimeError("Hey") |
| 23 |
|
| 24 |
time = None |
| 25 |
def msgfunc(d, msg): |
| 26 |
eventerr(d) |
| 27 |
sys.stderr.write( |
| 28 |
"Receive rank {}: {} ({}) at {}\n". |
| 29 |
format(rank, type(msg), msg, d)) |
| 30 |
|
| 31 |
inp = setup.publishMessageInput("in") |
| 32 |
inp.map(msgfunc, maxBuffered=buf, pickled=pickled) |
| 33 |
|
| 34 |
runtime = setup.runtime(timestep) |
| 35 |
times = takewhile(lambda t: t <= stoptime, runtime) |
| 36 |
for time in times: |
| 37 |
pass |
| 38 |
|
| 39 |
runtime.finalize() |