zamazalotta
zamazalotta

Reputation: 433

matlab bsxfun not multithreading?

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?

Upvotes: 1

Views: 963

Answers (1)

Amro
Amro

Reputation: 124563

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..

Upvotes: 2

Related Questions