Build a mex file from a complicated m-file.

I have a heavy m-file with around 50,000 lines (~5000 kb). I need to call this function hundreds of times and each function call takes a few seconds. I tried to convert this function into a mex file to reduce computing time, but I am not quite sure whether codegen supports conversion of such a large script. Any comment is welcomed!
Jongwoo

 채택된 답변

Walter Roberson
Walter Roberson 2015년 7월 24일

2 개 추천

I wouldn't recommend that to start. Altering code properly for code generation takes a fair bit of time. It would be more productive to profile the code first, find out where the slow parts of it are and see if you can recode them, possibly including moving just the slowest parts to mex.

댓글 수: 5

+1 for profiling the code in MATLAB, factoring out the slow parts, and just trying to generate a MEX function for those. The MATLAB Coder documentation has a section on performance and some best practices for accleration using MATLAB Coder.
Jongwoo Lee
Jongwoo Lee 2015년 7월 28일
편집: Jongwoo Lee 2015년 7월 28일
Thank you for your answer. I will follow your advice.
While waiting for the answer I already tried codegen, and what happened is all relevant .c files seem to be made but .obj is not, so I wonder what is going on right now. (please see attached .bmp file; just ignore some Koreans).
You should have a file called auto_OverallStructuteDynamics2.mexw64 in your current working directory. Is that the case? If not, are there errors shown in the report?
You can use that MEX function in MATLAB. If you want to generate standalone code you need to select a standalone target like a static library. Try:
codegen auto_OverallStructureDynamic2 -config:lib ...
or use:
cfg = coder.config('lib');
codegen ... -config cfg
to generate a static library.
Jongwoo Lee
Jongwoo Lee 2015년 7월 29일
I don't see .mexw64 file in the directory. I see error: "error building mex function" in the error report, without any details. I will try your suggestions and give feedback here. Thank you!
In the report, you can click on the "Build Log" tab. It should show any compiler errors if that is where the error happened.

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

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 MATLAB Coder에 대해 자세히 알아보기

제품

질문:

2015년 7월 24일

댓글:

2015년 7월 29일

Community Treasure Hunt

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

Start Hunting!

Translated by