JuliaSIMD / JuliaSIMD/Polyester.jl
Will `@batch` effect the `Threads.@threads`?
- Dominant language
- Julia
- Stars
- 285
- Forks
- 20
- PR merge metrics
- No merged PRs in 30d
Description
When I used `@batch` and `Threads.@threads` concurrently, I find a confusing problem.
```julia
using TimerOutputs
using LinearAlgebra
using Polyester
function testmul_thread(A,B,C)
Threads.@threads for i in 1:96
mul!(C[i],A,B)
end
end
function testmul_batch(A,B,C)
@batch per=core for i in 1:96
mul!(C[i],A,B)
end
end
@show Threads.nthreads() # 6
function testmuls()
A = rand(100,100)
B = rand(100,100)
C = [rand(100,100) for i in 1:96]
for i in 1:20
@timeit "testmul_th" testmul_thread(A,B,C)
@timeit "testmul_batch" testmul_batch(A,B,C)
end
end
# first time call
testmuls();
reset_timer!()
testmuls()
show(TimerOutputs.get_defaulttimer());
```
The number of threads is 6. When I only call the function `testmul_thread()` in `testmuls()`, the time consumed only `94.6ms`.
```
───────────────────────────────────────────────────────────────────────
Time Allocations
─────────────────────── ────────────────────────
Tot / % measured: 106ms / 89.5% 7.55MiB / 0.8%
Section ncalls time %tot avg alloc %tot avg
───────────────────────────────────────────────────────────────────────
testmul_th 20 94.6ms 100.0% 4.73ms 64.4KiB 100.0% 3.22KiB
───────────────────────────────────────────────────────────────────────
```
But, when I call concurrently `testmul_thread()` and `testmul_batch()`, the time consumed of `testmul_thread()` will increase to `417ms`:
```
──────────────────────────────────────────────────────────────────────────
Time Allocations
─────────────────────── ────────────────────────
Tot / % measured: 518ms / 99.4% 7.56MiB / 0.9%
Section ncalls time %tot avg alloc %tot avg
──────────────────────────────────────────────────────────────────────────
testmul_th 20 417ms 81.2% 20.9ms 64.9KiB 97.7% 3.25KiB
testmul_batch 20 97.0ms 18.8% 4.85ms 1.56KiB 2.3% 80.0B
──────────────────────────────────────────────────────────────────────────
```
Why the run of function `testmul_batch` will effect `testmul_thread`? Dose `@batch` change something about global configuration of julia threads?
Thank you very much.
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.