module CompTree
CompTree
– Parallel Computation Tree.
See README.rdoc.
Public Class Methods
build { |driver| ... }
click to toggle source
Build a new computation tree. A Driver
instance is passed to the given block.
Example:
CompTree.build do |driver| # Define a function named 'area' taking these two arguments. driver.define(:area, :width, :height) { |width, height| width*height } # Define a function 'width' which takes a 'border' argument. driver.define(:width, :border) { |border| 7 + border } # Ditto for 'height'. driver.define(:height, :border) { |border| 5 + border } # # Define a constant function 'border'. driver.define(:border) { 2 } # Compute the area using up to four parallel threads. puts driver.compute(:area, 4) # => 63 # We've done this computation. puts((7 + 2)*(5 + 2)) # => 63 end
A custom CompTree::Node
subclass may optionally be provided,
CompTree.build(:node_class => MyNode) { ... }
This will build the tree with MyNode
instances.
# File lib/comp_tree.rb, line 84 def self.build(opts = {}) yield Driver.new(opts) end