{"id":5520,"date":"2016-05-17T16:39:04","date_gmt":"2016-05-17T21:39:04","guid":{"rendered":"https:\/\/blogs.mathworks.com\/simulink\/?p=5520"},"modified":"2017-04-27T09:39:39","modified_gmt":"2017-04-27T14:39:39","slug":"simulation-data-inspector-inside-parfor","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2016\/05\/17\/simulation-data-inspector-inside-parfor\/","title":{"rendered":"Simulation Data Inspector inside parfor"},"content":{"rendered":"<p>Last week I presented <a href=\"https:\/\/blogs.mathworks.com\/simulink\/2016\/05\/05\/tips-for-simulating-models-in-parallel\">a few tips to run simulations in parallel<\/a>, and received an interesting <a href=\"https:\/\/blogs.mathworks.com\/simulink\/2016\/05\/05\/tips-for-simulating-models-in-parallel\/#comment-165698\">comment<\/a> asking how to use the <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/inspect-and-analyze-simulation-results.html\">Simulation Data Inspector<\/a> in that context.<\/p>\n<p>So let's take a look!<\/p>\n<p><strong>Background<\/strong><\/p>\n<p>Before getting into details of <a href=\"https:\/\/www.mathworks.com\/help\/distcomp\/parfor.html\"><tt>parfor<\/tt><\/a>, 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.<\/p>\n<p>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:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q2\/priorRuns.png\" alt=\"Prior Runs\" \/><\/p>\n<p>If you click on the hyperlink, you will be given the choice to open or discard the prior runs.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q2\/importPriorRuns.png\" alt=\"Import Prior Runs\" \/><\/p>\n<p><strong>Creating runs in parallel<\/strong><\/p>\n<p>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.<\/p>\n<p>Once your model is <a title=\"https:\/\/www.mathworks.com\/help\/simulink\/export-runtime-information.html (link no longer works)\">setup to log data<\/a>, you can do the following:<\/p>\n<p>Before the <tt>parfor<\/tt> loop:<\/p>\n<ul>\n<li>Determine if SDI has data from prior sessions using <tt><a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016b\/simulink\/slref\/simulink.sdi.hasdatafrompriorsessions.html (link no longer works)\">hasDataFromPriorSessions<\/a><\/tt><\/li>\n<li>If there is data, discard it using <a title=\"https:\/\/www.mathworks.com\/help\/releases\/R2016b\/simulink\/slref\/simulink.sdi.discarddatafrompriorsessions.html (link no longer works)\"><tt>discardDataFromPriorSessions<\/tt><\/a><\/li>\n<\/ul>\n<p>Inside the <tt>parfor<\/tt> loop:<\/p>\n<ul>\n<li>Simulate the model using <tt><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/sim.html\">sim<\/a><\/tt><\/li>\n<li>Create a run in SDI using <tt><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/simulink.sdi.createrun.html\">createRun<\/a><\/tt><\/li>\n<\/ul>\n<p>After the <tt>parfor<\/tt> loop:<\/p>\n<ul>\n<li>Import the runs created by the workers using <tt>importDataFromPriorSessions<\/tt><\/li>\n<li>Open SDI using <tt><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/simulink.sdi.view.html\">view<\/a><\/tt><\/li>\n<\/ul>\n<p>Here is what it looks like in code:<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q2\/SDI_in_parfor.png\" alt=\"Importing data from parallel workers\" \/><\/p>\n<p>Once the runs are imported, you can inspect and compare them in the Simulation Data Inspector.<\/p>\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q2\/compareParallelRuns.png\" alt=\"Comparing data from parallel workers\" \/><\/p>\n<p><strong>Now it's your turn<\/strong><\/p>\n<p>Share any tips or tricks you have to run simulations in parallel by leaving a <a href=\"https:\/\/blogs.mathworks.com\/simulink\/?p=5520&#comment\">comment here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/simulink\/2016Q2\/compareParallelRuns.png\" onError=\"this.style.display ='none';\" \/><\/div>\n<p>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.<br \/>\nSo let's take a... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2016\/05\/17\/simulation-data-inspector-inside-parfor\/\">read more >><\/a><\/p>\n","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[143,33],"tags":[84,321,320],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/5520"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/users\/41"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/comments?post=5520"}],"version-history":[{"count":16,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/5520\/revisions"}],"predecessor-version":[{"id":6521,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/5520\/revisions\/6521"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=5520"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=5520"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=5520"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}