フィルターのクリア

Load and Save using PARFOR Loops

20 ビュー (過去 30 日間)
Anas Khan
Anas Khan 2022 年 10 月 25 日
コメント済み: Anas Khan 2022 年 10 月 25 日
I am using PARFOR loops on a cluster like so:
files = dir('*.mat'); % Get list of data files to load
subjectIDs = cell(1,length(files));
% Extract subject name from each filename (SUBJECTNAME.mat format for each file)
for file = 1:length(files)
subidsplit = strsplit(files(file).name,'.');
subjectIDs{file} = subidsplit{1};
end
clear file subidsplit
frex = 2.^([10:76]/10);
parpool(length(files),'AttachedFiles',"wilson_sf.m") % Initialize parpool,
% one worker for each iteration, attach helper function
parfor ii = length(files)
CheahaGGC(1000, frex, 0, 0, 6,files,ii,subjectIDs);
end
Inside the function CheahaGGC, I am loading one file, running analysis on it, and saving it. My script completed without errors in 7 hours, but only one of the iteration's results were saved (the last one, corresponding to ii = length(files)). Is there a problem with how I implemented the loop? Each worker gets its own workspace so calling LOAD inside my function should give each worker its own data to analyze right? Same thing with SAVE. Shown below is the load and save inside of the function
function CheahaGGC(fs, freq, pad0, flgCond, omega0,files,ii,subjectIDs)
load(files(ii).name) % Load one file for this iteration
%%%%%%%%%%%%%%%%%%%%%%%
%%%% Analysis Code %%%%
%%%%%%%%%%%%%%%%%%%%%%%
save(strcat(subjectIDs{ii},'GGC','.mat'),'causalityGO','causalityNG') % Save results to file with subject name + "GGC" added

採用された回答

Bruno Luong
Bruno Luong 2022 年 10 月 25 日
編集済み: Bruno Luong 2022 年 10 月 25 日
Normal
parfor ii = length(files)
should be
parfor ii = 1:length(files)
  1 件のコメント
Anas Khan
Anas Khan 2022 年 10 月 25 日
Wow... thanks. Cannot believe the rabit holes I went down when it was that simple.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeParallel for-Loops (parfor) についてさらに検索

製品


リリース

R2021b

Community Treasure Hunt

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

Start Hunting!

Translated by