Guy on Simulink

Simulink & Model-Based Design

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!

Background

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:

Prior Runs

If you click on the hyperlink, you will be given the choice to open or discard the prior runs.

Import 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:

Inside the parfor loop:

  • Simulate the model using sim
  • Create a run in SDI using createRun

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:

Importing data from parallel workers

Once the runs are imported, you can inspect and compare them in the Simulation Data Inspector.

Comparing data from parallel workers

Now it's your turn

Share any tips or tricks you have to run simulations in parallel by leaving a comment here.

|
  • print

댓글

댓글을 남기려면 링크 를 클릭하여 MathWorks 계정에 로그인하거나 계정을 새로 만드십시오.