Module: Pwrake::HrfQueue

Included in:
LifoHrfQueueArray, PriorityHrfQueueArray
Defined in:
lib/pwrake/queue/queue_array.rb

Overview

HRF mixin module

Instance Method Summary collapse

Instance Method Details

#check(t = nil) ⇒ Object



193
194
195
196
197
198
199
200
201
# File 'lib/pwrake/queue/queue_array.rb', line 193

def check(t=nil)
  sum = 0
  @count.each{|x| sum+=x if x}
  if size != sum
    #$stderr.puts self.inspect
    #$stderr.puts t.inspect if t
    raise "sise != @count.sum"
  end
end

#hrf_delete(t) ⇒ Object



189
190
191
# File 'lib/pwrake/queue/queue_array.rb', line 189

def hrf_delete(t)
  @count[t.rank] -= 1
end

#hrf_get(host_info) ⇒ Object



161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/pwrake/queue/queue_array.rb', line 161

def hrf_get(host_info)
  (@count.size-1).downto(0) do |r|
    c = @count[r]
    if c && c>0
      t = (c <= @nproc) ? pop_last_rank(r,host_info) : pop_super(host_info)
      hrf_delete(t) if t
      return t
    end
  end
  raise "no element"
  nil
end

#hrf_init(n_cores = nil) ⇒ Object



150
151
152
153
# File 'lib/pwrake/queue/queue_array.rb', line 150

def hrf_init(n_cores=nil)
  @nproc = n_cores || 0
  @count = []
end

#hrf_push(t) ⇒ Object



155
156
157
158
159
# File 'lib/pwrake/queue/queue_array.rb', line 155

def hrf_push(t)
  r = t.rank
  c = @count[r]
  @count[r] = (c) ? c+1 : 1
end

#pop_last_rank(r, host_info) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/pwrake/queue/queue_array.rb', line 174

def pop_last_rank(r,host_info)
  tw_found = nil
  (size-1).downto(0) do |i|
    tw = at(i)
    if tw.rank == r && tw.acceptable_for(host_info)
      if tw.untried_host?(host_info)
        return delete_at(i)
      else
        tw_found ||= tw
      end
    end
  end
  tw_found
end