Sha256: 93f3b51ac1a1c6bd0241ca2c1738a2fee9977294944b9a483cef6dae90dcec1d
Contents?: true
Size: 1.9 KB
Versions: 3
Compression:
Stored size: 1.9 KB
Contents
module Experiment # This class is responsible for disrtibuting work # and instantiating experimental conditions according # to available resources # @private class WorkServer def initialize(experiments, options, ip = "localhost") uri="druby://#{ip}:8787" # The object that handles requests on the server front_object = self #$SAFE = 1 # disable eval() and friends DRb.start_service(uri, front_object) @experiments = experiments @started = @experiments.map { |e| false } @done = @started @options = options @experiment_instances = [] DRb.thread.join end # @deprecated def ready? # TODO: get rid of this true end # Workers call this method and recieve a new work object incrementally def new_item @experiments.each_with_index do |e, i| if @experiment_instances[i].nil? exp = @experiments[i] require "./experiments/#{exp}/#{exp}" cla = eval(as_class_name(exp)) experiment = cla.new :master, exp, @options if experiment.respond_to? :master_sub_experiments subs = experiment.master_sub_experiments @options.cv @experiments += subs.map { exp } @experiment_instances += subs return i + 1 else experiment.master_run! @options.cv @experiment_instances[i] = experiment return i end elsif !@experiment_instances[i].distribution_done? return i end end DRb.stop_service if @experiment_instances.all? {|a| a.done? } false end # accessor for the remote notification service def notify Notify end def experiment(num) @experiments[num] end def instance(num) @experiment_instances[num] end def as_class_name(str) str.split(/[\_\-]+/).map(&:capitalize).join end end end
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
experiment-0.3.2 | lib/experiment/work_server.rb |
experiment-0.3.1 | lib/experiment/work_server.rb |
experiment-0.3.0 | lib/experiment/work_server.rb |