Utilising Multicore on Linux Matlab 7.11 64-bit

I'm unable to get multicore working.
I am running the following in a script:
function partest
X=ones(10000);
for(a=1:100);
X.*X;
end
This is what my System Monitor shows: http://smanohar.com/matlab-multicore.png. As you can see, only one core is being used, despite the operation being element-wise!
I also get:
>> maxNumCompThreads
ans =
6
My system is:
Matlab: 7.11.0.584 R2010b, 64-bit (glnxa64)
OS: 64-bit Ubuntu 10.04, Kernel 2.6.32-29
CPU: Intel Xeon W3580, 6-core each @3.33 GHz
Why isn't it using all 6 CPUs? I thought that element-wise multiplication was parallellised?
Incidentally, Parallel toolbox is also installed. Under Parallel/Configurations Manager/local, when I press Start validation, the System monitor shows all cores are used for "Parallel Job" and "Matlabpool".

 Accepted Answer

Element-wise matrix operations are multithreaded by default in your MATLAB version. In fact, this has been true since R2008a.
For your problem, it seems like X.*X is too small of a computation to see the multithreaded effect. From your System Monitor image, the whole computation took about 20 seconds, which means that each loop (X.*X) is taking only about 0.2 seconds, so that's not long enough to see the effect. Note that for-loops are not multithreaded. To see the effect, you need to be looking at a long (single) computation. Try something like
X=ones(10000);
sqrt(X).^sqrt(X).^sqrt(X).^sqrt(X).^sqrt(X).^sqrt(X)
or something like that.

1 Comment

Aha! wonderful, thanks.
I tried a longer operation, as you suggested,
and it did indeed use all my CPUs!

Sign in to comment.

More Answers (1)

MALTAB by default is a single threaded process. Though you have multicore process, it does not use multiple cores to perform calculations.
Also the functions that you have written does not use any of the features of Parallel Computing Toolbox. Refer to the following documentation for more information on using the parallel computing toolbox.

3 Comments

Hi! thanks for the prompt response. Oh well that is a shame; I thought I'd read somewhere that Matlab (v7 onwards?) is supposed to *automatically* parallelise elementwise matrix operations if it were more efficient to do so... Sounds like this isn't the case. (If not, why not?)
So there's no way to do it without the parallel toolbox?
Out of interest, I tried the following code, to see what would happen if I could parallelise with for loops:
X=ones(10000); u=zeros(100,1);
parfor i=1:100
u(i)=sum(sum(X+X));
end
Very interesting: it took 30 seconds and only 1 CPU was active.
I replaced the critical line with:
u(i)=sum(sum(X));
i.e. I removed the elementwise binop. This time, it ran *really* fast, 4 seconds, and all 6 CPUs were active.
Do you understand why this would be?
Hi Sanjay,
Did you open the matlabpool?
Correction on this answer. In R2010b (since R2008a), MATLAB automatically multi-threads certain operations (linear algebra and element-wise computations).

Sign in to comment.

Categories

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!