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.



118
119
120
121
122
# File 'lib/pwrake/queue/queue_array.rb', line 118

def initialize
  @ntask = []
  @nproc = 0
  @mutex = Mutex.new
end

Instance Method Details

#add_nproc(n) ⇒ Object



124
125
126
127
128
# File 'lib/pwrake/queue/queue_array.rb', line 124

def add_nproc(n)
  @mutex.synchronize do
    @nproc += n
  end
end

#get_taskObject



136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
# File 'lib/pwrake/queue/queue_array.rb', line 136

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



130
131
132
133
134
# File 'lib/pwrake/queue/queue_array.rb', line 130

def incr(r)
  @mutex.synchronize do
    @ntask[r] = (@ntask[r]||0) + 1
  end
end