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!
I just found the answer to my initial problem:
I was running the above Matlab script from the terminal using the command matlab -nodisplay -nodesktop -r "run('scriptname')"
. For some reason this did not assign the values to scores
after the parfor-loop.
Now, running the script either with matlab -nodisplay -nodesktop -r "scriptname"
or executing the script from within Matlab makes it work perfectly.
@mathworks: is this a bug? :)