matlab bsxfun not multithreading?

972 Views Asked by At

I am using Matlab R2011a and according to the documentation the bsxfun function is multithreaded since R2009a (http://www.mathworks.com/help/techdoc/rn/br5k34y-1.html). However when I use bsxfun to compare a matrix against an upper and lower bound like this:

szS=10000;
szT=50000;
matT=rand(szT,3);
matS=rand(szS,3);
matSub=rand(szS,3);
matSlb=rand(szS,3);
for k=1:szS
   matchID = all([bsxfun(@lt,matT,matSub(k,:)) bsxfun(@gt,matT,matSlb(k,:))],2);
end

on the task manager I see than only one core of is engaged. Am I missing out something or is this normal?

1

There are 1 best solutions below

0
On

bsxfun executes the passed function in parallel by launching threads inside the same MATLAB process. Using only the "Task Manager" in Windows, you can't see the threads in execution, only running processes.

Just keep in mind that for the supported multithreaded functions, the speed up only applies if the data was large enough (but you are certainly above that threshold in you example).

Another option is with the Parallel Computing Toolbox. Using the matlabpool function, you can open new sessions of MATLAB in the back, each in a separate process. And when you call parfor it distributes the load on all workers. This approach scales very well especially when you run it on a cluster of computers.

I think it should be possible to use both in the same code..