awips2/pythonPackages/scientific/Examples/BSP/example1_array.py
root 9f19e3f712 Initial revision of AWIPS2 11.9.0-7p5
Former-commit-id: 64fa9254b946eae7e61bbc3f513b7c3696c4f54f
2012-01-06 08:55:05 -06:00

29 lines
735 B
Python
Executable file

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)