I am trying to run some of my Matlab code in parallel on a Ubuntu 13.04 machine with Matlab 2013a and an i7 processor:
range = [0.75 0.8];
scores = cell(length(range), 1);
parfor i=1:length(range)
pca_accuracy = range(i);
scores{i, :} = cross_validation(data_features, labels, 69, pca_accuracy);
end
cross_validation()
returns a matrix. However, after this code is run, variable scores
is still a 2-by-1 cell array with each cell being empty. It seems as if cross_validation()
does not return anything.
If I convert the parfor-loop into a normal for-loop, it also works fine on this computer. I also tested this code (with the parfor-loop) on another computer (Windows 7, Matlab 2013b) and it works fine on there.
A short version of cross_validation()
is:
function scores = cross_validation(data_features, labels, number_of_test_blocks, pca_accuracy)
number_of_samples = size(data_features, 1);
samples_per_test_block = ceil(number_of_samples/number_of_test_blocks);
scores = zeros(number_of_test_blocks, samples_per_test_block);
end
Could anyone give advice?
Thanks!
parfor
in 2013a gets thrown off byscores{i, :}
. Have you tried assigning toscores{i, 1}
instead? – s.bandarapca_accuracy
may prevent parallelization (assigning to the same thing with all workers). -- Could you give an example of all variables? As is your code is not runnable. – Dennis Jaheruddin