How do I resolve the Simulink error "JIT is required but JIT incompatibility found"
7 visualizzazioni (ultimi 30 giorni)
MathWorks Support Team il 26 Mag 2023
I am using SimEvents within Simulink to simulate a system with random behavior and, to study that randomized behavior, I want to make each run of the Simulink model use a different random seed and thus behaves in a unique way.
To do this, one of the blocks is running the MATLAB code
on startup to set a new random seed for the random number generator (RNG) each time the Simulink model is run.
However, when I try to run the Simulink model, I get the following error:
JIT is required but JIT incompatibility found
How can I resolve this error while still randomizing the different runs of the Simulink model?
MathWorks Support Team il 1 Giu 2023
Modificato: MathWorks Support Team il 1 Giu 2023
The error is referring to "Just In Time" (commonly shortened to JIT) compilation. This is a process where code for a usually interpreted language (MATLAB in this case) is compiled to machine code on the client's machine, just before being run (hence "just in time"). Contrast this with "Ahead of Time" compilation, where the developer's machine does the compilation. Using a JIT compiler often improves performance of the code, and MATLAB code in SimEvent models is always JIT compiled. This error is generated because some MATLAB functions (including "rng") cannot be JIT compiled and so this model can't run.
A workaround is to make sure that all interactions with the random number generator (RNG) are executed outside of Simulink. This can be achieved using the "coder.extrinsic" function, with the following steps:
1. Replace the your call to:
On its own, this change will resolve the error but the Simulink model will still behave the same in every run. This is because the "rng" function is resetting the RNG inside MATLAB, whereas all other functions are using the RNG inside the Simulink model.
2. Add calls to "coder.extrinsic" for each place where random numbers are used in the Simulink model. For example, a line like
newValue = rand();
should be replaced with:
newValue = rand();
Now, the call to "rand" will return different values in each run of the simulation.