-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
return used tls from @threads
for easier use of task_local_storage()
#48543
return used tls from @threads
for easier use of task_local_storage()
#48543
Conversation
To make this friendly and not too verbose to repl usage, a minimal show method for |
I think there is already a different macro for parallel reductions that can be more efficient than this (parallel reductions)? I forget what the name changed to. It used to be |
@vtjnash are you thinking of what's now |
Yeah, sounds right |
I think the right strategy here is to implement something akin to @tkf was experimenting with similar constructs, and I think it would be worthwhile providing a richer infrastructure in Base, |
@@ -95,6 +95,7 @@ function threading_run(fun, static) | |||
if !isempty(failed_tasks) | |||
throw(CompositeException(map(TaskFailedException, failed_tasks))) | |||
end | |||
return map(Base.get_task_tls, tasks) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about simply:
return map(Base.get_task_tls, tasks) | |
return tasks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there other useful things inside the tasks?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One thing that's nicer is that the show method for a vector of tasks is a lot tidier than a vector of dict. So running a threaded for loop in the repl would be tidier.
Another idea would be to expose a way to handle the buffer objects without the user having to manipulate tasks/TLSs xs, ys = Threads.@threads x = zeros(10,10) y = zeros(2,2) for i in eachindex(a)
# do something with x, y, a[i] etc.
end
# optionally do something with xs & ys which are both of length threadpoolsize() Edit: tried out here #50052 |
I would prefer that over exposing the TLS objects in that way. Kinda reminds me of Floops reducers. I am not super convinced by the syntax, but the common ask seems to be that one wants some buffer shared by iterations on that tasks and then somehow returned. |
How about having the Edit: Or some new Julia keyword |
What would an example of that look like? I think I get idea but not sure how initialization would be indicated |
It seems to me that using #50052 seems like a better fit for I'm tempted to close this in favor of that |
Threads.@threads for i in eachindex(a)
# only initialized once; not reset between different `i`
# similar to `static` from C/C++
local x = zeros(10, 10)
local y = zeros(2, 2)
# do something with x, y, a[i] etc.
end |
In thinking about #48542 I wondered maybe
@threads
could return the tls of all the used tasks, which would maketask_local_storage()
easier to use with@threads
.Something like
(Maybe this toy example could be reduced further with smarter
get
usage?)