Skip to content

Commit

Permalink
optimized construction of computation tree
Browse files Browse the repository at this point in the history
  • Loading branch information
quix committed Sep 20, 2008
1 parent 676c30c commit 88f13dc
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 29 deletions.
2 changes: 1 addition & 1 deletion lib/rake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
51 changes: 23 additions & 28 deletions lib/rake/parallel.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand All @@ -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
Expand Down

0 comments on commit 88f13dc

Please sign in to comment.