1.1 --- a/examples/simple.py Sat Sep 15 23:47:05 2007 +0000
1.2 +++ b/examples/simple.py Sat Sep 15 23:48:26 2007 +0000
1.3 @@ -5,6 +5,7 @@
1.4 """
1.5
1.6 import time
1.7 +#import random
1.8
1.9 # Array size.
1.10
1.11 @@ -26,6 +27,7 @@
1.12 print "Calculating..."
1.13 for i in range(0, N):
1.14 for j in range(0, N):
1.15 + #time.sleep(delay * random.random())
1.16 time.sleep(delay)
1.17 results[i*N+j] = i * N + j
1.18
2.1 --- a/examples/simple1.py Sat Sep 15 23:47:05 2007 +0000
2.2 +++ b/examples/simple1.py Sat Sep 15 23:48:26 2007 +0000
2.3 @@ -6,6 +6,7 @@
2.4 """
2.5
2.6 import time
2.7 +#import random
2.8
2.9 # Array size.
2.10
2.11 @@ -20,6 +21,7 @@
2.12 A supposedly time-consuming calculation on 'i' and 'j'.
2.13 """
2.14
2.15 + #time.sleep(delay * random.random())
2.16 time.sleep(delay)
2.17 return i * N + j
2.18
3.1 --- a/examples/simple2.py Sat Sep 15 23:47:05 2007 +0000
3.2 +++ b/examples/simple2.py Sat Sep 15 23:48:26 2007 +0000
3.3 @@ -5,6 +5,7 @@
3.4 """
3.5
3.6 import time
3.7 +#import random
3.8
3.9 # Array size.
3.10
3.11 @@ -19,8 +20,9 @@
3.12 A supposedly time-consuming calculation on 'i' and 'j'.
3.13 """
3.14
3.15 + #time.sleep(delay * random.random())
3.16 time.sleep(delay)
3.17 - return i * N + j
3.18 + return (i, j, i * N + j)
3.19
3.20 # Main program.
3.21
3.22 @@ -37,7 +39,8 @@
3.23 print "Calculating..."
3.24 for i in range(0, N):
3.25 for j in range(0, N):
3.26 - results[i*N+j] = calculate(i, j)
3.27 + i2, j2, result = calculate(i, j)
3.28 + results[i2*N+j2] = result
3.29
3.30 # Show the results.
3.31
4.1 --- a/examples/simple_create.py Sat Sep 15 23:47:05 2007 +0000
4.2 +++ b/examples/simple_create.py Sat Sep 15 23:48:26 2007 +0000
4.3 @@ -10,6 +10,7 @@
4.4
4.5 import pprocess
4.6 import time
4.7 +#import random
4.8
4.9 # Array size and a limit on the number of processes.
4.10
4.11 @@ -52,6 +53,7 @@
4.12 if ch:
4.13 try: # Calculation work.
4.14
4.15 + #time.sleep(delay * random.random())
4.16 time.sleep(delay)
4.17 ch.send((i, j, i * N + j))
4.18
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/examples/simple_create_map.py Sat Sep 15 23:48:26 2007 +0000
5.3 @@ -0,0 +1,59 @@
5.4 +#!/usr/bin/env python
5.5 +
5.6 +"""
5.7 +A simple example of parallel computation using a map and the create function.
5.8 +
5.9 +NOTE: We could use the with statement in the innermost loop to package the
5.10 +NOTE: try...finally functionality.
5.11 +"""
5.12 +
5.13 +import pprocess
5.14 +import time
5.15 +#import random
5.16 +
5.17 +# Array size and a limit on the number of processes.
5.18 +
5.19 +N = 10
5.20 +limit = 10
5.21 +delay = 1
5.22 +
5.23 +# Main program.
5.24 +
5.25 +if __name__ == "__main__":
5.26 +
5.27 + t = time.time()
5.28 +
5.29 + # Initialise the results using a map with a limit on the number of
5.30 + # channels/processes.
5.31 +
5.32 + results = pprocess.Map(limit=limit)
5.33 +
5.34 + # Perform the work.
5.35 + # NOTE: Could use the with statement in the loop to package the
5.36 + # NOTE: try...finally functionality.
5.37 +
5.38 + print "Calculating..."
5.39 + for i in range(0, N):
5.40 + for j in range(0, N):
5.41 + ch = results.create()
5.42 + if ch:
5.43 + try: # Calculation work.
5.44 +
5.45 + #time.sleep(delay * random.random())
5.46 + time.sleep(delay)
5.47 + ch.send(i * N + j)
5.48 +
5.49 + finally: # Important finalisation.
5.50 +
5.51 + pprocess.exit(ch)
5.52 +
5.53 + # Show the results.
5.54 +
5.55 + for i in range(0, N):
5.56 + for result in results[i*N:i*N+N]:
5.57 + print result,
5.58 + print
5.59 +
5.60 + print "Time taken:", time.time() - t
5.61 +
5.62 +# vim: tabstop=4 expandtab shiftwidth=4
6.1 --- a/examples/simple_create_queue.py Sat Sep 15 23:47:05 2007 +0000
6.2 +++ b/examples/simple_create_queue.py Sat Sep 15 23:48:26 2007 +0000
6.3 @@ -10,6 +10,7 @@
6.4
6.5 import pprocess
6.6 import time
6.7 +#import random
6.8
6.9 # Array size and a limit on the number of processes.
6.10
6.11 @@ -43,6 +44,7 @@
6.12 if ch:
6.13 try: # Calculation work.
6.14
6.15 + #time.sleep(delay * random.random())
6.16 time.sleep(delay)
6.17 ch.send((i, j, i * N + j))
6.18
7.1 --- a/examples/simple_managed.py Sat Sep 15 23:47:05 2007 +0000
7.2 +++ b/examples/simple_managed.py Sat Sep 15 23:48:26 2007 +0000
7.3 @@ -6,6 +6,7 @@
7.4
7.5 import pprocess
7.6 import time
7.7 +#import random
7.8
7.9 # Array size and a limit on the number of processes.
7.10
7.11 @@ -21,6 +22,7 @@
7.12 A supposedly time-consuming calculation on 'i' and 'j'.
7.13 """
7.14
7.15 + #time.sleep(delay * random.random())
7.16 time.sleep(delay)
7.17 return (i, j, i * N + j)
7.18
8.1 --- a/examples/simple_managed_map.py Sat Sep 15 23:47:05 2007 +0000
8.2 +++ b/examples/simple_managed_map.py Sat Sep 15 23:48:26 2007 +0000
8.3 @@ -6,6 +6,7 @@
8.4
8.5 import pprocess
8.6 import time
8.7 +#import random
8.8
8.9 # Array size and a limit on the number of processes.
8.10
8.11 @@ -21,6 +22,7 @@
8.12 A supposedly time-consuming calculation on 'i' and 'j'.
8.13 """
8.14
8.15 + #time.sleep(delay * random.random())
8.16 time.sleep(delay)
8.17 return i * N + j
8.18
8.19 @@ -30,7 +32,7 @@
8.20
8.21 t = time.time()
8.22
8.23 - # Initialise the results using map with a limit on the number of
8.24 + # Initialise the results using a map with a limit on the number of
8.25 # channels/processes.
8.26
8.27 results = pprocess.Map(limit=limit)
9.1 --- a/examples/simple_managed_queue.py Sat Sep 15 23:47:05 2007 +0000
9.2 +++ b/examples/simple_managed_queue.py Sat Sep 15 23:48:26 2007 +0000
9.3 @@ -6,6 +6,7 @@
9.4
9.5 import pprocess
9.6 import time
9.7 +#import random
9.8
9.9 # Array size and a limit on the number of processes.
9.10
9.11 @@ -21,6 +22,7 @@
9.12 A supposedly time-consuming calculation on 'i' and 'j'.
9.13 """
9.14
9.15 + #time.sleep(delay * random.random())
9.16 time.sleep(delay)
9.17 return (i, j, i * N + j)
9.18
10.1 --- a/examples/simple_map.py Sat Sep 15 23:47:05 2007 +0000
10.2 +++ b/examples/simple_map.py Sat Sep 15 23:48:26 2007 +0000
10.3 @@ -6,6 +6,7 @@
10.4 """
10.5
10.6 import time
10.7 +#import random
10.8
10.9 # Array size.
10.10
10.11 @@ -19,6 +20,7 @@
10.12 "A supposedly time-consuming calculation on 't'."
10.13
10.14 i, j = t
10.15 + #time.sleep(delay * random.random())
10.16 time.sleep(delay)
10.17 return i * N + j
10.18
11.1 --- a/examples/simple_pmap.py Sat Sep 15 23:47:05 2007 +0000
11.2 +++ b/examples/simple_pmap.py Sat Sep 15 23:48:26 2007 +0000
11.3 @@ -6,6 +6,7 @@
11.4
11.5 import pprocess
11.6 import time
11.7 +#import random
11.8
11.9 # Array size and a limit on the number of processes.
11.10
11.11 @@ -20,6 +21,7 @@
11.12 "A supposedly time-consuming calculation on 't'."
11.13
11.14 i, j = t
11.15 + #time.sleep(delay * random.random())
11.16 time.sleep(delay)
11.17 return i * N + j
11.18
12.1 --- a/examples/simple_start.py Sat Sep 15 23:47:05 2007 +0000
12.2 +++ b/examples/simple_start.py Sat Sep 15 23:48:26 2007 +0000
12.3 @@ -6,6 +6,7 @@
12.4
12.5 import pprocess
12.6 import time
12.7 +#import random
12.8
12.9 # Array size and a limit on the number of processes.
12.10
12.11 @@ -22,6 +23,7 @@
12.12 communicate with the parent process.
12.13 """
12.14
12.15 + #time.sleep(delay * random.random())
12.16 time.sleep(delay)
12.17 ch.send((i, j, i * N + j))
12.18
13.1 --- a/examples/simple_start_queue.py Sat Sep 15 23:47:05 2007 +0000
13.2 +++ b/examples/simple_start_queue.py Sat Sep 15 23:48:26 2007 +0000
13.3 @@ -6,6 +6,7 @@
13.4
13.5 import pprocess
13.6 import time
13.7 +#import random
13.8
13.9 # Array size and a limit on the number of processes.
13.10
13.11 @@ -19,6 +20,7 @@
13.12
13.13 "A supposedly time-consuming calculation on 'i' and 'j'."
13.14
13.15 + #time.sleep(delay * random.random())
13.16 time.sleep(delay)
13.17 return (i, j, i * N + j)
13.18