File: example1_array.py

package info (click to toggle)
python-scientific 2.4.11-2
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 1,956 kB
  • ctags: 3,063
  • sloc: python: 9,157; ansic: 4,483; xml: 4,145; makefile: 126; sh: 18; csh: 1
file content (29 lines) | stat: -rw-r--r-- 735 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
from Scientific.BSP import ParSequence, ParFunction, ParRootFunction
import Numeric; N = Numeric
import operator

# The local computation function.
def square(numbers):
    return numbers**2

# The global computation function.
global_square = ParFunction(square)

# The local output function
def output(result):
    print result

# The global output function - active on processor 0 only.
global_output = ParRootFunction(output)

# A list of numbers distributed over the processors.
items = ParSequence(N.arange(100))

# Computation.
results = global_square(items)

# Collect results on processor 0.
all_results = results.reduce(lambda a, b: N.concatenate((a, b)), N.zeros((0,)))

# Output from processor 0.
global_output(all_results)