Effacer les filtres
Effacer les filtres

Maximum input matrix size for mex function

3 vues (au cours des 30 derniers jours)
Ryan Johnson
Ryan Johnson le 1 Août 2012
I am building mex functions from .m files and am having issues with MATLAB crashing when my input matrix is too large. I am defining the input variable types using the MATLAB Coder project view.
I have created a very basic example which should show that the issue is isolated to the input matrix size. The .m code is the following:
function [return1 return2] = mexTest( input1, input2 ) %#codegen
return1 = input1(100,100);
return2 = input2 + input1(1,1);
end
It builds fine with Coder. input1 is defined as a double(2560x1920) and input2 is a double(1x1)...both sizes are defined in the MATLAB Coder project UI.
The code builds fine, but when I run it, MATLAB crashes with no warning messages, just a Windows message indicating that MATLAB has stopped working. I am on a Windows 7 64bit machine running MATLAB R2012a 32bit (7.14.0.739).
Furthermore, when I decrease the size of input1 to say, 100x100, the function runs just fine with no issues. I have tried increasing the maximum stack usage (up to 500,000,000 bytes) in the project settings as well as trying different options for variable sizing support.
When I run the memory command I get the following output, which seems do indicate that I have sufficient room to do what I am attempting.
Maximum possible array: 2046 MB (2.145e+09 bytes) *
Memory available for all arrays: 3355 MB (3.518e+09 bytes) **
Memory used by MATLAB: 469 MB (4.921e+08 bytes)
Physical Memory (RAM): 8182 MB (8.580e+09 bytes)
Any help or tips that can be provided would be very much appreciated.

Réponses (1)

John Elliott
John Elliott le 1 Août 2012
Hi Ryan,
You are probably running up against the Win32 stack size limit. One solution is for you to declare your input matrix to be variable-size. Large variable-size matrices such as yours will be allocated on the heap, not on the stack.
For your matrix input, you could define its type by example in the project interface, using this as your example:
coder.typeof(0,[2560,1920],1)
Another alternative is to use the 64-bit version of MATLAB.
-John
  1 commentaire
Ryan Johnson
Ryan Johnson le 1 Août 2012
Based on your suggestion to be variable sized, I tried the infinite sized input variables, rather than the size limited input variables and everything appears to be working. Thank you.

Connectez-vous pour commenter.

Catégories

En savoir plus sur MATLAB Algorithm Acceleration dans Help Center et File Exchange

Produits

Community Treasure Hunt

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

Start Hunting!

Translated by