Class: Pwrake::QueueArray

Inherits:
Array
  • Object
show all
Defined in:
lib/pwrake/queue/queue_array.rb

Direct Known Subclasses

FifoQueueArray, LifoQueueArray

Instance Method Summary collapse

Constructor Details

#initialize(nproc) ⇒ QueueArray

Returns a new instance of QueueArray.



8
9
10
11
# File 'lib/pwrake/queue/queue_array.rb', line 8

def initialize(nproc)
  @nproc = nproc
  super()
end

Instance Method Details

#find_rank(ncore) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/pwrake/queue/queue_array.rb', line 34

def find_rank(ncore)
  if empty?
    return 0
  end
  count = []
  size.times do |i|
    tw = q_at(i)
    r = tw.rank
    c = (count[r]||0) + tw.use_cores(ncore)
    if c >= @nproc
      return r
    end
    count[r] = c
  end
  count.size - 1
end

#shift(host_info, req_rank = 0) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/pwrake/queue/queue_array.rb', line 13

def shift(host_info, req_rank=0)
  i_tried = nil
  size.times do |i|
    tw = q_at(i)
    if tw.rank >= req_rank && tw.acceptable_for(host_info)
      if tw.tried_host?(host_info)
        i_tried ||= i
      else
        Log.debug "#{self.class}: task=#{tw.name} i=#{i}/#{size} rank=#{tw.rank}"
        return q_delete_at(i)
      end
    end
  end
  if i_tried
    tw = q_at(i_tried)
    Log.debug "#{self.class}(retry): task=#{tw.name} i=#{i_tried}/#{size} rank=#{tw.rank}"
    return q_delete_at(i_tried)
  end
  nil
end