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



207
208
209
210
211
212
213
214
215
# File 'lib/pwrake/queue/queue_array.rb', line 207

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



203
204
205
# File 'lib/pwrake/queue/queue_array.rb', line 203

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

#hrf_get(host_info) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/pwrake/queue/queue_array.rb', line 169

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



158
159
160
161
# File 'lib/pwrake/queue/queue_array.rb', line 158

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

#hrf_push(t) ⇒ Object



163
164
165
166
167
# File 'lib/pwrake/queue/queue_array.rb', line 163

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

#pop_last_rank(r, host_info) ⇒ Object



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/pwrake/queue/queue_array.rb', line 182

def pop_last_rank(r,host_info)
  i_tried = []
  (size-1).downto(0) do |i|
    tw = at(i)
    if tw.rank == r
      if tw.tried_host?(host_info)
        i_tried << i
      elsif tw.acceptable_for(host_info)
        return delete_at(i)
      end
    end
  end
  i_tried.each do |i|
    tw = at(i)
    if tw.acceptable_for(host_info)
      return delete_at(i)
    end
  end
  nil
end