2
votes

I've read that I can generate code from Simulink models/block diagrams. I am curious whether Simulink always converts a model to (c/c++/java) code prior to running a simulation in the Simulink software, and then execute that code? I mean, whenever I'm running a simulation is Matlab converting the block diagram to (c/c++/java) code and running that code behind the scene. In this case, simulation in Simulink directly depends on running some code; this information is important to me in some way.

Generating and running code for a complete model seems plausible, as we can write s-functions using C/Matlab code and use them as custom blocks. So simulating a model involves running code in some degree. Again, since we can write Matlab code as well, simulation may involve interpreting Matlab code in some environment. It makes me curious whether these information are available - how tightly running a simulation in Simulink depends on executing native code in user's machine.

I did some search before posting and found this SO question: How does simulation engine work? Discussion in this question does not answer my question directly.

1
Is your concern on simulation speeds ?PagMax
Simulation is basically a huge numerical integration problem. S-functions etc. only compute some entries on the left and the right side of the equation at each time step. It is converted to a compacted code when you Build your model and use things like XPC Target etc.percusse
@PagMax No I'm not concerned on speeds. Just curious whether native code gets generated and run behind the scene during simulation.Shafiul
Question fully answered?Daniel

1 Answers

4
votes

The answer depens on which mode you chose.

In the normal mode Simulink will run the model as it is primarily using the MATLAB execution engine. No code is generated. Native implemented parts (e.g. S-Functions) are used as individual binaries called by the MATLAB interpreter.

In the accelerator mode Simulink generates model code. This means your full model (except parts where code generation is impossible) is generated and compiled into one binary.

In the rapid accelerator mode not only your model but also the solver is generated and compiled into one binary, now running in a separate process.

For more details refer to the official documentation