Transparency violation error when using parfor
1 次查看(过去 30 天)
显示 更早的评论
[edit] the problem is the function call of 'save()' in the parfor loop. the solution is found here: http://ch.mathworks.com/matlabcentral/answers/135285-how-do-i-use-save-with-a-parfor-loop-using-parallel-computing-toolbox]/edit]
dear all, I try to postprocess a significant amount of images. I want to parallelize it. I tried to consider the coding restrictions that come with the parfor loop, but i still run into the
Error using test_parloop (line 21)
Transparency violation error.
See Parallel Computing Toolbox documentation about
Transparency
I posted below the code. thank you for any help!
clear all
clc
load('xls_file') % contains the logfile of all images
flag={'emp','d2o','cl3'}; % three folders / cases
readpath='C:\data\tomo_HS14\02_rawdata\';
writepath='C:\data\tomo_HS14\processed\';
if matlabpool('size') == 0 % checking to see if my pool is already open
matlabpool open 3
end
for i =3%1:size(flag) %iterate cases
jmax=size(xls{i},1);
% generate path strings
rpath=strcat(writepath,'1raw\',flag{i},'\'); %read
wpath=strcat(writepath,'2flt\',flag{i},'\'); %write
parfor j=1:jmax
if xls{i}{j,14}~=0 %check if the file is 'healthy'
% generate file name string
rfile=strcat(flag{i},'_',sprintf('%04d',j),'.fits'); %read
wfile=strcat(flag{i},'_filt_',sprintf('%04d',j),'.mat');%write
% read image
im=im2double(fitsread(strcat(rpath,rfile))');
% all sorts of image processing here
% write image
save(strcat(wpath,wfile),'im')
% generate command line output
fprintf('_%d',j)
if mod(j,100)==0
fprintf('\n')
end
end
end
end
matlabpool close
4 个评论
Walter Roberson
2015-7-25
When you use fullfile() you do not need to worry about whether you are executing on MS Windows or on OS-X or Linux, and you do not have to think about whether particular strings have already had the path separator or if you need to add the path separator. It simplifies the code, and it also makes it clearer to readers. Problems with incorrect paths and assumptions about directories are common when people put together filenames using strcat(), but people who use fullfile() are more likely to handle names properly in my experience. (In particular, people who use dir() to find file names and do not use fullfile() with the .name field often make mistakes in building the name.)
回答(1 个)
casper.dcl
2017-10-13
https://uk.mathworks.com/help/distcomp/transparency.html?requestedDomain=www.mathworks.com
You can't `save` in a `parfor` loop.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Big Data Processing 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!