add mechanism for using task-local vars with Threads.@threads#50052
add mechanism for using task-local vars with Threads.@threads#50052IanButterworth wants to merge 3 commits intoJuliaLang:masterfrom
Threads.@threads#50052Conversation
196fb16 to
cc84440
Compare
|
Just for reference, Polyester has supported something similar for a while. It might make sense to aim for future versions of Polyester to adopt whatever format gets merged into Base. https://github.com/JuliaSIMD/Polyester.jl#local-per-thread-storage |
|
Ah, so that's what the question on slack was about :D I haven't tried it, but does this syntax work with something like Threads.@threads begin
buffer = Int[]
for i in 1:100
#... use buffer
end
endtoo? Seems more convenient/clear to write than having it all on one line. |
|
The syntax is not very readable, but longer term we probably want a mini dsl ala openmp and it's probably wiser to leave that to packages, so this seem reasonable Is the overhead of array creation significant? Otherwise it might be simpler to return arrays rather than tuples for further manipulation? And for the outer container, a named tuples rather than a plain tuple? |
|
|
|
Makes sense. And automatically manage returning the vectors |
|
Or have the user be explicit about which entries should comprise the vectors xs, zs = @threads let x = 1, y = 1
for i = 1:100
# body
end
z = x + y
x, z
end |
Alternative to #48543
This adds a form of
Threads.@threadsthat allows storing of variables at the task level for use in the partitioned iterations.It means the user can use
@threadswith task local buffering/storage/states without having to read into thetask_local_storage()dict every iteration.For instance
Or a toy sum