How can I make expm running on many cores?

2 visualizaciones (últimos 30 días)
Stefano
Stefano el 16 de Jun. de 2022
Respondida: Raymond Norris el 16 de Jun. de 2022
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);

Respuesta aceptada

Raymond Norris
Raymond Norris el 16 de Jun. de 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.

Más respuestas (0)

Categorías

Más información sobre Parallel Computing Fundamentals en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by