Class: Pregel::Coordinator
- Inherits:
-
Object
- Object
- Pregel::Coordinator
- Defined in:
- lib/pregel/coordinator.rb
Instance Attribute Summary collapse
-
#workers ⇒ Object
readonly
Returns the value of attribute workers.
Instance Method Summary collapse
-
#initialize(graph, options = {}) ⇒ Coordinator
constructor
A new instance of Coordinator.
- #partition(graph) ⇒ Object
- #run ⇒ Object
Constructor Details
#initialize(graph, options = {}) ⇒ Coordinator
Returns a new instance of Coordinator.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/pregel/coordinator.rb', line 5 def initialize(graph, = {}) raise "empty graph" if graph.empty? @workers = [] @options = { :partitions => 1 }.merge() partition(graph) do |subgraph| @workers << Worker.new(subgraph) end end |
Instance Attribute Details
#workers ⇒ Object (readonly)
Returns the value of attribute workers.
3 4 5 |
# File 'lib/pregel/coordinator.rb', line 3 def workers @workers end |
Instance Method Details
#partition(graph) ⇒ Object
18 19 20 21 |
# File 'lib/pregel/coordinator.rb', line 18 def partition(graph) size = (graph.size.to_f / @options[:partitions]).ceil graph.each_slice(size) { |slice| yield slice } end |
#run ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/pregel/coordinator.rb', line 23 def run loop do # execute a superstep and wait for workers to complete step = @workers.select {|w| w.active > 0}.collect {|w| w.superstep } step.each {|t| t.join} break if @workers.select {|w| w.active > 0}.size.zero? end end |