Simulink Compiler errors out with matrix math

5 views (last 30 days)
I'm having a problem making a FMU block via Simulink Compiler - I've narrowed the problem down to matrix math. I get an error when I try to multiply a 3 x 3 matrix (or larger). I can multiply 2 x 2 matrices, but once I add a dimension, I get an error. I have "Use algorithms optimized for row-major array layout" checked ... I'm just stumped by this. I can't tell if this is some FMU limitation, or a Simulink Compiler limitation - any help would be welcome
ETA: I tried to compile it normally into an executable using coder, and experienced the same errors. So it's not related to the FMU - for some reason, the compiler doesn't like matrices 3 x 3 or larger ...

Answers (1)

Aishwarya Shukla
Aishwarya Shukla on 3 Mar 2023
Hi @Wayne,
It sounds like you are encountering a limitation with the Simulink Compiler when dealing with larger matrices. Without more information on the specific error message you are receiving, it's difficult to provide a specific solution. However, here are a few general suggestions that may help:
  1. Check your memory settings: If your system doesn't have enough memory, it could cause issues when dealing with larger matrices. Make sure you have enough RAM and consider adjusting your memory settings in MATLAB/Simulink.
  2. Consider using a different data type: Depending on the size of your matrices, you may be running into precision issues with the default double data type. Consider using a smaller data type, such as single or int16, if appropriate for your application.
  3. Try breaking up the matrix operations: If you are encountering issues when multiplying larger matrices, try breaking up the operation into smaller pieces. For example, instead of multiplying a 3x3 matrix by another 3x3 matrix, you could multiply a 3x1 vector by a 1x3 matrix three times.
  4. Check your code for errors: Make sure your code is correctly written and that there are no typos or syntax errors. Check that your input and output sizes match, and that all necessary libraries are included.
  1 Comment
Wayne Thomasson
Wayne Thomasson on 6 Mar 2023
Hey, very much appreciate your response. I have tried a few permutations to test this: I am able to add, e.g. two 2x2 matrices, and 1x4 vectors. But when I add 3x3 matrices and move to 1x5 vectors, it gives an error. The model itself runs fine with 3x3 and 1x5, I get correct values in the Simulink output. It's only when I try to compile to an FMU that I get an error. The error messages are below:
"C:/RTN/MATLAB/R2022a/sys/lcc64/lcc64/bin/lcc64" -c -w -noregistrylookup -nodeclspec -IC:/RTN/MATLAB/R2022a/sys/lcc64/lcc64/include64 -DRT -DUSE_RTMODEL -fno-inline -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DMAT_FILE=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0 -DTID01EQ=0 -DMODEL=FT1299Sim -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DRT -DUSE_RTMODEL -IC:/RTN/OCXSimulation/FT1299 -IC:/RTN/OCXSimulation/FT1299/FT1299Sim_fmu2cs_rtw -IC:/RTN/MATLAB/R2022a/extern/include -IC:/RTN/MATLAB/R2022a/simulink/include -IC:/RTN/MATLAB/R2022a/rtw/c/src -IC:/RTN/MATLAB/R2022a/rtw/c/src/ext_mode/common -IC:/RTN/MATLAB/R2022a/toolbox/shared/simulink/fmuexport/fmi2_noprefix -IC:/RTN/MATLAB/R2022a/rtw/c/src/rapid/fmu -Fo"FT1299Sim_data.obj" "C:\RTN\OCXSimulation\FT1299\FT1299Sim_fmu2cs_rtw\FT1299Sim_data.c"
"C:/RTN/MATLAB/R2022a/sys/lcc64/lcc64/bin/lcc64" -c -w -noregistrylookup -nodeclspec -IC:/RTN/MATLAB/R2022a/sys/lcc64/lcc64/include64 -DRT -DUSE_RTMODEL -fno-inline -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DMAT_FILE=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0 -DTID01EQ=0 -DMODEL=FT1299Sim -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DRT -DUSE_RTMODEL -IC:/RTN/OCXSimulation/FT1299 -IC:/RTN/OCXSimulation/FT1299/FT1299Sim_fmu2cs_rtw -IC:/RTN/MATLAB/R2022a/extern/include -IC:/RTN/MATLAB/R2022a/simulink/include -IC:/RTN/MATLAB/R2022a/rtw/c/src -IC:/RTN/MATLAB/R2022a/rtw/c/src/ext_mode/common -IC:/RTN/MATLAB/R2022a/toolbox/shared/simulink/fmuexport/fmi2_noprefix -IC:/RTN/MATLAB/R2022a/rtw/c/src/rapid/fmu -Fo"RTWCG_FMU_util.obj" "C:\RTN\MATLAB\R2022a\rtw\c\src\rapid\fmu\RTWCG_FMU_util.c"
"C:/RTN/MATLAB/R2022a/sys/lcc64/lcc64/bin/lcc64" -c -w -noregistrylookup -nodeclspec -IC:/RTN/MATLAB/R2022a/sys/lcc64/lcc64/include64 -DRT -DUSE_RTMODEL -fno-inline -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DMAT_FILE=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0 -DTID01EQ=0 -DMODEL=FT1299Sim -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DRT -DUSE_RTMODEL -IC:/RTN/OCXSimulation/FT1299 -IC:/RTN/OCXSimulation/FT1299/FT1299Sim_fmu2cs_rtw -IC:/RTN/MATLAB/R2022a/extern/include -IC:/RTN/MATLAB/R2022a/simulink/include -IC:/RTN/MATLAB/R2022a/rtw/c/src -IC:/RTN/MATLAB/R2022a/rtw/c/src/ext_mode/common -IC:/RTN/MATLAB/R2022a/toolbox/shared/simulink/fmuexport/fmi2_noprefix -IC:/RTN/MATLAB/R2022a/rtw/c/src/rapid/fmu -Fo"FT1299Sim_fmu.obj" "FT1299Sim_fmu.c"
"C:/RTN/MATLAB/R2022a/sys/lcc64/lcc64/bin/lcc64" -c -w -noregistrylookup -nodeclspec -IC:/RTN/MATLAB/R2022a/sys/lcc64/lcc64/include64 -DRT -DUSE_RTMODEL -fno-inline -DCLASSIC_INTERFACE=0 -DALLOCATIONFCN=0 -DMAT_FILE=0 -DONESTEPFCN=1 -DTERMFCN=1 -DMULTI_INSTANCE_CODE=0 -DINTEGER_CODE=0 -DMT=0 -DTID01EQ=0 -DMODEL=FT1299Sim -DNUMST=1 -DNCSTATES=0 -DHAVESTDIO -DRT -DUSE_RTMODEL -IC:/RTN/OCXSimulation/FT1299 -IC:/RTN/OCXSimulation/FT1299/FT1299Sim_fmu2cs_rtw -IC:/RTN/MATLAB/R2022a/extern/include -IC:/RTN/MATLAB/R2022a/simulink/include -IC:/RTN/MATLAB/R2022a/rtw/c/src -IC:/RTN/MATLAB/R2022a/rtw/c/src/ext_mode/common -IC:/RTN/MATLAB/R2022a/toolbox/shared/simulink/fmuexport/fmi2_noprefix -IC:/RTN/MATLAB/R2022a/rtw/c/src/rapid/fmu -Fo"lccstub.obj" "C:\RTN\MATLAB\R2022a\sys\lcc64\lcc64\mex\lccstub.c"
"### Creating shared library "./FT1299Sim_win64.dll" ..."
"C:/RTN/MATLAB/R2022a/sys/lcc64/lcc64/bin/lcclnk64" -dll -entry LibMain -s -LC:/RTN/MATLAB/R2022a/sys/lcc64/lcc64/lib64 FT1299Sim.def -o ./FT1299Sim_win64.dll @FT1299Sim.rsp
ft1299sim.obj .text: undefined reference to '_mm_loadu_pd'
ft1299sim.obj .text: undefined reference to '_mm_add_pd'
ft1299sim.obj .text: undefined reference to '_mm_storeu_pd'
gmake: *** [FT1299Sim_win64.dll] Error 4
The make command returned an error of 2
Build Summary
Top model targets built:
Model Action Rebuild Reason
=====================================================================
FT1299Sim Failed Code generation information file does not exist.
0 of 1 models built (0 models already up to date)
Build duration: 0h 0m 6.834s

Sign in to comment.

Categories

Find more on Arduino Hardware in Help Center and File Exchange

Products


Release

R2022a

Community Treasure Hunt

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

Start Hunting!