The way I’ve done this (or similar things) before is to compute a set of indices 1:N such that each index corresponds to a point in the state space. So you would distribute over that 1:N, and then construct which point it corresponds to within the loop.
Eg instead of
nb = 12
nz = 8
@sync @distributed for ib = 1:nb
for z = 1:nz
vf = solve_problem(params,ib,z,age)
end
end
you would do something like
nb = 12
nz = 8
N = nb*nz
@sync @distributed for i = 1:N
ib,iz = indicesfrom(i,nb,nz)
vf = solve_problem(params,ib,iz,age)
end
where you just need to figure out what that indicesfrom
function should look like. CartesianIndices
should help.