{"id":1825,"date":"2013-02-04T10:31:56","date_gmt":"2013-02-04T15:31:56","guid":{"rendered":"https:\/\/blogs.mathworks.com\/seth\/?p=1825"},"modified":"2017-05-23T13:33:19","modified_gmt":"2017-05-23T18:33:19","slug":"data-dependency-violation-errors-and-subsystem-semantics","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/simulink\/2013\/02\/04\/data-dependency-violation-errors-and-subsystem-semantics\/","title":{"rendered":"Data Dependency Violation Errors and Subsystem Semantics"},"content":{"rendered":"<p>Did you ever receive a \"data dependency violation\" error message from a Simulink model?<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q1\/data_dependency_violation_error.png\" alt=\"Input data dependency violation due to function-call or action susbsystems.  See Subsystem Examples in the Simulink library for valid and invalid examples of function-call and action subsystems.\" \/><\/p>\r\n\r\n<p>I will try to explain why this happens and what you need to do to avoid this error by introducing my favorite set of Simulink examples.<\/p>\r\n\r\n<p><strong>Function-Call Subsystems<\/strong><\/p>\r\n\r\n<p>To begin, let's explain how a <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/slref\/functioncallsubsystem.html\">Function-Call Subsystem<\/a> is executed.<\/p>\r\n\r\n<p>In the following example model, I display the blocks <a href=\"https:\/\/www.mathworks.com\/help\/simulink\/ug\/controlling-and-displaying-the-sorted-order.html\">sorted order<\/a>. You can notice that the Function-Call Subsystem is noted \"0:F{1}\". The \"F\" means that this subsystem is Function-Call and you should look at the call generator to see its sorted order. In this case, it is \"0:1\".<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q1\/simpleFcncallMdl.png\" alt=\"Example model involving function call\" \/><\/p>\r\n\r\n<p>If we generate code, we can see that the Function-Call Subsystem is executed in that order:<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q1\/fcnCallSSCode.png\" alt=\"Generated code involving a function call\" \/><\/p>\r\n\r\n<p><strong>Invoking a Function-Call Subsystem from an Atomic Subsystem<\/strong><\/p>\r\n\r\n<p>Now let's place the Function-Call Generator inside an Atomic Subsystem.<\/p> \r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q1\/FcncallAtomicMdl.png\" alt=\"Example model involving function call generated form an Atomic subsystem\" \/><\/p>\r\n\r\n<p>The same principle as in the previous example applies. Since the source is now inside an Atomic Subsystem, the Function-Call Subsystem is pulled inside the Atomic Subsystem.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q1\/fcnCallSSCodeAtomic.png\" alt=\"Generated code involving a function call generated from an Atomic Subsystem\" \/><\/p>\r\n\r\n<p><strong>Data Dependency Violation<\/strong><\/p>\r\n\r\n<p>Now, what happens if the Function-Call Subsystem takes an output of the Atomic Subsystem as input.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q1\/FcncallAtomicMdlImpossible.png\" alt=\"Problematic example model involving function call data dependency violation\" \/><\/p>\r\n\r\n<p>If you try to update this model, you will receive the following errors:<\/p>\r\n\r\n<p><font color=\"red\"><tt>Input data dependency violation due to function-call or action subsystems. See Subsystem Examples in the Simulink library for valid and invalid examples of function-call and action subsystems\r\n<br>\r\nInput ports (1, FcnCall) of 'fcnCallExample1c\/FcnCallSS' are involved in the loop\r\n<br>\r\nInput ports (1) of 'fcnCallExample1c\/GainBefore' are involved in the loop<\/tt><\/font><\/p>\r\n\r\n<p>I hope that based on the previous example, you can visualize why this semantics is impossible. On one hand, I specified that <tt>AtomicSS<\/tt> is atomic, including <tt>FcnCallSS<\/tt> that gets pulled in as shown above. On the other hand, <tt>FcnCallSS<\/tt> needs the output of <tt>Gain3<\/tt>. But <tt>Gain3<\/tt> cannot execute until <tt>AtomicSS<\/tt> is completed.<\/p>\r\n\r\n<p><strong>What to do?<\/strong><\/p>\r\n\r\n<p>To get help on this topic, search for the Simulink example titled <strong><a href=\"https:\/\/www.mathworks.com\/help\/simulink\/examples\/simulink-subsystem-semantics.html\">Simulink Subsystem Semantics<\/a><\/strong>. It can be opened by using <tt>sl_subsys_semantics<\/tt>.<\/p>\r\n\r\n<p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q1\/sl_subsys_semantics.png\" alt=\"Simulink Subsystem Semantics\" \/><\/p>\r\n\r\n<p>This example is a collection of models showing good and bad practices for the different types of subsystems available in Simulink. For function-call subsystems, you will find a large set of models. The green examples show the correct way to connect function-call subsystems and the red examples explain common errors.<\/p>\r\n\r\n<a href=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q1\/sl_subsys_semantics_fcn_call_examples_large.png\"><p><img decoding=\"async\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q1\/sl_subsys_semantics_fcn_call_examples_small.png\" alt=\"Simulink Subsystem Semantics\" \/><\/p><\/a>\r\n\r\n<p>For the example above, <tt>sl_subsys_fcncallerr7<\/tt> is the one you are looking for.<\/p>\r\n\r\n<\/p><strong>Now it's your turn<\/strong><\/p>\r\n\r\n<p>I hope <tt>sl_subsys_semantics<\/tt> will be as useful for you as it is for me! Give that a look and leave us a <a href=\"https:\/\/blogs.mathworks.com\/seth\/?p=1825&#comment\">comment below<\/a>.<\/p>\r\n\r\n\r\n\r\n \r\n\r\n\r\n\r\n\r\n","protected":false},"excerpt":{"rendered":"<div class=\"overview-image\"><img decoding=\"async\"  class=\"img-responsive\" src=\"https:\/\/blogs.mathworks.com\/images\/seth\/2013Q1\/sl_subsys_semantics_fcn_call_examples_small.png\" onError=\"this.style.display ='none';\" \/><\/div><p>Did you ever receive a \"data dependency violation\" error message from a Simulink model?\r\n\r\n\r\n\r\nI will try to explain why this happens and what you need to do to avoid this error by introducing my... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/simulink\/2013\/02\/04\/data-dependency-violation-errors-and-subsystem-semantics\/\">read more >><\/a><\/p>","protected":false},"author":41,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[21,43],"tags":[309,18,241,308],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/1825"}],"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=1825"}],"version-history":[{"count":27,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/1825\/revisions"}],"predecessor-version":[{"id":6589,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/posts\/1825\/revisions\/6589"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/media?parent=1825"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/categories?post=1825"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/simulink\/wp-json\/wp\/v2\/tags?post=1825"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}