Use the @showprogress macro for loops and maps
masterThe @showprogress macro is a convenient way to wrap loops or functional programming constructs to display a progress bar. It supports for loops, comprehensions, @distributed loops, and map/pmap/reduce calls, provided the iterable implements length.
If the computation is too fast to require updates, no output is displayed. For @distributed loops without a reducer, an @sync is implied.
using Distributed
using ProgressMeter
# For loops
@showprogress dt=1 desc="Computing..." for i in 1:50
sleep(0.1)
end
# pmap
@showprogress pmap(1:10) do x
sleep(0.1)
x^2
end
# reduce
@showprogress reduce(1:10) do x, y
sleep(0.1)
x + y
end
# Distributed loops
@showprogress @distributed for i in 1:10
sleep(0.1)
end
# Distributed loops with reducer
result = @showprogress desc="Computing..." @distributed (+) for i in 1:10
sleep(0.1)
i^2
end