Class: Pwrake::RankCounter

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

Instance Method Summary collapse

Constructor Details

#initializeRankCounter

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_taskObject



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