| Products & Services | Solutions | Academia | Support | User Community | Company |
| Download Product Updates | | | Get Pricing | | | Trial Software |
| Documentation → Parallel Computing Toolbox |
| Contents | Index |
| Learn more about Parallel Computing Toolbox |
FOR variable = drange(colonop)
statement
...
statement
end
The general format is
FOR variable = drange(colonop)
statement
...
statement
endThe colonop is an expression of the form start:increment:finish or start:finish. The default value of increment is 1. The colonop is partitioned by codistributed.colon into numlabs contiguous segments of nearly equal length. Each segment becomes the iterator for a conventional for-loop on an individual lab.
The most important property of the loop body is that each iteration must be independent of the other iterations. Logically, the iterations can be done in any order. No communication with other labs is allowed within the loop body. The functions that perform communication are gop, gcat, gplus, codistributor, codistributed, gather, and redistribute.
It is possible to access portions of codistributed arrays that are local to each lab, but it is not possible to access other portions of codistributed arrays.
The break statement can be used to terminate the loop prematurely.
Find the rank of magic squares. Access only the local portion of a codistributed array.
r = zeros(1, 40, codistributor()); for n = drange(1:40) r(n) = rank(magic(n)); end r = gather(r);
Perform Monte Carlo approximation of pi. Each lab is initialized to a different random number state.
m = 10000; for p = drange(1:numlabs) z = rand(m, 1) + i*rand(m, 1); c = sum(abs(z) < 1) end k = gplus(c) p = 4*k/(m*numlabs);
Attempt to compute Fibonacci numbers. This will not work, because the loop bodies are dependent.
f = zeros(1, 50, codistributor()); f(1) = 1; f(2) = 2; for n = drange(3:50) f(n) = f(n - 1) + f(n - 2) end
for MATLAB function reference page
![]() | findTask | gather | ![]() |

Includes the most popular MATLAB recorded presentations with Q&A sessions led by MATLAB experts.
| © 1984-2009- The MathWorks, Inc. - Site Help - Patents - Trademarks - Privacy Policy - Preventing Piracy - RSS |