How can I make expm running on many cores?

1 次查看(过去 30 天)
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);

采纳的回答

Raymond Norris
Raymond Norris 2022-6-16
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.

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Linear Algebra 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by