필터 지우기
필터 지우기

Significant Slow down in Simulink coder ceval after compiling in c++ vs c

조회 수: 9 (최근 30일)
Wilson
Wilson 2023년 9월 1일
답변: Shreshth 2023년 9월 26일
I have a simulation that relies on a lot of coder ceval calls to look out to map information and data that uses external c/c++ files to determine the information required for navigation. Recently some code was added that was c++ files so c files were updated to be found by the c++ compiler. Now that our simulink model is built in c++ there has been an extreme slowdown in these functions that coder.ceval is running. We used to be able to run at 10-20x realtime speed, but now are lucky to get 2.5x realtime speed.
Not that removing these calls is not an option, it worked fine before we began comiling in C++.
Has this been experienced by anybody? Are there settings that we maybe have missed? Things we can do in our C files to make it faster?
  댓글 수: 1
James Tursa
James Tursa 2023년 9월 1일
편집: James Tursa 2023년 9월 1일
Can you compile the C files separately and link them into your C++ code (e.g., using extern "C" facility)? Does that change things?

댓글을 달려면 로그인하십시오.

답변 (1개)

Shreshth
Shreshth 2023년 9월 26일
Hello Wilson,
Simulink is a MATLAB-based graphical programming environment for modelling, simulating, and analysing multidomain dynamic systems. When you're integrating C/C++ code with Simulink, there are a few things to consider, especially when you're noticing a slowdown after switching from C to C++.
1. Optimization Settings in Simulink: Ensure that you're using the right optimization settings in Simulink. You can access these settings in the Simulink model by going to Configuration Parameters > Optimization. You might want to consider enabling options like "Signal storage reuse", "Expression folding", and "Enable local block outputs".
2. S-Function: If your C/C++ code is implemented as S-Functions, ensure they are written efficiently. You might want to consider using the `SS_OPTION_RUNTIME_EXCEPTION_FREE_CODE` flag to indicate that your S-function doesn't produce errors that could be trapped during runtime.
3. Use Fixed-Point Arithmetic Where Possible: If your model allows it, using fixed-point arithmetic can speed up the simulation. This is because fixed-point arithmetic is generally faster than floating-point arithmetic.
4. Memory Management: As with standalone C/C++ programs, efficient memory management is crucial in Simulink as well. Avoid frequent memory allocation and deallocation within the simulation loop.
5.Avoid Unnecessary Data Copying: If you're using MATLAB Function blocks or S-Functions, try to avoid unnecessary data copying. For example, use in-place operations instead of creating new variables.
6. Efficient Use of Bus Signals: If you're using bus signals, try to group signals into buses at the highest level possible to minimize the overhead of bus signal handling.
7. Block Choice and Settings: Some blocks might have settings that can be adjusted for better performance. Also, consider if there are alternative blocks or approaches that could be more efficient.
Remember that it's important to profile your Simulink model to understand where the bottlenecks are. You can use the Simulink Profiler (in the Debug menu) for this purpose. Once you know where the slowdowns are happening, you can focus your optimization efforts there.
Lastly, consult the (Simulink Documentation - MathWorks India) for more detailed information on improving simulation performance.
Hope it helps.
Thank you,
Shubham Shreshth.

카테고리

Help CenterFile Exchange에서 Signal Import and Export에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by