Editing code for mex function to support 64 bit indexing
3 ビュー (過去 30 日間)
表示 古いコメント
Hey,
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:
nums=46340;
flashymatrixname=false(nums);
flashymatrixname(1:nums+1:end)=true;
flashyarrayname=ones(nums,1);
flashyconstname=1;
while length(flashyarrayname)<46342
[flashyarrayname2]=testfunction1(flashymatrixname, flashyarrayname,flashyconstname);
flashymatrixname(end+1,:)=false;
flashymatrixname(:,end+1)=false;
flashymatrixname(end,end)=true;
flashyarrayname(end+1)=1;
end
function [flashyarrayname2]=testfunction1(flashymatrixname, flashyarrayname,flashyconstname)
flashyarrayname2=NaN(length(flashyarrayname),1);
parfor i=1:length(flashyarrayname)
tempvar1=flashyarrayname(flashymatrixname(:,i));
tempvar2=flashyarrayname(i);
[flashyarrayname2(i)]=testfunction2(tempvar1,tempvar2,flashyconstname);
end
end
function [some_value]=testfunction2(tempvar1,tempvar2,flashyconstname)
some_value=flashyconstname*(1/tempvar2-1./tempvar1);
end
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
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!