Skip to content

Commit

Permalink
<v1.3 thread safety
Browse files Browse the repository at this point in the history
Fixes the issue noticed in SciML/DifferentialEquations.jl#498 of possible duplicated seeds.
  • Loading branch information
ChrisRackauckas committed Sep 3, 2019
1 parent db58a0c commit 2b76fa4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/DiffEqJump.jl
Expand Up @@ -16,6 +16,13 @@ abstract type AbstractJump end
abstract type AbstractAggregatorAlgorithm end
abstract type AbstractJumpAggregator end

import Base.Threads
@static if VERSION < v"1.3"
seed_multiplier() = Threads.threadid()
else
seed_multiplier() = 1
end

include("jumps.jl")
include("massaction_rates.jl")
include("aggregators/aggregators.jl")
Expand Down Expand Up @@ -44,7 +51,7 @@ export JumpProblem

export SplitCoupledJumpProblem

export Direct, DirectFW, SortingDirect, DirectCR
export Direct, DirectFW, SortingDirect, DirectCR
export BracketData, RSSA
export FRM, FRMFW, NRM

Expand Down
2 changes: 1 addition & 1 deletion src/solve.jl
Expand Up @@ -11,7 +11,7 @@ end
function DiffEqBase.__init(
jump_prob::DiffEqBase.AbstractJumpProblem{P},
alg::DiffEqBase.DEAlgorithm,timeseries=[],ts=[],ks=[],recompile::Type{Val{recompile_flag}}=Val{true};
callback=nothing, seed = rand(UInt64),
callback=nothing, seed = seed_multiplier()*rand(UInt64),
kwargs...) where {P,recompile_flag}

if !isempty(jump_prob.jump_callback.discrete_callbacks)
Expand Down

0 comments on commit 2b76fa4

Please sign in to comment.