How can i re-mex 'Matlab coder' generated .c, .h and .o files using ' -largedimarrays' flag ?

10 views (last 30 days)
Hi, I have some perfectly working matlab codes that I use for some calculation of electrical properties. These codes takes too much time in matlab so I decided to create mex files using codegen, and succeeded. For a while, I am using mex files in my program and there is a great improvement in execution time. However, my electrical problems getting bigger while the time passes. So, recently I got an error saying that: Cannot grow a matrix with greater than intmax() elements. I learned that to overcome this problem '-largedimarrays' flag should be used for mexing. But, I do not know how to mex the files in the codegen file created by matlab. I made a few research and still couldn't find a way to mex these files. So I am asking for help in the following issues:
1- codegen command created lots of .c .h ... files in a folder named codegen for a one .m file. How can I re-mex these files using-largesimarrays?
2- can I make it directly from the .m file by some option or a codegen flag while running codegen?
3- are there any other methods rather than largedimarrays method to solve the problem I faced in the first hand? (cannot grow ...)
Thank you in advance

Accepted Answer

Ryan Livingston
Ryan Livingston on 10 Dec 2014
Edited: Ryan Livingston on 10 Dec 2014
Currently, the maximum array size supported by MATLAB Coder MEX files is intmax('int32') elements:
Unfortunately, the limitation is deeper than a simple lack of the -largedimarrays flag. Rather, it results because of how the code is generated.
We made a note of your request for larger array support.
One possible workaround is to split your arrays into smaller pieces and work on those and then combine the results at the end of your computation.
  2 Comments
Özer
Özer on 13 Dec 2014
Thanks for the response.
- So, do you say, even if I change in the Coder-created *.c files 'int32' with 'int64', mex does not support it (i.e. I cannot mex it manually)?
- And, for dynamic memory allocation, I have only got the option to split the matrix after some size exceeded?
Ryan Livingston
Ryan Livingston on 14 Dec 2014
1. MEX can support 64-bit sizes/indices:
The code currently generated by MATLAB Coder can use 32-bit indices.
Modifying the generated MEX code by hand is not recommended as there are dependencies for the MEX code on a runtime library that may also have restrictions.
2. Unfortunately, yes. The current best option that I see is to partition the arrays after they exceed the documented maximum size.

Sign in to comment.

More Answers (0)

Categories

Find more on MATLAB Coder in Help Center and File Exchange

Products

Community Treasure Hunt

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

Start Hunting!