Editing code for mex function to support 64 bit indexing

2 ビュー (過去 30 日間)
Marc Laub
Marc Laub 2021 年 1 月 15 日
コメント済み: Marc Laub 2021 年 1 月 17 日
I want to speed up my code by using a mex function, I actually already did but the probem is that MatLab coder only supports 32bit indexing and when my function input gets to large, MatLab crashes.
I already tried:
but this doesnt help me because the topic is about what to change when a matrix that needs more than 32 bit indexing is created in the mex function.
In my case the matrix is generated in MatLab and given to the mex function, which gives some outputs. The same matrix can change its size in MatLab and it is returned to the mex function repeatedly.
I wrote some minimal working code to illustrade the problem:
while length(flashyarrayname)<46342
[flashyarrayname2]=testfunction1(flashymatrixname, flashyarrayname,flashyconstname);
function [flashyarrayname2]=testfunction1(flashymatrixname, flashyarrayname,flashyconstname)
parfor i=1:length(flashyarrayname)
function [some_value]=testfunction2(tempvar1,tempvar2,flashyconstname)
I generted a mex function form testfunction1 with MatLab Coder and it reproduces the error.
I than searched all files in the codegen/mex/testfunction1 folder and subfolders for the flashy names of the matrix and the array according to the link above.
The problem was that I cant find where the matrix size is explicitly declared so I could change it, the size must be somehow given by matlab. In the coder_test_api.cpp are declarations such as:
static void emlrt_marshallIn(const emlrtStack *sp, const mxArray *flashymatrixname, const char_T *identifier, coder::array<boolean_T, 2U> &y)
so somehow the size which is limited to 32 bit indexing and which I need to change is somehow overgiven by " *flashymatrixname" and I dont know how to change it, since the workaround from the link with replacing Int_32 by mwsize does not apply, since its not declared.
So maybe somebody could help me with this. It would also bee important in what kind of files I would need t replace such declaration, I guess i should only change it in the files that Coder created and not in some other files that Coder needs also, like some library headers or so....
Many Thanks in advance,
Best regards
  2 件のコメント
Marc Laub
Marc Laub 2021 年 1 月 17 日
The only bibraries I use for compiling are mathutil and emlrt, so just to understand you correct, I would need those libraries 64bit based, otherwise my plan fails at this point already? People that write 64bit mex functions on there own without coder use those libraries instead of the ones Coder uses in the MatLabroot\version\extern\lib ?
The mex with open mp gives a speedup by a factor of 20-30. I'll try to chunk the problematic boolean matrix into pieces, each one indexable with 32bit, and hope that the chunking does not cost more time than mex gives me.


回答 (0 件)


Find more on MATLAB Code Analysis in Help Center and File Exchange




Community Treasure Hunt

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

Start Hunting!

Translated by