-
Notifications
You must be signed in to change notification settings - Fork 373
Use multithreading in row_group_slots refarray method #2661
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
Changes from 4 commits
e05ec3e
f9199b2
928cb10
d711a0e
dd320eb
4915a3b
fe50a5c
726a46a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,4 +15,5 @@ gennames | |
| getmaxwidths | ||
| ourshow | ||
| ourstrwidth | ||
| tforeach | ||
| ``` | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -83,3 +83,41 @@ else | |
| end | ||
|
|
||
| funname(c::ComposedFunction) = Symbol(funname(c.outer), :_, funname(c.inner)) | ||
|
|
||
| """ | ||
| tforeach(f, x::AbstractArray; basesize::Integer) | ||
|
|
||
| Apply function `f` to each entry in `x` in parallel, spawning | ||
| one separate task for each block of at least `basesize` entries. | ||
|
|
||
| A number of task higher than `Threads.nthreads()` may be spawned, | ||
| since that can allow for a more efficient load balancing in case | ||
| some threads are busy (nested parallelism). | ||
| """ | ||
| function tforeach(f, x::AbstractArray; basesize::Integer) | ||
| @static if VERSION >= v"1.4" | ||
| nt = Threads.nthreads() | ||
| len = length(x) | ||
| if nt > 1 && len > basesize | ||
| # Round size up to ensure all chunks have at least `basesize` entries | ||
| # This ensures balanced sizes by avoiding a small last chunk | ||
| basesize′ = cld(len, fld(len, basesize)) | ||
| @sync for p in Iterators.partition(x, basesize′) | ||
|
||
| Threads.@spawn begin | ||
| for i in p | ||
| f(@inbounds x[i]) | ||
| end | ||
| end | ||
| end | ||
| else | ||
| for i in eachindex(x) | ||
| f(@inbounds x[i]) | ||
| end | ||
| end | ||
| else | ||
| for i in eachindex(x) | ||
| f(@inbounds x[i]) | ||
| end | ||
| end | ||
| return | ||
| end | ||
Uh oh!
There was an error while loading. Please reload this page.