I made progress meters for parllel runners about a year ago in Julia using 
Tk.jl. I've seen stopped using that bit of acode but here is what I have 
unearthed from the depths:

#################### Progress Types ####################

type ProgressFrame
  trace::Bool
  widget::Tk_Widget

  function ProgressFrame(title::String, trace::Bool)
    if trace
      print(title * "...\n\n")
      new(true)
    else
      widget = Frame(Toplevel("Mamba Progress"))
      pack(widget, expand=true, fill="both")
      grid(Label(widget, title), 1, 2)
      new(false, widget)
    end
  end
end

type Progress
  frame::ProgressFrame
  chain::Integer
  iters::Integer
  counter::Integer
  t0::Float64

  runin::Integer
  threshold::Float64

  pb::Tk_Widget
  l1::Tk_Widget
  l2::Tk_Widget

  function Progress(f::ProgressFrame, chain::Integer, iters::Integer)
    runin = max(1, min(10, iround(0.01 * iters)))
    if f.trace
      new(f, chain, iters, 0, time(), runin, 0.0)
    else
      pb = Progressbar(f.widget, orient="horizontal")
      l1 = Label(f.widget, "Chain $chain: ")
      l2 = Label(f.widget, @sprintf("[%s of %s remaining]", 0, 0))

      grid(l1, chain+1, 1, sticky="news")
      grid(pb, chain+1, 2, sticky="news")
      grid(l2, chain+1, 3, sticky="news")

      new(f, chain, iters, 0, time(), runin, time(), pb, l1, l2)
    end
  end
end


#################### Progress Methods ####################

function next!(p::Progress)
  p.counter += 1
  if p.frame.trace
    if p.counter / p.iters >= p.threshold && p.counter >= p.runin
      p.threshold += 0.10
      print(STDOUT, p)
    end
  else
    t = time()
    if t > p.threshold + 1.0 || p.counter >= p.iters
      p.threshold = t
      myid() == 1 ? update!(p) : remotecall(1, update!, p)
      sleep(0.01)
    end
  end
  p
end

function reset!(p::Progress)
  p.counter = 0
  p.t0 = time()
  p.threshold = p.frame.trace ? 0.0 : time()
  p
end

function terminate!(f::ProgressFrame)
  f.trace || tcl("destroy", parent(f.widget))
  f
end

function update!(p::Progress)
  elapsed = time() - p.t0
  remaining = elapsed * (p.iters / p.counter - 1.0)
  str = @sprintf("[%s of %s remaining]",
                 strfsec(remaining),
                 strfsec(elapsed + remaining))
  set_value(p.pb, integer(100.0 * p.counter / p.iters))
  set_value(p.l2, str)
  p
end

function Base.print(io::IO, p::Progress)
  elapsed = time() - p.t0
  remaining = elapsed * (p.iters / p.counter - 1.0)
  str = @sprintf("Chain %u: %3u%% [%s of %s remaining]",
                 p.chain,
                 100.0 * p.counter / p.iters,
                 strfsec(remaining),
                 strfsec(elapsed + remaining))
  println(io, str)
end

function strfsec(sec::Real)
  hr, sec = divrem(sec, 3600)
  min, sec = divrem(sec, 60)
  @sprintf "%u:%02u:%02u" hr min sec
end




On Sunday, November 15, 2015 at 9:35:24 AM UTC-6, Jason Eckstein wrote:
>
>
>
> I was playing around with the ProgressMeter.jl package by Tim Holy and it 
> works great for a single threaded loop.  I was wondering if there's any way 
> to run several loops on multiple workers and have a set of progress bars 
> update in real time.  When I tried this with Tim's package it just said 
> Progress: 100% Time: .... after each was complete but nothing during 
> intermediate progress.  What I had in mind was a display like
> Worker 1:  Progress: X%...
> Worker 2: Progress: Y% ....
> that update in real time but have multiple lines to represent the 
> different workers.
>

Reply via email to