Simulation Data Inspector inside parfor
Last week I presented a few tips to run simulations in parallel, and received an interesting comment asking how to use the Simulation Data Inspector in that context.
So let's take a look!
Before getting into details of parfor, let's first discuss an interesting feature of the Simulation Data Inspector (SDI). In case you were not aware, SDI uses a database file to store the runs it displays. That way, if you close SDI, or even shutdown MATLAB, you do not lose your data.
In case you did not notice, when you open SDI in a new MATLAB session and the previous session was containing runs, you can see the following in the bottom left corner:
If you click on the hyperlink, you will be given the choice to open or discard the prior runs.
Creating runs in parallel
Since parallel workers are MATLAB sessions without the graphical interface, it is possible to use this prior session data feature to import runs created by the workers.
Once your model is setup to log data, you can do the following:
Before the parfor loop:
- Determine if SDI has data from prior sessions using hasDataFromPriorSessions
- If there is data, discard it using discardDataFromPriorSessions
Inside the parfor loop:
After the parfor loop:
- Import the runs created by the workers using importDataFromPriorSessions
- Open SDI using view
Here is what it looks like in code:
Once the runs are imported, you can inspect and compare them in the Simulation Data Inspector.
Now it's your turn
Share any tips or tricks you have to run simulations in parallel by leaving a comment here.
コメントを残すには、ここ をクリックして MathWorks アカウントにサインインするか新しい MathWorks アカウントを作成します。