Parfor indices loop problem
10 views (last 30 days)
Show older comments
I am new to using parfor. I have a script that takes about an hour to run for each iteration and thought of using parfor to speed it up. My problem is that the parfor loop doesn't go through all indices of the vector I'm iterating through.
parfor root_index=1:length(root)% root is a char array that has the directories I need for the next loop
cd(root(root_index))
%Get array with folder names=folders
for folder_index=1:length(folders)
%do something
end
end
Folders=[F8.F9, F10, F11, F12, F13, F14, F15]; Loop works fine till F10 and then starts repeating itself
2 Comments
Raymond Norris
on 2 Apr 2021
root is a set of directories and folders is a set of (sub)directories, correct?
When you say "the loop works fine", which loop are you referring to? folders is the used directly by the for-loop, not the parfor. At the top you mention that the parfor loop doesn't go all the way through, but in the end you say that folders doesn't complete.
I've attached an example that works for for-loop and parfor. See if this works for you. To run it, run the following:
% Run as a for-loop
sn(0)
% Run parfor (let's assume 4 workers)
sn(4)
One thing to check is that you're changing your directory before the next parfor iteration.
If this works for you, share more about what you're doing to see what the difference is.
Answers (0)
See Also
Categories
Find more on Loops and Conditional Statements in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!