def CommsTimeBM(): print('Creating channels now...') # Create channels a = Channel() b = Channel() c = Channel() d = Channel() print("Running commstime test") Par( Prefix(c, a, prefix_item=0), # Initiator Delta2(a, b, d), # Forwarding to two Succ(b, c), # Feeding back to prefix Consumer(d)).start() # Timing process print('Finished run...')
def fulladder(A_in, B_in, C_in, Sum_in, Carry_in): """Full adder implementation. Based on Bjorndalen, Vinter & Anshus (2007). """ Aa = Channel() Ab = Channel() Ba = Channel() Bb = Channel() Ca = Channel() Cb = Channel() i1 = Channel() i1a = Channel() i1b = Channel() i2 = Channel() i3 = Channel() return Par(Delta2(A_in, Aa, Ab), Delta2(B_in, Ba, Bb), Delta2(C_in, Ca, Cb), Delta2(i1, i1a, i1b), Xor(Aa, Ba, i1), Xor(i1a, Ca, Sum_in), And(Ab, Bb, i2), And(i1b, Cb, i3), Or(i2, i3, Carry_in))
Delta2(i1, i1a, i1b), Xor(Aa, Ba, i1), Xor(i1a, Ca, Sum_in), And(Ab, Bb, i2), And(i1b, Cb, i3), Or(i2, i3, Carry_in)) if __name__ == '__main__': print('\nFull adder implemented in Python CSP\n') # Inputs to full adder A = Channel() B = Channel() Cin = Channel() # Outputs of full adder Carry = Channel() Sum = Channel() # Channels for printing to STDOUT PCarry = Channel() PSum = Channel() # Create and start adder adder = Par(Bool1(A), Bool2(B), Zeroes(Cin), fulladder(A, B, Cin, Sum, Carry), Sign(Carry, PCarry, 'Carry: '), Printer(PCarry), Sign(Sum, PSum, 'Sum: '), Printer(PSum)) adder.start()
i1 = Channel() i1a = Channel() i1b = Channel() i2 = Channel() i3 = Channel() return Par(Delta2(A_in, Aa, Ab), Delta2(B_in, Ba, Bb), Delta2(C_in, Ca, Cb), Delta2(i1, i1a, i1b), Xor(Aa, Ba, i1), Xor(i1a, Ca, Sum_in), And(Ab, Bb, i2), And(i1b, Cb, i3), Or(i2, i3, Carry_in)) if __name__ == '__main__': print('\nFull adder implemented in Python CSP\n') # Inputs to full adder A = Channel() B = Channel() Cin = Channel() # Outputs of full adder Carry = Channel() Sum = Channel() # Channels for printing to STDOUT PCarry = Channel() PSum = Channel() # Create and start adder adder = Par(Bool1(A), Bool2(B), Zeroes(Cin), fulladder(A, B, Cin, Sum, Carry), Sign(Carry, PCarry, 'Carry: '), Printer(PCarry), Sign(Sum, PSum, 'Sum: '), Printer(PSum)) adder.start()
sys.path.append("../") from CChannel import CChannel as Channel del sys @process def out(cout): i = 0 while True: print("PYTHON: About to write " + str(i) + "\n") cout.write(i) print("PYTHON: Have written " + str(i) + "\n") i = i + 1 @process def inn(cin): while True: print("PYTHON: About to read \n") a = cin.read() print("PYTHON: Read " + str(a) + "\n") if __name__ == "__main__": c = Channel() p = Par(out(c), inn(c)) p.start()