I have a question about sum in matlab.
For a vector (1xN matrices), sum seems to be parallelised. For example,
a=rand(1,100000000);
maxNumCompThreads(2);
tic;for ii=1:20;b=sum(a,2);end;toc
maxNumCompThreads(1);
tic;for ii=1:20;b=sum(a,2);end;toc
> Elapsed time is 1.219342 seconds.
> Elapsed time is 2.393047 seconds.
But if instead I consider a 2xN matrix,
a=rand(2,100000000);
maxNumCompThreads(2);
tic;for ii=1:20;b=sum(a,2);end;toc
maxNumCompThreads(1);
tic;for ii=1:20;b=sum(a,2);end;toc
> Elapsed time is 7.614303 seconds.
> Elapsed time is 7.432590 seconds.
In this case, sum doesn't seem to benefit from the extra core.
Anyone came across this before? I'm wondering if this could be due to indexing overhead and whether it is possible to make sum faster in the case of 2xN matrices.
Thanks a lot.