You'd think this would be simple question, but I can't find the solution. Take the following loop:
A = zeros(1,10000000);
parfor i = 1:length(A)
A(i) = i;
end
This only runs on a single core on my computer, although it's readily parallelisable (or at least it should be). I am using Matlab 2012b, and I've tried looking for documentation on how to create parallel loops but can't find any (the matlab docs just show examples of how to create these loops, not how to actually run them in parallel).
I've tried looking up how to modify parallel computing toolbox settings, but none of them work since they're all for Matlab 2013 (I'm using 2012b). If someone could provide an example of a trivial, parallelisable loop that actually runs in parallel I would be very grateful!
Note: I have checked and the parallel computing toolbox is installed, although I have no way of knowing if it is enabled, or how to enable it, since the documentation doesn't seem to provide an answer to this for my version (I typed preferences into the command prompt but didn't see it there).
EDIT: I got it working by doing this:
matlabpool('open',4);
A = zeros(1,10000000);
parfor i = 1:length(A)
A(i) = i;
end
matlabpool('close');
... but I don't really know why this works, whether I have close the pool every time, what a pool actually is (I've read the documnentation, still don't get it), and how matlabpool differs from parpool...
A(i)=i, now you're just overwriting the same variable over and over and after the loop,Awill just be equal to10000000. - Gunther Struyfparpool? It's in the "see also" section of theparfordocumentation: mathworks.de/de/help/distcomp/parpool.html - sebastianmatlabpool open- chappjc