Parallel Clocks (Experimental)
Parallel clocks are a new feature in v0.3 and cannot yet considered to be stable. Please develop your applications first single-threaded before going parallel. Please report any failures.
Parallel clocks are virtual clocks with local clocks on parallel threads to support multi-threaded simulations.
A parallel clock structure consists of a master (global) clock on thread 1 and ActiveClock
s on all available threads > 1. An active clock is a task running a thread local clock. The thread local clock can schedule and execute events locally.
The master clock communicates with its parallel active clocks via message channels. It synchronizes time with the local clocks. Tasks (processes and actors) have access to their thread local clock from it and then work only with the local clock.
Missing docstring for PClock
. Check Documenter's build log for details.
Missing docstring for pclock
. Check Documenter's build log for details.
Parallel clocks can be identified by their thread number: the master clock works on thread 1, local clocks on parallel threads ≥ 2. They can be setup and accessed easily:
julia> @show x=nthreads()-1;
ERROR: UndefVarError: nthreads not defined
julia> clk = PClock() # now the clock has (+x) active parallel clocks
ERROR: UndefVarError: PClock not defined
julia> ac2 = pclock(clk, 2) # access the active clock on thread 2
ERROR: UndefVarError: pclock not defined
julia> ac2.clock # the thread local clock
ERROR: UndefVarError: ac2 not defined
julia> ac2.clock.ac[] # local clocks can access their active clock
ERROR: UndefVarError: ac2 not defined
Tasks on parallel threads have access to the thread local clock by pclock(clk)
. Then they can schedule events, delay!
or wait!
on it as usual. The thread local clock is passed to a process!
automatically if you set it up on a parallel thread.
You can fork explicitly existing clocks to other threads or collapse them if no longer needed. You can get direct access to parallel active clocks and diagnose them.
Missing docstring for fork!
. Check Documenter's build log for details.
Missing docstring for collapse!
. Check Documenter's build log for details.
julia> clk = Clock() # create a clock
ERROR: UndefVarError: Clock not defined
julia> fork!(clk) # fork it
ERROR: UndefVarError: fork! not defined
julia> clk # it now has parallel clocks
ERROR: UndefVarError: clk not defined
julia> collapse!(clk) # collapse it
ERROR: UndefVarError: collapse! not defined
julia> clk # it now has no parallel clocks
ERROR: UndefVarError: clk not defined
Missing docstring for diagnose
. Check Documenter's build log for details.