I'm trying to prove a code to run in parallel, code works perfectly except when I'm assiging data to a sliced variable, I believe I'm respecting Matlab's parfor restrictions, and in fact it runs smoothly for some parfor iterations but a certain point Matlab crashs asking to exiting.
The problem is in the last line when asigning values to "features" (I've tried also with cells but same problem):
if (matlabpool('size')==0)
matlabpool();
end
%Prepare iterations
numTrain = size(Xnorm(1000:1250,:),1);
numFeatures = size(Xnorm,2);
classData=Y(1000:1250,:);
%Linear Space for Grid
zz = linspace(0.1,20,10);
zsize=length(zz);
%Definitions to use inside parfor
features=zeros(numFeatures,1);
fmax=@(x) max(x);
parfor i = 1:numFeatures
%Internal variables definition
CsCross=zeros(zsize,1);
SigmaCsMax=zeros(zsize,1);
fprintf('\nFeature:%i...',i);
for j=1:zsize
%Precompute kernel
K = [ (1:numTrain)' , gpuKernel(Xnorm(1000:1250,i),zz(j)) ];
for iter = 1:zsize
options = sprintf('-c %d -t 4 -v 10 -q',zz(iter));
model = svmtrain(classData, K, options);
CsCross(iter)=model;
end
SigmaCsMax(j)=fmax(CsCross);
end
temp=fmax(SigmaCsMax);
%%% HERE THE ERROR IS CAUSED. When removed code runs smoothly
features(i)=temp;
end
Any suggestion about it? What am I doing wrong? (just to say code works without parfor)
Thanks in advance,
Sergi