def execute(processCount): n = 10000000 # 100 times fewer than C due to speed issues. delta = 1.0 / n startTime = time() sliceSize = n / processCount channel = Channel() processes = [calculator(-channel, i, sliceSize, delta) for i in xrange(0, processCount)] processes.append(accumulator(+channel, n, delta, startTime, processCount)) Parallel(*processes)
def runSimulation(numberOfCustomers, numberOfWaitingSeats, nextCustomerWaitTime, hairTrimTime): worldToShop = Channel() shopToBarber = Channel() barberToShop = Channel() shopToWorld = Channel() Parallel( barber(hairTrimTime, shopToBarber.reader(), barberToShop.writer()), shop(numberOfWaitingSeats, worldToShop.reader(), shopToBarber.writer(), barberToShop.reader(), shopToWorld.writer()), worldSink(shopToWorld.reader()), worldSource(numberOfCustomers, nextCustomerWaitTime, worldToShop.writer()))
def main(numberOfCustomers, numberOfWaitingSeats, numberOfBarbers, nextCustomerWaitTime, hairTrimTime): worldToShopIn = Channel() shopOutToShopIn = Channel() toBarber = Channel() toShopOut = Channel() shopInToAccounts = Channel() shopOutToAccounts = Channel() Parallel( shopIn(numberOfWaitingSeats, worldToShopIn.reader(), toBarber.writer(), shopInToAccounts.writer()), shopOut(toShopOut.reader(), shopOutToAccounts.writer()), accounts(shopInToAccounts.reader(), shopOutToAccounts.reader()), world(numberOfCustomers, nextCustomerWaitTime, worldToShopIn.writer()), *[ barber(i, hairTrimTime, toBarber.reader(), toShopOut.writer()) for i in range(numberOfBarbers) ])
def main(numberOfCustomers, numberOfWaitingSeats, numberOfBarbers, nextCustomerWaitTime, hairTrimTime): worldToShopIn = Channel() shopOutToShopIn = Channel() toBarber = Channel() toShopOut = Channel() shopInToAccounts = Channel() shopOutToAccounts = Channel() Parallel( shopIn(numberOfWaitingSeats, worldToShopIn.reader(), toBarber.writer(), shopInToAccounts.writer()), shopOut(toShopOut.reader(), shopOutToAccounts.writer()), accounts(shopInToAccounts.reader(), shopOutToAccounts.reader()), world(numberOfCustomers, nextCustomerWaitTime, worldToShopIn.writer()), *[barber(i, hairTrimTime, toBarber.reader(), toShopOut.writer()) for i in range(numberOfBarbers)] )