Parfor indices loop problem
이전 댓글 표시
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
Raymond Norris
2021년 4월 2일
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.
shekhar narayanan
2021년 4월 5일
답변 (0개)
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!