0
votes

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!

1
Could you provide a slimmed down variant of cross_validation and the variables so we can check if we have the same behavior on our machines?bdecaf
@bdecaf Thanks! I added the code to the initial post.davhab
Perhaps parfor in 2013a gets thrown off by scores{i, :}. Have you tried assigning to scores{i, 1} instead?s.bandara
@s.bandara Thanks for your answer. This doesn't work either unfortunately.davhab
I don't think this will leave your variables empty, but assigning to pca_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

1 Answers

1
votes

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? :)