Skip to content

Commit

Permalink
Merge pull request #182 from LilithHafner/lh/julia_con-opt
Browse files Browse the repository at this point in the history
[Julia] move `topn` definition into body of `@threads`
  • Loading branch information
jinyus authored Oct 10, 2023
2 parents 632a140 + a03d5b2 commit 2dbe3dd
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions julia_con/related.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ function related(posts)
end
end
function related(::Type{T}, posts) where {T}
topn = 5
# key is every possible "tag" used in all posts
# value is indicies of all "post"s that used this tag
tagmap = Dict{String,Vector{T}}()
Expand All @@ -80,16 +79,17 @@ function related(::Type{T}, posts) where {T}
end
end

relatedposts = Vector{RelatedPost}(undef, length(posts))
relatedposts = Vector{RelatedPost}(undef, length(posts))

@threads for (postsrange, _) in chunks(posts, nthreads())
@threads for (postsrange, _) in chunks(posts, nthreads())
topn = 5
maxn = MVector{topn,T}(undef)
maxv = MVector{topn,T}(undef)
taggedpostcount = Vector{T}(undef, length(posts))

for i in postsrange
post = posts[i]
post = posts[i]

taggedpostcount .= 0
# for each post (`i`-th)
# and every tag used in the `i`-th post
Expand All @@ -110,7 +110,7 @@ function related(::Type{T}, posts) where {T}
end
end



return relatedposts
end
Expand Down

0 comments on commit 2dbe3dd

Please sign in to comment.