0

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!

5
  • 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? Commented Nov 14, 2013 at 15:13
  • @bdecaf Thanks! I added the code to the initial post. Commented Nov 14, 2013 at 15:21
  • Perhaps parfor in 2013a gets thrown off by scores{i, :}. Have you tried assigning to scores{i, 1} instead? Commented Nov 14, 2013 at 15:50
  • @s.bandara Thanks for your answer. This doesn't work either unfortunately. Commented Nov 14, 2013 at 15:54
  • 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. Commented Nov 14, 2013 at 16:15

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.