How to evaluate the computation time of some codes in parallel properly?

2 vues (au cours des 30 derniers jours)
Slivery
Slivery le 2 Août 2022
Commenté : Slivery le 4 Août 2022
I need to evaluate the computation time of an algorithm in multiple runs (e.g., 21 runs). To reduce the time, I use parfor to conduct 21 runs in parallel. However, I found that the compuation time of algorithms in parfor is very unstable, especially when the computation time of the algorithm is short. I use tic and toc in the parfor to record computation time.
Is there any other method in matlab to evaluate the computation time in parallel more properly ? Your help is really appreciated!
  2 commentaires
Jeffrey Clark
Jeffrey Clark le 3 Août 2022
@Slivery, I think you want to use parfeval and have the algorithm (or a wrapper) do the tic-toc. Assuming you have as many cores available that you try to run concurrently, the times of each should represent proper timing. If you don't control the number of concurrent executions tic-toc won't represent each correctly - you would need access to the thread accumulated execution times.
Or use parfor (or the above) and just do one call to cputime just before starting the 27 executions and again right after they all complete. According to this information in cputime, all MATLAB thread's execution times are summed into cputime readings.
Slivery
Slivery le 3 Août 2022
Thanks a lot for your help! I will try these methods.

Connectez-vous pour commenter.

Réponse acceptée

Jeffrey Clark
Jeffrey Clark le 3 Août 2022
@Slivery, when using the cputime difference method don't forget to divide by 21 (the number of executions being averaged). Depending on how short each computation is you may still have a lot of MATLAB and threading overhead time included in your timing. In that case add a wrapper for your function to simply loop N times and then include N in your division.

Plus de réponses (0)

Catégories

En savoir plus sur Startup and Shutdown dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by