LCOV - code coverage report
Current view: top level - src - threads.jl (source / functions) Hit Total Coverage
Test: on branch nothing Lines: 5 9 55.6 %
Date: 2025-02-26 15:13:49 Functions: 0 0 -

          Line data    Source code
       1             : """
       2             :     p :: Problem
       3             :     ps = mtproblem(p)
       4             : 
       5             :     Threads.@threads :static for i in 1:N
       6             :         solve(ps, ...)
       7             :         x[i] = pos(ps[])    # ps[] get instance for active thread
       8             :     end
       9             : 
      10             : Create instances of `p` for [`solve!`](@ref)ing in multiple threads.
      11             : 
      12             : !!! note
      13             :     Solving multiple instances of a problem in multiple threads requires
      14             :     a "private" solver for each thread. This is handled by [`mtproblem`](@ref).
      15             :     **However**, you may also need a "private" output ([`pipeline`](@ref))!
      16             :     The user is responsible for providing thread-local output and avoiding
      17             :     data-races!
      18             : 
      19             : !!! note
      20             :     `mtproblem()` is now only a thin wrapper of `TaskLocalValue{Problem}`,
      21             :     which can be passed to [`solve!`](@ref)
      22             : 
      23             : !!! note
      24             :     Make sure to start Julia with option `--threads/-t`.
      25             : 
      26             : See also [`problem`](@ref), [`solve!`](@ref),
      27             : [TaskLocalValues.jl](https://github.com/vchuravy/TaskLocalValues.jl)
      28             : """
      29          53 : function mtproblem(p::Problem{N, T, S, Dy, Out}) where {N, T, S, Dy, Out}
      30          53 :     TaskLocalValue{Problem{N, T, S, Dy, Out}}(
      31          53 :         () -> problem(similar(p); replace=p.output))
      32             : end
      33             : 
      34           0 : function solve!(p::TaskLocalValue{Problem{N, T, S, Dy, Out0}},
      35             :                 t0::T, t1::T, y0::SVector{N, T},
      36             :                 out::Out) where {N, T, S, Dy, Out0, Out}
      37           0 :     solve!(p[], t0, t1, y0, out)
      38             : end
      39             : 
      40        2048 : function solve!(p::TaskLocalValue{Problem{N, T, S, Dy, Out}},
      41             :                 t0::T, t1::T, y0::SVector{N, T}) where {N, T, S, Dy, Out}
      42        2048 :     solve!(p[], t0, t1, y0)
      43             : end
      44             : 
      45           0 : getsolver(p::TaskLocalValue{Problem{N, T, S, Dy, Out}}) where {N, T, S, Dy, Out} =
      46             :     getsolver(p[])
      47             : 
      48           0 : getoutput(p::TaskLocalValue{Problem{N, T, S, Dy, Out}}) where {N, T, S, Dy, Out} =
      49             :     getoutput(p[])

Generated by: LCOV version 1.16