From 88f13dc449dea7acdcd3551380d466dc11c8d7ba Mon Sep 17 00:00:00 2001 From: quix Date: Sat, 20 Sep 2008 11:02:22 -0400 Subject: [PATCH] optimized construction of computation tree --- lib/rake.rb | 2 +- lib/rake/parallel.rb | 51 ++++++++++++++++++++------------------------ 2 files changed, 24 insertions(+), 29 deletions(-) diff --git a/lib/rake.rb b/lib/rake.rb index 07fcadd5e..cde2559ff 100755 --- a/lib/rake.rb +++ b/lib/rake.rb @@ -582,7 +582,7 @@ def invoke(*args) application.parallel_tasks.clear application.parallel_parent_flags.clear base_invoke(*args) - application.invoke_parallel_tasks + application.invoke_parallel(self.name) } end end diff --git a/lib/rake/parallel.rb b/lib/rake/parallel.rb index 2e7ee54ef..1573a2287 100644 --- a/lib/rake/parallel.rb +++ b/lib/rake/parallel.rb @@ -5,25 +5,10 @@ module Rake ; end module Rake module TaskManager - # :nodoc: - def invoke_parallel_tasks - parent_names = parallel_tasks.keys.map { |name| - name.to_sym - } - - root_name = "computation_root__#{Process.pid}__#{rand}".to_sym - + def invoke_parallel(root_task_name) # :nodoc: CompTree::Driver.new(:discard_result => true) { |driver| # - # Define the root computation node. - # - # Top-level tasks are immediate children of the root. - # - driver.define(root_name, *parent_names) { - } - - # - # build the rest of the computation tree from task prereqs + # Build the computation tree from task prereqs. # parallel_tasks.each_pair { |task_name, cache| task = self[task_name] @@ -36,19 +21,29 @@ def invoke_parallel_tasks } } + root_node = driver.nodes[root_task_name.to_sym] + # - # Mark computation nodes without a function as computed. - # - driver.nodes[root_name].each_downward { |node| - unless node.function - node.result = true - end - } - - # - # launch the computation + # If there were nothing to do, there would be no root node. # - driver.compute(root_name, :threads => num_threads, :fork => false) + if root_node + # + # Mark computation nodes without a function as computed. + # + root_node.each_downward { |node| + unless node.function + node.result = true + end + } + + # + # Launch the computation. + # + driver.compute( + root_node.name, + :threads => num_threads, + :fork => false) + end } end end