How can I display the progress of a 'parfor' or 'parfeval' loop in MATLAB R2017a and newer?
22 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
MathWorks Support Team
il 23 Ott 2017
Modificato: MathWorks Support Team
il 26 Giu 2024
I have written some code which uses the MATLAB Parallel Computing Toolbox 'parfor' and 'parfeval' constructs. Since my code takes a long time to execute, I would like it to show some indication of the progress of the code such as the number of 'parfor' iterations completed, or the number of 'parfeval' function calls completed. How can I do this in MATLAB R2017a and newer?
Risposta accettata
MathWorks Support Team
il 26 Giu 2024
Modificato: MathWorks Support Team
il 26 Giu 2024
Building a 'waitbar' during a 'parfor' loop
1, The status of a 'parfor' loop can be displayed during execution using a data queue. The 'parallel.pool.DataQueue' function was added in MATLAB R2017a in order to send data from a MATLAB parallel worker to the MATLAB Desktop client:
In particular, the functionality of 'parallel.pool.DataQueue' can be used to display a 'waitbar' on the MATLAB Desktop client while a 'parfor' loop is executing on the parallel workers. Please refer to the following example in the 'parallel.pool.DataQueue' documentation page for more information:
The above example builds a 'parallel.pool.DataQueue' object in the MATLAB client and workers. Then, the 'afterEach' function is used to register a callback function which gets executed on the MATLAB Desktop client whenever new data is available in the queue. Finally, the 'send' function is used within the 'parfor' loop to provide data to the 'parallel.pool.DataQueue'.
Building a 'waitbar' during 'parfeval' execution
The following documentation page provides an example of using the 'waitbar' function to display the progress of a 'parfeval' computation:
This example can be opened in MATLAB using:
>> openExample('parallel/paralleldemo_blackjack_parfeval')
In the above example, note that the 'waitbar' is created and updated on the MATLAB Desktop client, while the computations are running on the MATLAB parallel workers. At the start of the code, 100 'parfeval' computations are queued. The 'waitbar' and plots are updated as each 'parfeval' computation is completed.
0 Commenti
Più risposte (0)
Vedere anche
Categorie
Scopri di più su Parallel for-Loops (parfor) in Help Center e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!