Open efaulhaber opened 3 years ago
You can reset the state via
using Polyester, ThreadingUtilities
Polyester.reset_workers!()
ThreadingUtilities.reinitialize_tasks!()
Yes, that works! I guess that's not supposed to happen, right? One shouldn't need to reset the state manually.
Was reset_workers!
removed in the recent 0.5.1 update? I still need to reset the state manually from time to time but can't seem to access it anymore.
It is now in PolyesterWeave.jl
Thanks!
Just so its visible for others, this is what I'm using with PolyesterWeave 0.1 and ThreadingUtilities 0.4.6:
PolyesterWeave.reset_workers!()
for i = 1:Threads.nthreads()-1; ThreadingUtilities.initialize_task(i); end
Have there been any developments by now? Threads are still being disabled (without notifying the user), and resetting them with the commands above is not really convenient.
I don't see any situation where disabling threading and not re-enabling it automatically is the desired behavior.
try
/finally
has > 10 ns overhead, but that would be how we could re-enable.
julia> bar(x) = x
bar (generic function with 1 method)
julia> function foo(x)
try
bar(x)
finally
bar(x)
end
nothing
end
foo (generic function with 2 methods)
julia> foo(2)
julia> @benchmark foo(2)
BenchmarkTools.Trial: 10000 samples with 998 evaluations.
Range (min … max): 17.132 ns … 28.618 ns ┊ GC (min … max): 0.00% … 0.00%
Time (median): 18.461 ns ┊ GC (median): 0.00%
Time (mean ± σ): 18.522 ns ± 0.338 ns ┊ GC (mean ± σ): 0.00% ± 0.00%
▆▄ ▄█▁ ▆▂ ▄ ▃ ▁ ▂
▃▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▆███▇▇███▅▃▅██▄▄▄▄█▅▅▅▄█▇▅▅▅▅█▄▅▆▆▇▇▆▆ █
17.1 ns Histogram: log(frequency) by time 19.9 ns <
Memory estimate: 0 bytes, allocs estimate: 0.
Maybe an exceptionhandling=true
argument for the batch macro can be considered for merging if contributed by those that need the feature?
For people interested in this issue: a function Polyester.reset_threads!()
has just been released to make it easier for people to do this manually (without requiring to depend on PolyesterWeave.jl and ThreadingUtilities.jl explicitly).
MWE:
When running this in a new REPL (Julia started with two threads,
julia -t 2
), the output offoo()
is, as expected:I get the same output when running this multiple times. Now, when I interrupt Julia before the function is done (that's what the
sleep
is for),@batch
only uses one thread until I restart Julia: