File Exchange

image thumbnail

iterlin and iterget

version (2.1 KB) by Samuel Bandara
Linearize nested loops for smarter dispatch by parfor

1 Download

Updated 17 Dec 2013

View Version History

View License

MATLAB does not allow nested parfor loops, resulting in idle time for workers at loop boundaries. In the following example, no loop is a good choice for conversion to parfor:

for plate = 1 : 3
for row = 2 : 7
for col = 4 : 9
% time-consuming computations here %

A solution for having workloads from within nested loops be dispatched to workers without idling is to linearize, but that approach becomes cumbersome if ranges do not start from one. Now, iterlin and iterget provide a simple pattern:

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

With the above pattern, you reduce idle time for workers, and no longer need to think about which loop to convert to parfor.

Cite As

Samuel Bandara (2021). iterlin and iterget (, MATLAB Central File Exchange. Retrieved .

Comments and Ratings (1)


Some more background on using this function is here,

MATLAB Release Compatibility
Created with R2012b
Compatible with any release
Platform Compatibility
Windows macOS Linux
Tags Add Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!