Skip to content

Commit

Permalink
task splitting: change additive accumulation to multiplicative (#53408)
Browse files Browse the repository at this point in the history
Issue raised
[here](https://discourse.julialang.org/t/linear-relationship-between-xoshiro-tasks/110454).
Given this definition, look at output values:
```jl
using .Threads

macro fetch(ex) :(fetch(@Spawn($(esc(ex))))) end

function taskCorrelatedXoshiros(+ = +)
    r11, r10 = @fetch (@fetch(rand(UInt64)), rand(UInt64))
    r01, r00 = (@fetch(rand(UInt64)), rand(UInt64))
    r01 + r10 - (r00 + r11)
end
```
Before:
```jl
julia> sort!(unique(taskCorrelatedXoshiros() for _ = 1:1000))
9-element Vector{UInt64}:
 0x0000000000000000
 0x0000000000000001
 0x00000000007fffff
 0x0000000000800000
 0x0000000000800001
 0xffffffffff7fffff
 0xffffffffff800000
 0xffffffffff800001
 0xffffffffffffffff
```
After:
```jl
julia> sort!(unique(taskCorrelatedXoshiros() for _ = 1:1000))
1000-element Vector{UInt64}:
 0x000420647a085960
 0x0038c5b889b585c6
 0x007b29fae8107ff7
 0x00e73b9e883ac1c8
                  ⋮
 0xfe68be9c0dde1e88
 0xfeca042354218c35
 0xfeeb8203e470c96b
 0xfff5dbb8771307b9

julia> sort!(unique(taskCorrelatedXoshiros(*) for _ = 1:1000))
1000-element Vector{UInt64}:
 0x00126f951c1e56dc
 0x0025a82477ffac08
 0x002dd82c9986457a
 0x00a713c4d56a3dbc
                  ⋮
 0xfe2e40a5b345095e
 0xfe77b90881967436
 0xfea2559be63f1701
 0xff88b5b28cefac5f
```

(cherry picked from commit 77c0672)
  • Loading branch information
StefanKarpinski authored and KristofferC committed Mar 6, 2024
1 parent 2d89fee commit f46f0b8
Showing 1 changed file with 143 additions and 198 deletions.
Loading

0 comments on commit f46f0b8

Please sign in to comment.