Class: Pwrake::RankCounter
- Inherits:
-
Object
- Object
- Pwrake::RankCounter
- Defined in:
- lib/pwrake/queue/queue_array.rb
Instance Method Summary collapse
- #add_nproc(n) ⇒ Object
- #get_task ⇒ Object
- #incr(r) ⇒ Object
-
#initialize ⇒ RankCounter
constructor
A new instance of RankCounter.
Constructor Details
#initialize ⇒ RankCounter
Returns a new instance of RankCounter.
110 111 112 113 114 |
# File 'lib/pwrake/queue/queue_array.rb', line 110 def initialize @ntask = [] @nproc = 0 @mutex = Mutex.new end |
Instance Method Details
#add_nproc(n) ⇒ Object
116 117 118 119 120 |
# File 'lib/pwrake/queue/queue_array.rb', line 116 def add_nproc(n) @mutex.synchronize do @nproc += n end end |
#get_task ⇒ Object
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
# File 'lib/pwrake/queue/queue_array.rb', line 128 def get_task @mutex.synchronize do (@ntask.size-1).downto(0) do |r| c = @ntask[r] if c && c>0 t = yield(c, @nproc, r) #t = (c<=@n) ? pop_last_rank(r) : pop if t @ntask[t.rank] -= 1 Log.debug "RankCount rank=#{r} nproc=#{@nproc} count=#{c} t.rank=#{t.rank} t.name=#{t.name}" end return t end end end nil end |
#incr(r) ⇒ Object
122 123 124 125 126 |
# File 'lib/pwrake/queue/queue_array.rb', line 122 def incr(r) @mutex.synchronize do @ntask[r] = (@ntask[r]||0) + 1 end end |