It looks like your seeder function depends only on the output of the corresponding call to partial_seeder. It might also be simpler to use parfor here. For example, you could do simply this:
seeds=NaN(num_pts,3,volume/4);
for i=1:volume/4
tempResult = NaN(num_pts, 3);
tempResult(:,1:2) = partial_seeder(min_grain,num_pts);
tempResult(:,3) = seeder(tempResult(:, 1:2));
seeds(:, :, i) = tempResult;
end
Another option would be to make each parfeval request call both partial_seeder and then seeder. I.e.:
function out = doBoth(min_grain, num_pts)
ps_result = partial_seeder(min_grain, num_pts);
s_result = seeder(ps_result);
out = [ps_result, s_result];
end
for i=1:volume/4
f(i) = parfeval(@doBoth, 1, min_grain, num_pts);
end
seeds=NaN(num_pts,3,volume/4);
for i=1:volume/4
[idx, result] = fetchNext(f);
seeds(:, :, idx) = result;
end
Either of the above approaches should be reasonable unless volume/4 is small compared to the number of workers you have. One final approach would be to launch the seeder computations when the partial_seeder calls complete:
seeds=NaN(num_pts,3,volume/4);
for i=1:volume/4
psF(i) = parfeval(@partial_seeder, 1, min_grain, num_pts);
end
for i=1:volume/4
[idx, result] = fetchNext(psF);
sF(idx) = parfeval(@seeder, 1, result);
end
fetchOutputs(sF)
0 件のコメント
サインインしてコメントする。