module CompTree

  1. lib/comp_tree/driver.rb
  2. lib/comp_tree/error.rb
  3. lib/comp_tree.rb
  4. show all
Parent: comp_tree.rb

CompTree — Parallel Computation Tree.

See README.rdoc.

Methods

Public Class

  1. build

Classes and Modules

  1. Driver
  2. Error
  3. NodeError
  4. RedefinitionError
  5. NoFunctionError
  6. NoNodeError

Public Class methods

build { |driver| ... }

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.

[show source]
    # File lib/comp_tree.rb, line 84
84:   def self.build(opts = {})
85:     yield Driver.new(opts)
86:   end