Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
A make-like build utility for Ruby.

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
contrib/quix
lib
test
CHANGES
README
Rakefile
comp_tree.gemspec
install.rb

README

= CompTree -- Parallel Computation Tree

== Synopsis
  
  require 'comp_tree'
  
  CompTree::Driver.new { |driver|

    # Define a function named 'area' taking these three arguments.
    driver.define_area(:width, :height, :offset) { |width, height, offset|
      width*height - offset
    }
    
    # Define a function 'width' which takes a 'border' argument.
    driver.define_width(:border) { |border|
      2 + border
    }
    
    # Ditto for 'height'.
    driver.define_height(:border) { |border|
      3 + border
    }
    
    # Define a constant function 'border'.
    driver.define_border {
      5
    }
    
    # Ditto for 'offset'.
    driver.define_offset {
      7
    }
    
    # Compute the area using four parallel threads.
    area = driver.compute(:area, :threads => 4)

    # We've done this computation.
    if area == (2 + 5)*(3 + 5) - 7
      puts "It worked!"
    else
      puts "Send bug report to ..."
    end
  }

=== Alternative Forms for Function Definitions

This form evals a lambda, saving you the repeat parameter list:

  driver.define_area :width, :height, :offset, %{
    width*height - offset
  }
  
  driver.define_width :border, %{
    2 + border
  }
  
Notice the '<code>%</code>' before the brace.  The lambda is created
just once, during the time of definition.

Finally there is the raw form which uses no +eval+ or
+method_missing+ tricks:

  driver.define(:area, :width, :height, :offset) { |width, height, offset|
    width*height - offset
  }
        
  driver.define(:width, :border) { |border|
    2 + border
  }

== Important Notes

The user should have a basic understanding of <em>functional
programming</em> (see for example
http://en.wikipedia.org/wiki/Functional_programming) and the meaning
of <em>side effects</em>.

CompTree requires the user to adopt a functional style.  Every
function you define must explicitly depend on the data it uses.

  #
  # BAD example: depending on state -- offset not listed as a parameter
  #
  driver.define_area(:width, :height) { |width, height|
    width*height - offset
  }

Unless <em>offset</em> is really a constant, the result of
<tt>driver.compute(:area, :num_threads => n)</tt> is not well-defined
for _n_ > 1.

Just as depending on some changeable state is bad, it is likewise bad
to affect a state (to produce a <em>side effect</em>).

  #
  # BAD example: affecting state
  #
  driver.define_area(:width, :height, :offset) { |width, height, offset|
    ACCUMULATOR.add "more data"
    width*height - offset
  }

Given a tree where nodes are modifying _ACCUMULATOR_, the end state of
_ACCUMULATOR_ is not well-defined.  Moreover if _ACCUMULATOR_ is not
thread-safe, the result will be even worse.

Note however it is OK affect a state as long as <em>no other function
depends on that state</em>.  This is the principle under which
+comp_tree+ parallelizes Rake tasks (http://drake.rubyforge.org).

== Install

  % gem install comp_tree

Or for the regular (non-gem) .tgz package,

  % ruby install.rb [--uninstall]

== Links

* Download: http://rubyforge.org/frs/?group_id=6917
* Rubyforge home: http://rubyforge.org/projects/comptree
* Repository: http://github.com/quix/comp_tree

== Author

* James M. Lawrence <quixoticsycophant@gmail.com>

== License
  
  Copyright (c) 2008 James M. Lawrence.  All rights reserved.
  
  Permission is hereby granted, free of charge, to any person
  obtaining a copy of this software and associated documentation files
  (the "Software"), to deal in the Software without restriction,
  including without limitation the rights to use, copy, modify, merge,
  publish, distribute, sublicense, and/or sell copies of the Software,
  and to permit persons to whom the Software is furnished to do so,
  subject to the following conditions:
  
  The above copyright notice and this permission notice shall be
  included in all copies or substantial portions of the Software.
  
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  SOFTWARE.

Something went wrong with that request. Please try again.