def test(): a = Channel("a") b = Channel("b") c = Channel("c") d = BlackHoleChannel("d") run_CSP(PoisonTest(a.write), Identity(a.read, b.write), Identity(b.read, c.write), Identity(c.read, d.write)) for ch in [a, b, c, d]: print("State of channel", ch.name, "- poisoned is", ch.poisoned)
def CommsTimeBM(run_no, Delta2=Delta2): # Create channels a = Channel("a") b = Channel("b") c = Channel("c") d = Channel("d") rets = run_CSP( Prefix(c.read, a.write, prefixItem=0), # initiator Delta2(a.read, b.write, d.write), # forwarding to two Successor(b.read, c.write), # feeding back to prefix consumer(d.read, run_no)) # timing process return rets[-1]
async def AltTest_p(): sg1 = Skip() sg2 = Skip() ch = Channel('p') alt = Alternative(sg1, sg2, ch.read) ret = await alt.select() print("Returned from alt.select():", ret)
def a2atest(): print("-----------------------") print("Testing Any2Any Channel") print("All readers and writers should report as done") # TODO: potential race if one of the writers/readers finish early and poison the channel! # the same problem might occur above as well! c = Channel() run_CSP(WN(1, c.write), WN(2, c.write), RN(3, c.read), RN(4, c.read))
def run_bm(): chans = [Channel(f'ch {i}') for i in range(N_CHANNELS)] procs = [] for cno, ch in enumerate(chans): for c_pid in range(N_PROCS_PER_CHAN): writer_id = (cno, c_pid) procs.append(stressed_writer(ch.write, writer_id)) procs.append(stressed_reader(chans, N_PROCS_PER_CHAN)) run_CSP(*procs)
def test2(): a = Channel() run_CSP(Count(a.write), Count(a.write), PoisonReader(a.read)) print("Processes done")
def __init__(self, name=None): Channel.__init__(self, name)
def serve_test(): chnames = ['a', 'b', 'c', 'd'] chans = [Channel(n) for n in chnames] for c in chans: apycsp.net.register_channel(c, c.name)
v = await cin() t2 = time.time() @process async def writer_timed(N, cout): global t1 for i in range(10): await cout(i) t1 = time.time() for i in range(N): await cout(i) N = 10 c = Channel('a') run_CSP(writer(N, c.write), reader_verb(N, c.read)) def run_timing(read_end, write_end): dts = [] for i in range(5): N = 1000 print(f"Run {i}:", end="") #t1 = time.time() run_CSP(writer_timed(N, write_end), reader_timed(N, read_end)) #t2 = time.time() dt_ms = (t2 - t1) * 1000 dt_op_us = (dt_ms / N) * 1000 print(f" DT = {dt_ms:8.3f} ms per op: {dt_op_us:8.3f} us") dts.append(dt_op_us)
def a2otest(): print("-----------------------") print("Testing Any2One Channel") print("Reader should report as done, none of the writers should") c = Channel() run_CSP(WN(1, c.write), WN(2, c.write), RN(3, c.read))
def o2atest(): print("-----------------------") print("Testing One2Any Channel") print("Writer should report as done, none of the readers should") c = Channel() run_CSP(WN(1, c.write), RN(2, c.read), RN(3, c.read))
def o2otest(): print("-----------------------") print("Testing One2One Channel") print("Reader and writer should both report as done") c = Channel() run_CSP(WN(1, c.write), RN(2, c.read))
def AltTest4(): print("------------- AltTest4 ----------------") c = Channel('ch4') run_CSP(alt_writer(c.write), p1(c.read))
def AltTest3(): print("------------- AltTest3 ----------------") c = Channel('ch3') run_CSP(p1_b(c.read), p2(c.write))
def AltTest2(): print("------------- AltTest2 ----------------") c = Channel('ch2') run_CSP(p1(c.read), p2(c.write))
def AltTest5(): print("------------- AltTest5 ----------------") c = Channel('ch5') run_CSP(alt_timer(c.read), writer(c.write))