parfor/variable sliced help

1 view (last 30 days)
Nick
Nick on 3 Jun 2012
Hi, I'm trying to speed up a code with matlabpool but I have some trouble with parfoor and the sliced variable.
The code use a 4D array (or, in an other variant, cell) called f (each dimension represent a parameter) that I have to optimize and plot. In a nutshell, I can summarize my code in the following one (it's the whole code)
N=10;
f = Inf*ones(N,N,N,N); % (1)
% f = cell(N,N,N,N); % (2)
% Matlabpool
if matlabpool('size')>1
matlabpool close force
end
matlabpool open
parfor t=1:N % t loop
for k=1:N
for l=1:k % l loop
f(k,l,t,1) = k*l*t; % (1)
% f{k,l,t,1} = k*l*t; % (2)
end
end
end
% Matlabpool
if matlabpool('size')>1
matlabpool close force
end
Please note that the inner loop (the l loop) goes from 1 to k. Even if at the moment I don't use the 4th dimension of f, the code doesn't run and it appears the error
Error using parforTest (line 11)
Error: The variable f in a parfor cannot be classified.
See Parallel for Loops in MATLAB, "Overview".
My questions are:
a) why it doesn't run? To me, it seems that f is a sliced variable.
b) I try to use cell instead of array (lines (2) instead of lines (1) ), but the error is the same. What is the difference between use cell and array regards to parfor loop? Actually, I will prefer to use array because since in dimension 1 and 2 of f the data are disposed "triangularly", I can suppress the plot of the other point giving them the value "Inf" in the allocation of f (line 2). Instead, with cell, to plot I have to fill up the dimension 1 and 2 with values "Inf" and then convert from cell to matrix.
c) I manage to run the code putting the parfor loop in the "l loop" instead of the the "t loop", bt it seem to me that in that case I have to call more times the workers so speeding down the optimization. From the workers point of view, is it faster to use the l loop or the t loop?
d) (Note) I use the block
% Matlabpool
if matlabpool('size')>1
matlabpool close force
end
because somethimes I interrupt the running (and workers stay open) so to get rid of trouble with workers I close and restart them. Is there other way to do so?
  1 Comment
Walter Roberson
Walter Roberson on 3 Jun 2012
A favor to everyone, please? Rename any variable named lower-case L -- especially in the font used on the forum it is difficult to distinguish between lower-case L and the digit 1 (one)

Sign in to comment.

Answers (1)

Nick
Nick on 3 Jun 2012
Sorry guys, I forgot to say goodbye and thanks in advice you all!
Thanks,
Nick

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!