Module: Pwrake::HrfQueue

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

Overview

HRF mixin module

Instance Method Summary collapse

Instance Method Details

#hrf_delete(t) ⇒ Object



122
123
124
# File 'lib/pwrake/queue/queue_array.rb', line 122

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

#hrf_get(host_info, rank) ⇒ Object



86
87
88
89
90
91
92
93
94
95
96
97
98
99
# File 'lib/pwrake/queue/queue_array.rb', line 86

def hrf_get(host_info, rank)
  (@count.size-1).downto(rank) do |r|
    c = @count[r]
    if c && c>0
      t = (c <= @nproc) ?
        pop_last_rank(r, host_info) :
        pop_super(host_info, rank)
      hrf_delete(t) if t
      return t
    end
  end
  Log.debug "#{self.class}#hrf_get: no item for rank=#{rank} @count=#{@count.inspect}"
  nil
end

#hrf_init(nproc) ⇒ Object



75
76
77
78
# File 'lib/pwrake/queue/queue_array.rb', line 75

def hrf_init(nproc)
  @nproc = nproc
  @count = []
end

#hrf_push(t) ⇒ Object



80
81
82
83
84
# File 'lib/pwrake/queue/queue_array.rb', line 80

def hrf_push(t)
  r = t.rank
  n = t.use_cores(@nproc)
  @count[r] = (@count[r] || 0) + n
end

#pop_last_rank(r, host_info) ⇒ Object



101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/pwrake/queue/queue_array.rb', line 101

def pop_last_rank(r, host_info)
  i_tried = nil
  size.times do |i|
    tw = q_at(i)
    if tw.rank == r && 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