%% Preserve Subsystem Boundaries in Generated Code
% This example shows how to preserve the boundary of a virtual subsystem. By
% selecting subsystem parameter *Treat as atomic unit*, you instruct the 
% code generator to build code for the subsystem so that it executes as an atomic unit.
% Once you mark a system as atomic, you can specify how the code generator
% represents the subsystem in code by setting the block parameter  
% *Code Generation Function Packaging*. You can specify that the code 
% generator produce these code implementations for the subsystem:
%
% * Inline:  Inline the subsystem code at the call sites
% * Function:  A void/void function with I/O and internal data in global data structure
% * Reusable function:  A re-entrant function with data passed in as part of function arguments
% * Auto:  Let Simulink Coder optimize the implementation based on context
% 
% 1. Generate code and a code generation report.
%
% 2. Use the generated report to inspect the generated source file
% |rtwdemo_atomic.c|. For |SS1|, the code generator produces reusable function 
% code with function name |myfun|.
%
% Simulink and Simulink Coder can avoid artificial algebraic loops if you
% select parameter *Minimize algebraic loop occurrences*.  See the Simulink 
% documentation for information on minimizing occurrences of algebraic loops.

% Copyright 2020 The MathWorks, Inc.

%% Example Model
model = 'rtwdemo_atomic';
open_system(model);