You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a situation where I'd like to chunk K different vectors (containing different types), and parallelize across N tasks. I'd rather not spawn N tasks for each of K vectors (NK spawns in total). What would be good is having a way to spawn N tasks, and have the nth task work through the nth chunk of each of the K vectors. To do that, I need to be able to get the nth of N chunks for the kth vector, from within the nth thread. Does the API enable this, or does it always return all N chunks instead of just the required one?
You can chunk the indices, assuming they are the same for all arrays, something like this may be what you want:
julia> x =ones(20); y =ones(20); z =zeros(20);
julia>@syncfor inds inindex_chunks(x; n=4)
@spawnbeginfor i in inds
z[i] = x[i] + y[i]
endendend
julia> z
20-element Vector{Float64}:2.02.02.02.0...
Activity
lmiq commentedon Jun 25, 2026
You can chunk the indices, assuming they are the same for all arrays, something like this may be what you want:
ojwoodford commentedon Jun 25, 2026
Thanks. That won't work for me though. I need something like this:
lmiq commentedon Jun 25, 2026
Actually you can do that, because the chunking is lazy, so you can do:
such that you can do:
ojwoodford commentedon Jun 25, 2026
That’s nice. Good to know. Is there a way to construct the chunk inside the task, though? If the data structure A isn’t iterable,
chunk.()won’t work.lmiq commentedon Jun 25, 2026
You can just do:
inside the task. You will be repeating the chunking for each task, but very likely that is not an issue, as it is very cheap.
ojwoodford commentedon Jun 25, 2026
Thanks. I guess this relies on the fact that the chunking is deterministic, so never changes between calls to
chunks.lmiq commentedon Jun 25, 2026
Oh yes. It is.