Skip to content

Commit

Permalink
move parallel-mode-only data into @parallel struct
Browse files Browse the repository at this point in the history
  • Loading branch information
quix committed Apr 6, 2009
1 parent 3b43c5c commit bdfb714
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 31 deletions.
41 changes: 19 additions & 22 deletions lib/rake.rb
Original file line number Diff line number Diff line change
Expand Up @@ -590,12 +590,12 @@ def invoke(*args)
if application.num_threads == 1
base_invoke(*args)
else
if application.parallel_lock.locked?
if application.parallel.lock.locked?
raise "Calling Task#invoke within a task is not allowed."
end
application.parallel_lock.synchronize {
application.parallel_tasks.clear
application.parallel_parent_flags.clear
application.parallel.lock.synchronize {
application.parallel.tasks.clear
application.parallel.needed.clear
base_invoke(*args)
application.invoke_parallel(self.name)
}
Expand All @@ -622,23 +622,20 @@ def invoke_with_call_chain(task_args, invocation_chain) # :nodoc:
execute(task_args) if needed?
else
#
# parallel mode
# Parallel mode -- gather tasks for batch execution.
#
# Either the task knows it's needed or we've marked it as
# such. See next comments.
# needed.
#
# Why do we manually mark tasks as needed? Since this is a
# dry run, files are not created or modified. Therefore the
# 'needed?' result does not propagate through the recursion.
#
prereqs = invoke_prerequisites_parallel(task_args, new_chain)
if application.parallel_parent_flags[self] or needed?
# gather tasks for batch execution
application.parallel_tasks[name] = [task_args, prereqs]

#
# Since this is a dry run, parents must be manually marked
# as needed. Files are not created or modified, so the
# the 'needed?' flag does not propagate.
#
if needed? or application.parallel.needed[self]
application.parallel.tasks[name] = [task_args, prereqs]
unless invocation_chain == InvocationChain::EMPTY
application.parallel_parent_flags[invocation_chain.value] = true
application.parallel.needed[invocation_chain.value] = true
end
end
end
Expand Down Expand Up @@ -1758,9 +1755,7 @@ module TaskManager
alias :last_comment :last_description # Backwards compatibility

attr_accessor :num_threads
attr_reader :parallel_tasks #:nodoc:
attr_reader :parallel_lock #:nodoc:
attr_reader :parallel_parent_flags #:nodoc:
attr_reader :parallel

def initialize
super
Expand All @@ -1770,9 +1765,11 @@ def initialize
@last_description = nil

@num_threads = 1
@parallel_tasks = Hash.new
@parallel_lock = Mutex.new
@parallel_parent_flags = Hash.new

@parallel = Struct.new(:tasks, :needed, :lock).new
@parallel.tasks = Hash.new
@parallel.needed = Hash.new
@parallel.lock = Mutex.new
end

def create_rule(*args, &block)
Expand Down
14 changes: 5 additions & 9 deletions lib/rake/parallel.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

module Rake ; end

require 'rake/comp_tree/comp_tree'

module Rake
Expand All @@ -10,19 +8,17 @@ def invoke_parallel(root_task_name) # :nodoc:
#
# Build the computation tree from task prereqs.
#
parallel_tasks.each_pair { |task_name, cache|
self.parallel.tasks.each_pair { |task_name, cache|
task = self[task_name]
task_args, prereqs = cache
children_names = prereqs.map { |child|
child.name.to_sym
}
driver.define(task_name.to_sym, *children_names) {
children_names = prereqs.map { |child| child.name }
driver.define(task_name, *children_names) {
task.execute(task_args)
true
}
}

root_node = driver.nodes[root_task_name.to_sym]
root_node = driver.nodes[root_task_name]

#
# If there were nothing to do, there would be no root node.
Expand All @@ -40,7 +36,7 @@ def invoke_parallel(root_task_name) # :nodoc:
#
# Launch the computation.
#
driver.compute(root_node.name, num_threads)
driver.compute(root_node.name, self.num_threads)
end
end
end
Expand Down

0 comments on commit bdfb714

Please sign in to comment.