| 1 |
#!/usr/bin/env python3 |
| 2 |
|
| 3 |
import music |
| 4 |
from itertools import groupby, takewhile |
| 5 |
import sys |
| 6 |
|
| 7 |
setup = music.Setup() |
| 8 |
stoptime = setup.config("stoptime") |
| 9 |
timestep = setup.config("timestep") |
| 10 |
buf = setup.config("buffer") |
| 11 |
events = setup.config("events") |
| 12 |
|
| 13 |
comm = setup.comm |
| 14 |
rank = comm.Get_rank() |
| 15 |
size = comm.Get_size() |
| 16 |
|
| 17 |
out = setup.publishEventOutput("out") |
| 18 |
|
| 19 |
width = out.width() |
| 20 |
local = width // size |
| 21 |
rest = width % size |
| 22 |
firstId = rank * local |
| 23 |
|
| 24 |
# distribute the rest: |
| 25 |
firstId += min(rank, rest) |
| 26 |
if rank < rest: local += 1 |
| 27 |
|
| 28 |
out.map(music.Index.GLOBAL, |
| 29 |
base=firstId, |
| 30 |
size=local, |
| 31 |
maxBuffered=buf) |
| 32 |
|
| 33 |
eventgen = ((firstId + i % local, i * stoptime / events) |
| 34 |
for i in range(events)) # index, time |
| 35 |
steps = groupby(eventgen, lambda i_t: int(i_t[0]/timestep)) |
| 36 |
def step(): return next(steps, (None, None)) |
| 37 |
|
| 38 |
runtime = setup.runtime(timestep) |
| 39 |
times = takewhile(lambda t: t < stoptime, runtime) |
| 40 |
nextStep, nextEvents = step() |
| 41 |
for t in times: |
| 42 |
if int(t/timestep) != nextStep: continue |
| 43 |
|
| 44 |
for index, when in nextEvents: |
| 45 |
sys.stderr.write("Insert rank {}: Event ({}, {}) at {}\n". |
| 46 |
format(rank, index, when, t)) |
| 47 |
out.insertEvent(when, index, music.Index.GLOBAL) |
| 48 |
|
| 49 |
nextStep, nextEvents = step() |
| 50 |
|
| 51 |
runtime.finalize() |