How can I make expm running on many cores?

3 ビュー (過去 30 日間)
Stefano
Stefano 2022 年 6 月 16 日
回答済み: Raymond Norris 2022 年 6 月 16 日
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 件)

Community Treasure Hunt

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

Start Hunting!

Translated by