Filter löschen
Filter löschen

How do I resolve the Simulink error "JIT is required but JIT incompatibility found"

8 Ansichten (letzte 30 Tage)
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
rng('shuffle')
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?

Akzeptierte Antwort

MathWorks Support Team
MathWorks Support Team am 1 Jun. 2023
Bearbeitet: MathWorks Support Team am 1 Jun. 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:
rng('shuffle')
with:
coder.extrinsic("rng");
rng('shuffle');
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:
coder.extrinsic("rand");
newValue = rand();
Now, the call to "rand" will return different values in each run of the simulation.

Weitere Antworten (0)

Kategorien

Mehr zu Discrete-Event Simulation finden Sie in Help Center und File Exchange

Produkte


Version

R2022a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by