File tree Expand file tree Collapse file tree 2 files changed +48
-22
lines changed Expand file tree Collapse file tree 2 files changed +48
-22
lines changed Original file line number Diff line number Diff line change @@ -796,47 +796,38 @@ function showprogressdistributed(args...)
796
796
r = loop. args[1 ]. args[2 ]
797
797
body = loop. args[2 ]
798
798
799
- setup = quote
800
- n = length ($ (esc (r)))
801
- p = Progress (n, $ (showprogress_process_args (progressargs)... ))
802
- ch = RemoteChannel (() -> Channel {Bool} (n))
803
- end
804
-
805
799
if na == 1
806
800
# would be nice to do this with @sync @distributed but @sync is broken
807
801
# https://github.com/JuliaLang/julia/issues/28979
808
802
compute = quote
809
- display = @async let i = 0
810
- while i < n
811
- take! (ch)
812
- next! (p)
813
- i += 1
814
- end
815
- end
816
- @distributed for $ (esc (var)) = $ (esc (r))
803
+ waiting = @distributed for $ (esc (var)) = $ (esc (r))
817
804
$ (esc (body))
818
805
put! (ch, true )
819
806
end
807
+ wait (waiting)
820
808
nothing
821
809
end
822
810
else
823
811
compute = quote
824
- display = @async while take! (ch) next! (p) end
825
- results = @distributed $ (esc (reducer)) for $ (esc (var)) = $ (esc (r))
812
+ @distributed $ (esc (reducer)) for $ (esc (var)) = $ (esc (r))
826
813
x = $ (esc (body))
827
814
put! (ch, true )
828
815
x
829
816
end
830
- put! (ch, false )
831
- results
832
817
end
833
818
end
834
819
835
820
quote
836
- $ setup
837
- results = $ compute
838
- wait (display)
839
- results
821
+ let n = length ($ (esc (r)))
822
+ p = Progress (n, $ (showprogress_process_args (progressargs)... ))
823
+ ch = RemoteChannel (() -> Channel {Bool} (n))
824
+
825
+ @async while take! (ch) next! (p) end
826
+ results = $ compute
827
+ put! (ch, false )
828
+ finish! (p)
829
+ results
830
+ end
840
831
end
841
832
end
842
833
Original file line number Diff line number Diff line change 372
372
println (" Testing @showprogress macro on distributed for loop without reducer" )
373
373
testfunc16 (3000 , 0.01 , 0.001 )
374
374
375
+ function testfunc16cb (N, dt, tsleep)
376
+ ProgressMeter. @showprogress dt= dt @distributed for i in N
377
+ if rand () < 0.7
378
+ sleep (tsleep)
379
+ end
380
+ 200 < i < 400 && continue
381
+ i > 1500 && break
382
+ i ^ 2
383
+ end
384
+ end
385
+
386
+ println (" Testing @showprogress macro on distributed for loop with continue" )
387
+ testfunc16cb (1 : 1000 , 0.01 , 0.002 )
388
+
389
+ println (" Testing @showprogress macro on distributed for loop with break" )
390
+ testfunc16cb (1000 : 2000 , 0.01 , 0.003 )
391
+
392
+
393
+ println (" testing `@showprogress @distributed` in global scope" )
394
+ @showprogress @distributed for i in 1 : 10
395
+ sleep (0.1 )
396
+ i^ 2
397
+ end
398
+
399
+ println (" testing `@showprogress @distributed (+)` in global scope" )
400
+ # https://github.com/timholy/ProgressMeter.jl/issues/243
401
+ result = @showprogress @distributed (+ ) for i in 1 : 10
402
+ sleep (0.1 )
403
+ i^ 2
404
+ end
405
+ @test result == sum (abs2, 1 : 10 )
406
+
407
+
408
+
409
+
375
410
function testfunc17 ()
376
411
n = 30
377
412
p = ProgressMeter. Progress (n, start= 15 )
You can’t perform that action at this time.
0 commit comments