How do I resolve the Simulink error "JIT is required but JIT incompatibility found"
10 次查看(过去 30 天)
显示 更早的评论
MathWorks Support Team
2023-5-26
编辑: MathWorks Support Team
2023-6-1
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?
采纳的回答
MathWorks Support Team
2023-6-1
编辑:MathWorks Support Team
2023-6-1
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.
0 个评论
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Discrete-Event Simulation 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!