parallel pool to increase code speed

I have a very long code that uses a lot of functions which I have written, currently the code takes around 3 minutes to run. I have read about parallel pool but im not sure how to use it and if it would be a good option to use in my case to improve the running time of my code.
I have tried turning on parallel pool from the bottom left of the matlab menu and running my code but there was no differenece and from the task manager I can tell the same CPU usage is being allocated. Any advice is appreciated

3 comentarios

KSSV
KSSV el 22 de Jun. de 2022
Editada: KSSV el 22 de Jun. de 2022
Striaght away, you cnnot go to parallel code. You need to check is my code optimised? Did I vectorise the code?
REad about profile, see where your code is spending much time. From this try to optimmise the function.
After the above checks are done, then think of parallel code. Every code cannot be parallelised, it depends on how your code is.
Turning on the parallel pool will not run your code in parallel.
Ahmed Abdulla
Ahmed Abdulla el 22 de Jun. de 2022
@KSSV Yes I have already used profile and got rid of all unneeded loops and vectorised what I can and now i got to parralel pool
KSSV
KSSV el 22 de Jun. de 2022
We have to look into the code to suggest.

Iniciar sesión para comentar.

Respuestas (1)

Raymond Norris
Raymond Norris el 22 de Jun. de 2022

1 voto

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. Keep in mind that code that takes 3 minutes to run might improve with more resources, but it could also take more time just send data/instructions back and forth to all of the MATLAB processes. Explicit MATLAB multi-parallelism benifits more for longer running jobs (e.g, hours/days down to minutes/hours) than say running a job from 3 minutes to 3 seconds.
Based on the Profiler, have you identified for-loops that could benefit from being re-written as parfor? If so, what were the results of that?

Categorías

Más información sobre Startup and Shutdown en Centro de ayuda y File Exchange.

Productos

Versión

R2021b

Preguntada:

el 22 de Jun. de 2022

Respondida:

el 22 de Jun. de 2022

Community Treasure Hunt

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

Start Hunting!

Translated by