Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
pbayer committed Feb 23, 2023
2 parents fba6278 + 69f224d commit 0aeb085
Show file tree
Hide file tree
Showing 16 changed files with 95 additions and 89 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# DiscreteEvents news

## v0.3.5
(released 2023-02-23)
- updated compat
- removed multi-threading (parallel clocks) from export and docs

## v0.3.1

(released 2020-09-16) A few days after the release of v0.3.0 Hector Perez contributed some macros to make the `DiscreteEvents` API more Julian for common cases:
Expand Down
4 changes: 2 additions & 2 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "DiscreteEvents"
uuid = "127e53a7-d08a-4bd9-afb0-daf0d2b65a85"
authors = ["Paul Bayer <[email protected]>"]
version = "0.3.4"
version = "0.3.5"

[deps]
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
Expand All @@ -12,7 +12,7 @@ Unitful = "1986cc42-f94f-5a68-af5c-568840ba703d"

[compat]
DataStructures = "0.17, 0.18"
Distributions = "0.22, 0.23, 0.24"
Distributions = "0.22, 0.23, 0.24, 0.25"
Unitful = "1"
julia = "1"

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ julia> include("examples/intro.jl")
</code></pre>
</details>

For further examples see the [documentation](https://pbayer.github.io/DiscreteEvents.jl/dev), or the companion site [DiscreteEventsCompanion](https://pbayer.github.io/DiscreteEventsCompanion.jl/dev/).
For further examples see the [documentation](https://pbayer.github.io/DiscreteEvents.jl/dev).

## Installation

Expand Down
1 change: 0 additions & 1 deletion docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ makedocs(
"processes.md",
"actors.md",
"resources.md",
"parallel.md",
"usage.md"],
"Internals" => [
"internals.md",
Expand Down
46 changes: 0 additions & 46 deletions docs/src/clocks.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,52 +39,6 @@ You can query the current clock time:
tau
```

## 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`](@ref)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.

```@docs
PClock
pclock
```

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:

```@repl clocks
@show x=nthreads()-1;
clk = PClock() # now the clock has (+x) active parallel clocks
ac2 = pclock(clk, 2) # access the active clock on thread 2
ac2.clock # the thread local clock
ac2.clock.ac[] # local clocks can access their active clock
```

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.

```@docs
fork!
collapse!
```

```@repl clocks
clk = Clock() # create a clock
fork!(clk) # fork it
clk # it now has parallel clocks
collapse!(clk) # collapse it
clk # it now has no parallel clocks
```

```@docs
diagnose
```

## Real Time Clocks (Experimental)

Real time clocks are a new feature in v0.3 and thus cannot yet be considered as stable. Please try and report problems.
Expand Down
12 changes: 12 additions & 0 deletions docs/src/history.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@
```@meta
CurrentModule = DiscreteEvents
```
## v0.3.1
A few days after the release of v0.3.0 Hector Perez contributed some macros to make the `DiscreteEvents` API more Julian for common cases:

- [`@event`](@ref): wraps [`fun`](@ref) and [`event!`](@ref) into one call,
- [`@periodic`](@ref): wraps [`fun`](@ref) and [`periodic!`](@ref) into one call,
- [`@process`](@ref): wraps [`Prc`](@ref) and [`process!`](@ref) into one call,
- [`@wait`](@ref): simplified call of [`wait!`](@ref),

The following macros provide syntactic sugar to existing functions:

- [`@delay`](@ref): calls [`delay!`](@ref),
- [`@run!`](@ref): calls [`run!`](@ref).

## v0.3.0

Expand Down
6 changes: 1 addition & 5 deletions docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,9 @@ A Julia package for **discrete event generation and simulation**.
- [**Troubleshooting**](troubleshooting.md): If something doesn't work as expected.
- [**Version history**](history.md): A list of features and changes.

## Companion

There is a companion site [DiscreteEventsCompanion](https://pbayer.github.io/DiscreteEventsCompanion.jl/dev/) with more information, examples, notebooks and benchmarks.

## Development

`DiscreteEvents` is in active development. Please use, test and help evolve it. Its GitHub repository is at [https://github.com/pbayer/DiscreteEvents.jl](https://github.com/pbayer/DiscreteEvents.jl).
`DiscreteEvents` is in development. Please use, test and help evolve it. Its GitHub repository is at [https://github.com/pbayer/DiscreteEvents.jl](https://github.com/pbayer/DiscreteEvents.jl).

**Author:** Paul Bayer
**License:** MIT
Expand Down
12 changes: 0 additions & 12 deletions docs/src/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,6 @@ LocalClock
localClock
```

**An example on active clocks:**

```@repl
using DiscreteEvents
clk = Clock() # create a clock
fork!(clk) # fork it to parallel threads
clk # now you see parallel active clocks
clk = PClock() # create a parallel clock structure
ac2 = pclock(clk, 2) # get access to the active clock on thread 2
ac2.clock # access the parallel clock 2
```

`Schedule` and `ClockChannel` are two important `Clock` substructures:

```@docs
Expand Down
14 changes: 2 additions & 12 deletions docs/src/news.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
# News in v0.3.1
# News in v0.3.5

```@meta
CurrentModule = DiscreteEvents
```

A few days after the release of v0.3.0 Hector Perez contributed some macros to make the `DiscreteEvents` API more Julian for common cases:

- [`@event`](@ref): wraps [`fun`](@ref) and [`event!`](@ref) into one call,
- [`@periodic`](@ref): wraps [`fun`](@ref) and [`periodic!`](@ref) into one call,
- [`@process`](@ref): wraps [`Prc`](@ref) and [`process!`](@ref) into one call,
- [`@wait`](@ref): simplified call of [`wait!`](@ref),

The following macros provide syntactic sugar to existing functions:

- [`@delay`](@ref): calls [`delay!`](@ref),
- [`@run!`](@ref): calls [`run!`](@ref).
- multithreading (parallel clocks) has been removed from exports, testing and documentation as it was unstable and has been broken by Julia 1.7 and 1.8

## Earlier releases

Expand Down
45 changes: 45 additions & 0 deletions docs/src/old/clocks-parallel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## 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`](@ref)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.

```@docs
PClock
pclock
```

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:

```@repl clocks
@show x=nthreads()-1;
clk = PClock() # now the clock has (+x) active parallel clocks
ac2 = pclock(clk, 2) # access the active clock on thread 2
ac2.clock # the thread local clock
ac2.clock.ac[] # local clocks can access their active clock
```

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.

```@docs
fork!
collapse!
```

```@repl clocks
clk = Clock() # create a clock
fork!(clk) # fork it
clk # it now has parallel clocks
collapse!(clk) # collapse it
clk # it now has no parallel clocks
```

```@docs
diagnose
```
File renamed without changes.
2 changes: 1 addition & 1 deletion docs/src/processes.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ println(::Clock, ::IO, ::Any, ::Any)

## Examples

The [A-B Call Center Problem](@ref a-b_call_center) illustrates how to implement and setup a process. You can find [more examples at `DiscreteEventsCompanion`](https://pbayer.github.io/DiscreteEventsCompanion.jl/dev/examples/examples/#Examples).
The [A-B Call Center Problem](@ref a-b_call_center) illustrates how to implement and setup a process.
7 changes: 4 additions & 3 deletions src/DiscreteEvents.jl
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ pkg> add("https://github.com/pbayer/DiscreteEvents.jl")
module DiscreteEvents

"Gives the package version."
const version = v"0.3.4"
const version = v"0.3.5"

using Unitful, Random, DataStructures, Logging, .Threads, Distributions
import Unitful: FreeUnits, Time
Expand All @@ -46,18 +46,19 @@ include("resources.jl")
include("utils.jl")
include("macros.jl")

export Clock, PClock, RTClock, setUnit!, 𝐶,
export Clock, RTClock, setUnit!, 𝐶,
Action, Timing, at, after, every, before, until,
tau, sample_time!, fun, event!, periodic!, register!,
incr!, run!, stop!, resume!, sync!, resetClock!,
Prc, process!, interrupt!, delay!, wait!, now!,
fork!, collapse!, pclock, diagnose,
createRTClock, stopRTClock,
PrcException,
Resource,
onthread, pseed!,
@process, @event, @periodic, @delay, @wait, @run!

# 0.3.5 export no more PClock, fork!, collapse!, pclock, diagnose

Random.seed!(123)
rng = MersenneTwister(2020)
𝐶.state == Undefined() ? init!(𝐶) : nothing
Expand Down
22 changes: 19 additions & 3 deletions src/schedule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -240,8 +240,24 @@ function _cid(ac::ActiveClock, cid::Int, spawn::Bool)
end
_cid(rtc::RTClock, cid::Int, spawn::Bool) = rtc.id

# calculate the scale from a given number
function _scale(n::T)::Float64 where {T<:Number}
# calculate the scale of a given number
function _scale(n::T)::T where {T<:Number}
i = 1
if n >= 1
while n >= 10^i
i += 1
end
return 10^(i-1)
elseif n > 0
while n < 1/10^i
i += 1
end
return 1/10^i
else
return 1
end
end
#= function _scale(n::T)::Float64 where {T<:Number}
if n > 0
i = 1.0
while !(10^i ≤ n < 10^(i+1))
Expand All @@ -252,7 +268,7 @@ function _scale(n::T)::Float64 where {T<:Number}
return 1.0
end
end

=#
# ---------------------------------------------------------------
# assign and register events and samples to a clock
# ---------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ using DiscreteEvents, Test, SafeTestsets, .Threads
@safetestset "Events" begin include("test_events.jl") end
@safetestset "Clock" begin include("test_clock.jl") end
@safetestset "Units" begin include("test_units.jl") end
@safetestset "Threads" begin include("test_threads.jl") end
# @safetestset "Threads" begin include("test_threads.jl") end
@safetestset "Channel 1" begin include("test_channels1.jl") end
@safetestset "Processes" begin include("test_process.jl") end
@safetestset "Resources" begin include("test_resources.jl") end
Expand Down
4 changes: 2 additions & 2 deletions test/test_utils.jl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ end
input = Channel{Int}(Inf)
output = Channel{Int}(Inf)

if (VERSION v"1.3") && (nthreads() > 1)
#= if (VERSION ≥ v"1.3") && (nthreads() > 1)
println("... testing utilities ...")
run_model(arrival_dist, service_dist, 10, 2, 20)
@test length(output) == 10
Expand All @@ -68,4 +68,4 @@ if (VERSION ≥ v"1.3") && (nthreads() > 1)
pseed!(123)
@test x == prand(1)
end

=#

0 comments on commit 0aeb085

Please sign in to comment.