Skip to content

Commit

Permalink
refactor(fit): replace Threads.@threads with @sync and Threads.@Spawn
Browse files Browse the repository at this point in the history
  • Loading branch information
guo-yong-zhi committed Oct 19, 2024
1 parent 2ee4963 commit 5d0f89d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/fit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -243,9 +243,9 @@ function filttrain!(qtrees, inpool, outpool, nearlevel2; optimiser,
sl2 = Threads.SpinLock()
shuffle!(inpool)
nchunks = min(length(queue), max(1, length(inpool)÷4))
Threads.@threads for ichunk in 1:nchunks
@sync for ichunk in 1:nchunks
que = @inbounds queue[ichunk]
for ind in QTrees.index_chunk(length(inpool), nchunks, ichunk)
Threads.@spawn for ind in QTrees.index_chunk(length(inpool), nchunks, ichunk)
i1, i2 = inpool[ind]
cp = QTrees._collision_randbfs(qtrees[i1], qtrees[i2], empty!(que))
if cp[1] >= nearlevel2
Expand Down
8 changes: 4 additions & 4 deletions src/qtree_functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,9 @@ function _totalcollisions_native(qtrees::AbstractVector, copairs;
at=(length(qtrees[1]), 1, 1))
sl = Threads.SpinLock()
nchunks = min(length(queue), max(1, length(copairs)÷4))
Threads.@threads for ichunk in 1:nchunks
@sync for ichunk in 1:nchunks
que = @inbounds queue[ichunk]
for ind in index_chunk(length(copairs), nchunks, ichunk)
Threads.@spawn for ind in index_chunk(length(copairs), nchunks, ichunk)
i1, i2 = copairs[ind]
empty!(que)
push!(que, at)
Expand All @@ -99,9 +99,9 @@ function _totalcollisions_native(qtrees::AbstractVector, coitems::Vector{CoItem}
colist=Vector{CoItem}(), queue::AbstractThreadQueue=thread_queue())
sl = Threads.SpinLock()
nchunks = min(length(queue), max(1, length(coitems)÷4))
Threads.@threads for ichunk in 1:nchunks
@sync for ichunk in 1:nchunks
que = @inbounds queue[ichunk]
for ind in index_chunk(length(coitems), nchunks, ichunk)
Threads.@spawn for ind in index_chunk(length(coitems), nchunks, ichunk)
(i1, i2), at = coitems[ind]
empty!(que)
push!(que, at)
Expand Down

0 comments on commit 5d0f89d

Please sign in to comment.