Hello,
I am trying to implement hints given in ProgressMeter.jl to print a progressbar. I have written two toy functions (one directly copied from the hint and another one building off on the hint) but unable to understand why the first function prints the progressbar + output whereas the second function only allows me to fetch the output but does not display any progress bar. Could someone show me the correct approach? I can get the progressbars to print in the second function with @showprogress following the docs but unable to implement the instruction under βTips for parallel programmingβ for the same purpose.
#code
@everywhere function test_bar()
p = Progress(10, 1, "Computing function...")
channel = RemoteChannel(()->Channel{Bool}(10), 1)
@sync begin
# this task prints the progress bar
@async while take!(channel)
ProgressMeter.next!(p)
end
# this task does the computation
@async begin
z = @distributed (+) for i in 1:10
sleep(1)
put!(channel, true)
i^2
end
put!(channel, false) # this tells the printing task to finish
z
end
end
end
@everywhere function loglike_para(beta::Array{T}, data::R1, Applications::R2, sim_draws_tau::R4,
sim_draws_q::R5, sim_draws_eta::R6, num_draws_tau::S, num_draws_q::S, num_draws_eta::S, lambda::F, J::S,
day_new_sampled::Array{S}, Pr_D_sampled::Array{S}, K::S, numsample::S, num_offer_samples::S, num_app_samples::S, distribution::D) where {T<:Real} where {S<:Int} where {R1<:IndexedTable, R2<:DataFrame, R4<:IndexedTable, R5<:IndexedTable, R6<:IndexedTable} where {F<:Float64} where {D<:Bernoulli{Float64}}
ids::Array{String,2} = JuliaDB.select(data, (:std_id, :act_yr)) |>
x -> IterTools.distinct(x) |> x -> table(x) |>
x -> DataFrames.DataFrame(x) |>
x -> Matrix(x) |>
x -> convert(Array{String}, x)
app_ids = collect(1:num_app_samples)
p = Progress(size(ids)[1], 1, "Computing function...")
channel = RemoteChannel(()->Channel{Bool}(size(ids)[1]), 1)
@sync begin
# this task prints the progress bar
@async while take!(channel)
ProgressMeter.next!(p)
end
# this task does the computation
@async begin
z = @distributed (vcat) for i in 1:size(ids)[1]
sleep(1)
std_id = ids[i, :][1]::String
act_yr = ids[i, :][2]::String
L_1 = L_stage1(beta, data, Applications, sim_draws_tau, sim_draws_q, sim_draws_eta,
num_draws_tau, num_draws_q, num_draws_eta, lambda, J, day_new_sampled,
Pr_D_sampled, K, numsample, num_offer_samples, num_app_samples, distribution, std_id, act_yr, app_ids)
L_2 = L_stage2(beta, data, sim_draws_q, num_draws_q, std_id, act_yr, day_new_sampled,
Pr_D_sampled, K, J, numsample)
L_3 = L_stage3(beta, data, sim_draws_tau, num_draws_tau, std_id, act_yr, J)
LL = combine_all(L_1, L_2, L_3, num_draws_tau, num_draws_q, num_draws_eta)
end
put!(channel, false) # this tells the printing task to finish
-sum(z)
end
end
end
#output
julia> r = test_bar()
Computing function...100%|βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ| Time: 0:00:10
Task (done) @0x000000002e5dd430
julia> fetch(r)
385
julia> r_1 = loglike_para_new(beta, table(data_test), Applications, sim_draws_tau, sim_draws_q, sim_draws_eta, num_draws_tau, num_draws_q, num_draws_eta, lambda, J, day_new_sampled, Pr_D_sampled, K, numsample, num_offer_samples, num_app_samples, distribution)
Task (done) @0x000000002e5ddcd0
julia> fetch(r_1)
9.045955435747743