1.1 --- a/examples/simple_managed.py Sat Sep 15 15:57:18 2007 +0000
1.2 +++ b/examples/simple_managed.py Sat Sep 15 15:57:34 2007 +0000
1.3 @@ -15,15 +15,14 @@
1.4
1.5 # Work function and monitoring class.
1.6
1.7 -def calculate(ch, i, j):
1.8 +def calculate(i, j):
1.9
1.10 """
1.11 - A time-consuming calculation, using 'ch' to communicate with the parent
1.12 - process, with 'i' and 'j' as operands.
1.13 + A supposedly time-consuming calculation on 'i' and 'j'.
1.14 """
1.15
1.16 time.sleep(delay)
1.17 - ch.send((i, j, i * N + j))
1.18 + return (i, j, i * N + j)
1.19
1.20 class MyExchange(pprocess.Exchange):
1.21
1.22 @@ -47,16 +46,25 @@
1.23 # assignment of values as the data arrives.
1.24
1.25 exchange.D = [0] * N * N
1.26 - calc = exchange.manage(calculate)
1.27 +
1.28 + # Wrap the calculate function and manage it.
1.29 +
1.30 + calc = exchange.manage(pprocess.MakeParallel(calculate))
1.31 +
1.32 + # Perform the work.
1.33
1.34 print "Calculating..."
1.35 for i in range(0, N):
1.36 for j in range(0, N):
1.37 calc(i, j)
1.38
1.39 + # Wait for the results.
1.40 +
1.41 print "Finishing..."
1.42 exchange.finish()
1.43
1.44 + # Show the results.
1.45 +
1.46 print "Time taken:", time.time() - t
1.47 for i in range(0, N):
1.48 for result in exchange.D[i*N:i*N+N]: