The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Software » comp.soft-sys.matlab

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Early exit from parfor loop?
Replies: 0  

Advanced Search

Back to Topic List Back to Topic List  

Posts: 303
Registered: 12/10/05
Early exit from parfor loop?
Posted: Apr 12, 2012 5:39 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

I am looping over N files in a filesystem looking for M files with a
certain property. Sometimes they are found early and I can exit the
loop, however when using parfor there is no easy way to do this.

E.g. consider this code:

mydir = dir;
N = numel(dir);
myfiles = {}; % store filenames that pass <test>

parfor j = 1:N

if <test>
myfiles{j} = mydir(j);


The result is a cell array with some non-empty elements. This searches
all N files but if I want it to stop when it finds M=2 files, there
doesn't seem to be a way. This is probably well known behavior, but
I'm posting just in case anyone has a workaround... :)

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.