Module: Experiment::Distributed
- Included in:
- Base
- Defined in:
- lib/experiment/distributed.rb
Called on slave collapse
-
#master ⇒ Object
master server DRb object.
Called on slave collapse
-
#slave_run! ⇒ Object
Main function.
Called on master collapse
-
#distribution_done? ⇒ Boolean
returns true if all work has been disseminated.
-
#get_work ⇒ Hash, false
Send work from the master server.
-
#master_done! ⇒ Object
Cleans up the master server after all work is done.
-
#master_run!(cv) ⇒ Object
Strats up the master server.
-
#submit_result(cv, result, performance) ⇒ Object
Sends the result of the computation back to the master server.
Instance Attribute Details
#master ⇒ Object
master server DRb object
13 14 15 |
# File 'lib/experiment/distributed.rb', line 13 def master @master end |
Instance Method Details
#distribution_done? ⇒ Boolean
returns true if all work has been disseminated
54 55 56 |
# File 'lib/experiment/distributed.rb', line 54 def distribution_done? @started.all? end |
#get_work ⇒ Hash, false
Send work from the master server
44 45 46 47 48 49 50 51 |
# File 'lib/experiment/distributed.rb', line 44 def get_work() if cv = @started.index(false) @started[cv] = true {:cv => cv, :input => @data[cv], :dir => @dir, :options => Experiment::Config.to_hash } else false end end |
#master_done! ⇒ Object
Cleans up the master server after all work is done
83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/experiment/distributed.rb', line 83 def master_done! @done = true specification! true summarize_performance! summarize_results! @results cleanup! Notify.completed @experiment #sleep 1 #DRb.stop_service end |
#master_run!(cv) ⇒ Object
Strats up the master server
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/experiment/distributed.rb', line 71 def master_run!(cv) @cvs = cv || 1 @results = {} Notify.started @experiment split_up_data write_dir! @completed = (1..@cvs).map {|a| false } @started = @completed.dup end |
#slave_run! ⇒ Object
Main function. Will continously request work from the server, execute it and send back results, then loops to the beggining.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/experiment/distributed.rb', line 17 def slave_run! while work = @master.get_work puts work.inspect Experiment::Config.set work[:options] @current_cv = work[:cv] @dir = work[:dir] #@data = work[:input] File.open(@dir + "/raw-#{@current_cv}.txt", "w") do |output| @ouptut_file = output run_the_experiment end result = analyze_result!(@dir + "/raw-#{@current_cv}.txt", @dir + "/analyzed-#{@current_cv}.txt") write_performance! @master.submit_result @current_cv, result, @abm.first end end |
#submit_result(cv, result, performance) ⇒ Object
Sends the result of the computation back to the master server. Called on the master server object.
60 61 62 63 64 65 66 |
# File 'lib/experiment/distributed.rb', line 60 def submit_result(cv, result, performance) @completed[cv] = true array_merge(@results, result) @abm << performance Notify.cv_done @experiment, cv master_done! if @completed.all? end |