problems at using the "parfor" loop caused by "print " command
Show older comments
Hi All,
I'm having a problems at using the "parfor" loop. The main idea of the program, parallel processing txt files. For each txt file, I create two graphs based on the information contained in it. The graphs are created in the program "MainInd". Then I send the "handles" of the graphs to the function "Savegraphs". The task of the "Savegraphs" function, to save the created graphs using the cycle "for" via the command “print”. Error which Matlab returns is as follows:
_Error using parallel_function (line 598) Problem converting PostScript. System returned error: -1.Failed to convert to output format; Ghostscript status: -100. Unable to open the initial device, quitting. Unable to open the initial device, quitting. Error stack: ghostscript.m at 188 print>LocalPrint at 311 print.m at 237 Savegraphs.m at 17
Error in MainInd (line 10) parfor idxFileName = 1:N_
The functions "MainInd" and "Savegraphs" look as follow:
MainInd.m
clear
inFolder = 'C:\Program Files\MATLAB\Last\work\parallel_comp\Jobexample\In\';
listOfFiles = dir([inFolder '*.txt']);
N = length(listOfFiles);
fileNames = cell(1,N);
parfor idxFileName = 1:N
fileNames{idxFileName} = listOfFiles(idxFileName). name ;
fid = fopen([inFolder fileNames{idxFileName}]);
fprintf('file name: %s\n',fileNames{idxFileName});
vec = fscanf(fid,'%f ');
f1=figure(51);
set(f1,'Visible','off')
set(f1,'PaperUnits','inches','PaperPosition',[0 0 1920 1080])
plot(vec,sin(vec))
title('sin')
f2=figure(2);
set(f2,'Visible','off')
set(f2,'PaperUnits','inches','PaperPosition',[0 0 1920 1080])
plot(vec,cos(vec))
title('cos')
w = getCurrentTask();
Savegraphs(f1,f2,w.ID)
end
The Savegraphs.m:
function Savegraphs(f1,f2,idfold)
newdir = sprintf('%d',idfold);
if ~exist(['G:\',newdir], 'dir')
mkdir(['G:\',newdir]);
end
graphs=[f1,f2];
NamesGr={'f1.png','f2.png'};
filePNGQ={['G:\',newdir,'\',NamesGr{1}],['G:\',newdir,'\',NamesGr{2}]};
for bb=1:length(graphs)
print(graphs(bb),'-dpng','-r1',filePNGQ{bb})
end
If in the "MainInd" I change "parfor" to "for", and Savegraphs (f1, f2, w.ID) to Savegraphs (f1, f2, idxFileName) everything works. In order to run the program you need to change a variable “inFolder” in the "MainInd" – to the corresponding path in your machine and the path G: \ in the "SaveGraphs" - to the corresponding path also. The txt files I attached to the message.
B.R.
Y.
4 Comments
Edric Ellis
on 15 Apr 2015
Which version of MATLAB are you using?
Yura
on 15 Apr 2015
Edric Ellis
on 16 Apr 2015
There were several printing problems that occurred on workers on releases prior to R2014b (the first with the new MATLAB graphics system) - I would recommend upgrading and trying again.
Answers (0)
Categories
Find more on Parallel for-Loops (parfor) in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!