How can I make expm running on many cores?

2 views (last 30 days)
I need to compute the exponential of large matrices. I am using the instruction expm and I would like to make it running on a parallel manner.
How can I make this function running on many cores? For instance the example below is still running on one core.
delete (gcp('nocreate'))
parpool(4);
ntot=2^12
Atot=rand(ntot,ntot);
expm(Atot);

Accepted Answer

Raymond Norris
Raymond Norris on 16 Jun 2022
Starting a parallel pool doesn't run subsequent MATLAB code in parallel, it simple starts a colletion of headless MATLAB processes. You need to use a parallel construct (e.g., parfor, gpuArray, etc.) to explicitly parallelize the code.
Regarding your code, expm is already using multi-core. You can test this via the following example. For this I'm running MATLAB R2022a on a 12-core VM.
maxNumCompThreads(1);
ntot=2^12;
Atot=rand(ntot,ntot);
tic, expm(Atot); toc
Elapsed time is 27.851388 seconds.
maxNumCompThreads(4);
ntot=2^12;
Atot=rand(ntot,ntot);
tic, expm(Atot); toc
Elapsed time is 7.882113 seconds.
maxNumCompThreads(12);
ntot=2^12;
Atot=rand(ntot,ntot);
tic, expm(Atot); toc
Elapsed time is 3.815132 seconds.
MATLAB is already implicitly parallelizing expm.

More Answers (0)

Categories

Find more on Parallel Computing Fundamentals in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!