Transparency violation error when using parfor

1 view (last 30 days)
[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 Comments
Matlabber 1.0
Matlabber 1.0 on 25 Jul 2015
@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 on 25 Jul 2015
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.)

Sign in to comment.

Answers (1)

casper.dcl
casper.dcl on 13 Oct 2017
https://uk.mathworks.com/help/distcomp/transparency.html?requestedDomain=www.mathworks.com
You can't `save` in a `parfor` loop.

Categories

Find more on Data Type Conversion in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!