About parallel computing toolbox

Hello, everyone,
I have a code of large scale problem, and it contains many for loops, and all loops are independent. I want to compute it by parallel toolbox.
Is it enough by changing all "for" to "parfor"?
Thank you.

 Respuesta aceptada

Walter Roberson
Walter Roberson el 10 de Nov. de 2013

1 voto

It might be, but you might also find that you need to adjust the code slightly. The easiest way to find out is to try.

4 comentarios

C Zeng
C Zeng el 11 de Nov. de 2013
Walter, thanks.
I notice that Matlab can recognize if it is proper to use parfor. For example sometimes it shows not proper due to data is indexed but not sliced, does it mean it will report error for sure?
C Zeng
C Zeng el 11 de Nov. de 2013
Actually it looks strange to me that parfor may run slower than for: tic for i=1:10^8 j=i+1; end toc takes 0.36 second, but
tic parfor i=1:10^8 j=i+1; end toc takes 34.6 seconds in my desktop.
Who can explain it? Thank you.
Walter Roberson
Walter Roberson el 11 de Nov. de 2013
Using multiple threads requires starting up new processes, setting up MATLAB on them, moving the code for the thread to the new process, moving the data for the thread to the new process, running the thread, synchronizing with the original process so that the various threads do not write over each other, collecting the results, and shutting down the process. That can be a lot more time than just doing the initial code in the original thread.
HK Physicist
HK Physicist el 22 de Mayo de 2020
It seems that it does not work cleverly.
It works only when the data structure is well planned manually.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Parallel Computing Toolbox en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 10 de Nov. de 2013

Comentada:

el 22 de Mayo de 2020

Community Treasure Hunt

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

Start Hunting!

Translated by