Utilities
Single-threaded Speed-up
The Julia scheduler is running on thread 1. If your application uses tasks or channels on thread 1 (e.g. with process!
), it has to compete against other background tasks. You can remove this competition and speed up your application significantly (often by $\times10$ or more) by moving it to a thread other than 1.
DiscreteEvents.onthread
— Functiononthread(f::F, tid::Int; wait::Bool=true) where {F<:Function}
Execute a function f
on thread tid
.
To execute f
on a thread other than 1 can speed it up significantly if it depends on asynchronous tasks.
Arguments
f::Function
: function to executetid::Int
: thread idwait::Bool=true
: if true, it waits for function to finish
Example
julia> using DiscreteEvents, .Threads
julia> onthread(2) do; threadid(); end
2
Look at the M/M/c benchmarks and to this example on DiscreteEventsCompanion
for an illustration. You cannot speedup applications not using tasks or channels with this technique.
Parallel RNG Seed
DiscreteEvents.pseed!
— Functionpseed!(s::Int)
Seed each of the thread local RNGs with s*threadid()
to get reproducible, but different random number sequences on each thread.