How to recitfy a serialisation error while using a parfor which large data sets?
Ältere Kommentare anzeigen
I am working on a project that involves 2D projections of a specimen and i am require to transform it into cross-sectional image and then stack each cross sections to get a 3D image. I using Matlab for my simulations but as it involves huge data sets the processing time is very huge. code-
projection_length = 4100;
images = cell(1,500);
for i = 1:500
fname= sprintf('pre%03d.tif', i);
images{i} = imread(fname);
end
parfor q = 1:projection_length
tmpData = zeros(1600, 500);
for i = 1:500
fname= sprintf('pre%03d.tif', i);
tmpData(:, i) = images{i}(1 : 1600, q, :);
disp(['Analyzing projection ' num2str(q) ' of ' num2str(projection_length) ', Angle ' num2str(i) '...']);
end
idata=255-tmpData;
H = iradon(idata, 0.72, 'Hann', 0.8, 1600 );
postfname= sprintf('post%06d.tif', q);
imwrite(H, postfname);
end
I am loading all images into a cell in the beginning because I found that imread used most of the processing time when I read specific regions again and again in the loop, but since the images are large and the images variable is also too large in this case, i run out of memory. For projection length of around 1600 I undergo a serialization error that says-
Warning: Error caught during construction of remote parfor code. The parfor construct will now be run locally rather than on the remote matlabpool. The most likely cause of this is an inability to send over input arguments because of a serialization error. The error report from the caught error is:
Error using distcompserialize Out of Memory during serialization
Error in distcomp.remoteparfor (line 36) obj.SerializedInitData = distcompMakeByteBufferHandle(distcompserialize(varargin));
Error in parallel_function (line 437) P = distcomp.remoteparfor(W, @make_channel, parfor_C);
Error in Microfab_bead_reconstruction (line 15) parfor q = 1:projection_length
In parallel_function at 450
Is there a way to fix this, is it due to the huge memory of the variable 'images' which results in communication overhead when used parallely? Are there any other alternatives? I tried using the distributed class of variables but then I won't be able to use the parfor.
Akzeptierte Antwort
Weitere Antworten (1)
Walter Roberson
am 18 Jun. 2015
0 Stimmen
3 Kommentare
Tushar Anchan
am 18 Jun. 2015
Walter Roberson
am 19 Jun. 2015
projection_length = 4100;
numfiles = 500;
numrows = 1600;
tmpData = cell(projection_length);
parfor q = 1 : projection_length
tmpData{q} = zeros(numrows,numfiles,3);
end
%I am not positive this can be sliced on i. You might have to slice on q
parfor i = 1:numfiles
fname = sprintf('pre%03d.tif', i);
thisimage = imread(fname);
for q = 1 : projection_length
tmpdata{q}(:,i,:) = thisimage(1:numrows, q, :);
end
end
parfor q = 1 : projection_length
idata = 255 - tmpData{q};
H = iradon(idata, 0.72, 'Hann', 0.8, numrows );
postfname= sprintf('post%06d.tif', q);
imwrite(H, postfname);
end
Walter Roberson
am 22 Jun. 2015
projection_length = 4100;
numfiles = 500;
numrows = 1600;
q_chunk_size = 75; %number of projections to handle in a row. Adjust so that 1600 x numfiles x 3 x q_chunk_size fits in memory
for chunk_base = 1 : q_chunk_size : projection_length
%last chunk might be smaller
if chunk_base + q_chunk_size > projection_length
chunk_length = projection_length - chunk_base + 1;
else
chunk_length = q_chunk_size;
end
tmpData = cell(chunk_length);
parfor qrel = 1 : chunk_length
tmpData{qrel} = zeros(numrows,numfiles,3);
end
%I am not positive this can be sliced on i. You might have to slice on q
parfor i = 1:numfiles
fname = sprintf('pre%03d.tif', i);
thisimage = imread(fname);
for qrel = 1 : chunk_length
tmpdata{qrel}(:,i,:) = thisimage(1:numrows, qrel + chunk_base - 1, :);
end
end
parfor qrel = 1 : chunk_length
idata = 255 - tmpData{qrel};
H = iradon(idata, 0.72, 'Hann', 0.8, numrows );
postfname = sprintf('post%06d.tif', qrel + chunk_base - 1);
imwrite(H, postfname);
end
end
Kategorien
Mehr zu Parallel for-Loops (parfor) finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!