Hi,
I am currently analyzing a large study using the latest SPM 12 version. What I usually do is to let a script create a few matlabbatch files and then let this script start multiple matlab jobs to work on those in parallel (the idea comes from the CAT12 toolbox):
something like this for Windows:
function run_matlab(np, matlabbatch, check)
spm_path = fileparts(which('spm')); %get spm path
mat_name = which(mfilename);
[~,mat_name,~] = fileparts(mat_name);
fname = [num2str(np) '_' mat_name '.mat'];
save([num2str(np) '_' mat_name],'matlabbatch');
lo_cmd = ['clear matlabbatch;load(''' fname ''');'];
ex_cmd = ['addpath(''' spm_path ''');spm(''defaults'',''FMRI'');spm_jobman(''initcfg'');spm_jobman(''run'',matlabbatch);'];
end_cmd = ['delete(''' fname ''');'];
if ~check
system(['start matlab.exe -nodesktop -nosplash -logfile ' num2str(np) '_' mat_name '.log -r "' lo_cmd ex_cmd end_cmd 'exit"']);
end
This is extremely handy and does not require any fancy parallel processing toolboxes or SPM code changes. However, last night I observed that when running realign & unwarp (never did this before) I had a crash at the second volunteer, when running 4 parallel jobs. Running the volunteer in a single job was no problem. The error was:
SPM12: spm_uw_estimate (v6824) 19:57:27 - 28/02/2019
========================================================================
Unwarp terminated abnormally.
28-Feb-2019 20:08:00 - Failed 'Realign & Unwarp'
Array indices must be positive integers or logical values.
In file "C:\Users\buechel\Documents\MATLAB\spm12\spm_uw_estimate.m" (v6824), function "make_ref" at line 718.
In file "C:\Users\buechel\Documents\MATLAB\spm12\spm_uw_estimate.m" (v6824), function "spm_uw_estimate" at line 352.
In file "C:\Users\buechel\Documents\MATLAB\spm12\config\spm_run_realignunwarp.m" (v6554), function "spm_run_realignunwarp" at line 90.
When looking at the code in more detail I stumbled over :
sfname(i,:) = [tempname spm_file_ext ',1,1'];
This creates a seemingly random filename (under Windows 10 in the directory c:\Users\buechel\AppData\Local\Temp\)
Because all 4 processes write to this directory, my guess was that one process was deleting/overwriting a file belonging to another one. This was true as Matlab does not guarantee unique filenames if running without the Java engine or (my guess) when using different Matlab jobs.
I added 1 line and changed another one in spm_uw_estimate that fixes this issue:
%CB
[pa,~, ~] = fileparts(P(1).fname);
%CB
old_P = P;
if ds.fwhm ~= 0
spm_uw_show('SmoothStart',length(P));
for i=1:length(old_P)
spm_uw_show('SmoothUpdate',i);
%CB
%sfname(i,:) = [tempname spm_file_ext ',1,1'];
sfname(i,:) = [tempname(pa) spm_file_ext ',1,1'];
%CB
to_smooth = sprintf('%s,%d,%d',old_P(i).fname,old_P(i).n);
spm_smooth(to_smooth,sfname(i,:),ds.fwhm);
end
P = spm_vol(sfname);
spm_uw_show('SmoothEnd');
end
This puts the temporary smoothed files in the same directory as the other scans (which also has the advantage that after a terminated debug session you are more likely to see these files and delete them).
Best,
Christian
--
Prof. Dr. Christian Büchel
Institut für Systemische Neurowissenschaften Haus W34, Universitätsklinikum Hamburg-Eppendorf Martinistr. 52, D-20246 Hamburg, Germany
Tel.: +49-40-7410-54726
Fax.: +49-40-7410-59955
[log in to unmask]
http://www.uke.uni-hamburg.de/institute/systemische-neurowissenschaften/
|