Transparency violation error when using parfor

조회 수: 1 (최근 30일)
Matlabber 1.0
Matlabber 1.0 2015년 7월 24일
답변: casper.dcl 2017년 10월 13일
[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
Matlabber 1.0
Matlabber 1.0 2015년 7월 25일
@Walter Roberson thanks for you advice. you first commen i think is tecnically correct, but this time i am lucky and it works well.
what is the idea behind your second comman, waht advantages brings it?
Walter Roberson
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
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.

카테고리

Help CenterFile Exchange에서 Big Data Processing에 대해 자세히 알아보기

제품

Community Treasure Hunt

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

Start Hunting!

Translated by