How to nest multiple parfor loops

后端 未结 3 1449
广开言路
广开言路 2020-12-03 03:53

parfor is a convenient way to distribute independent iterations of intensive computations among several \"workers\". One meaningful restriction is that pa

3条回答
  •  执念已碎
    2020-12-03 04:52

    Based on the answers from @DanielR and @MrAzzaman, I am posting two functions, iterlin and iterget in place of prod and ind2sub that allow iteration over ranges also if those do not start from one. An example for the pattern becomes

    rng = [1, 4; 2, 7; 3, 10];
    parfor k = iterlin(rng)
        [plate, row, col] = iterget(rng, k);
        % time-consuming computations here %
    end
    

    The script will process the wells in rows 2 to 7 and columns 3 to 10 on plates 1 to 4 without any workers idling while more wells are waiting to be processed. In hope that this helps someone, I deposited iterlin and iterget at the MATLAB File Exchange.

提交回复
热议问题