From: Etienne on 20 Feb 2010 05:56 Hi folks I am trying to speed up a mex file and have found that the bottleneck seems to be a mexCallMATLAB statement that calls a matlab function. The question is if the use of function handles could speed this up, and if so, ho would you do this? When I create a function handle such as h=(a)func How do I send this via the mexCallMATLAB function? 1. Is it mexCallMATLAB(nlhs, plhs, nrhs, prhs, h)? or 2. Is it mexCallMATLAB(nlhs, plhs, nrhs, prhs, 'h')? or 3. Is it mexCallMATLAB(nlhs, plhs, nrhs, prhs, '@func')? or 4. Is it mexCallMATLAB(nlhs, plhs, nrhs, prhs, @func)? Thanks in advance Etienne
From: Rune Allnor on 20 Feb 2010 06:09 On 20 Feb, 11:56, "Etienne" <etienne.coet...(a)airbus.com> wrote: > Hi folks > > I am trying to speed up a mex file and have found that the bottleneck seems to be a mexCallMATLAB statement that calls a matlab function. The question is if the use of function handles could speed this up, No. There is no point trying to speed up matlab by calling matlab from a mex file. The overhead by calling matlab functions from the mex file is far worse than whatever loop overhead you attempt to get rid of directly in matlab domain. If you want speed, do *everything* in the mex file. Rune
From: Etienne on 20 Feb 2010 10:10 Rune Allnor <allnor(a)tele.ntnu.no> wrote in message <c2ad4034-6c64-4ea0-bf98-6c5b989d42b2(a)f15g2000yqe.googlegroups.com>... > On 20 Feb, 11:56, "Etienne" <etienne.coet...(a)airbus.com> wrote: > > Hi folks > > > > I am trying to speed up a mex file and have found that the bottleneck seems to be a mexCallMATLAB statement that calls a matlab function. The question is if the use of function handles could speed this up, > > No. > > There is no point trying to speed up matlab by calling > matlab from a mex file. The overhead by calling matlab > functions from the mex file is far worse than whatever > loop overhead you attempt to get rid of directly in > matlab domain. > > If you want speed, do *everything* in the mex file. > > Rune Hi Rune The problem is that I am calling state derivatives from a simulink model, hence the need for calling matlab. Etienne
From: Bruno Luong on 20 Feb 2010 10:16 Etienne, if you need to call a function handle from MEX, use mexCallMATLAB with FEVAL. Bruno
From: Etienne on 22 Feb 2010 12:53 "Bruno Luong" <b.luong(a)fogale.findmycountry> wrote in message <hloubj$b12$1(a)fred.mathworks.com>... > Etienne, if you need to call a function handle from MEX, use mexCallMATLAB with FEVAL. > > Bruno Hi Bruno I have tried the code below, but the syntax I am using seems to be a problem. I am not sure what I am doing wrong. Do you maybe have an example? This relates back to my orginal post. What syntax would you use to send a handle through a mex file? Regards Etienne C============================================ FSTR='@FUN' PRHS(1) = mxCreateString(FSTR) CALL mxCopyCharacterToPtr(FSTR, PRHS(1), 4) C Define the dimensions of states in MATLAB environment C NDM = NDIM PRHS(2) = MXCREATEDOUBLEMATRIX(1,1,MXREAL) CALL MXCOPYREAL8TOPTR(NDM,MXGETPR(PRHS(2)),1) C C Define the state variable in MATLAB environment C PRHS(3) = MXCREATEDOUBLEMATRIX(NDIM,1,MXREAL) CALL MXCOPYREAL8TOPTR(U,MXGETPR(PRHS(3)),NDIM) C C Define the parameter variable in MATLAB environment C PRHS(4) = MXCREATEDOUBLEMATRIX(NPARX,1,MXREAL) CALL MXCOPYREAL8TOPTR(PAR,MXGETPR(PRHS(4)),NPARX) C C Call the m-file AUTOEQN for derivatives C K = MEXCALLMATLABWITHTRAP(2,PLHS,4,PRHS,"feval")
|
Next
|
Last
Pages: 1 2 3 Prev: out of memory, memory problem in large matrix Next: Hidden object properties in mex file |