Path: news.mathworks.com!not-for-mail
From: "Titus Edelhofer" <titus.edelhofer@mathworks.de>
Newsgroups: comp.soft-sys.matlab
Subject: Re: mexCallMATLAB is slow
Date: Wed, 15 Nov 2006 10:05:07 +0100
Organization: The MathWorks, Inc.
Lines: 63
Message-ID: <ejel83$4ck$1@fred.mathworks.com>
References: <ef45ef9.-1@webcrossing.raydaftYaTP>
NNTP-Posting-Host: 172.16.75.172
X-Trace: fred.mathworks.com 1163581508 4500 172.16.75.172 (15 Nov 2006 09:05:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 15 Nov 2006 09:05:08 +0000 (UTC)
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2869
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2869
Xref: news.mathworks.com comp.soft-sys.matlab:378805



Hi,
in the mex file you shouldn't use mexCallMATLAB, but
just assign values to the array, something like

/* copy the array */
pOut[0] = mxDuplicateArray(pIn[0]);
/* get the pointer */
double *ptr = mxGetPr(pOut[0]);
/* do the assignment: */
ptr[0] = 1;

Titus

"Nikolai Yu. Zolotykh" <zny@uic.nnov.ru> schrieb im Newsbeitrag 
news:ef45ef9.-1@webcrossing.raydaftYaTP...
> mexCallMATLAB is slower.
>
> Let
> A=zeros(1000);
>
> I want to do an assignment
>
> A(1,1) = 1
>
> In MATLAB environment it requires 0.000027 seconds:
>
> tic;A(1,1)=1;toc;
> Elapsed time is 0.000027 seconds.
>
> The following mexFucntion does the same:
>
> /* myassignment.c */
> #include "mex.h"
> void mexFunction(int nOut, mxArray *pOut[],
> int nIn, const mxArray *pIn[])
> {
>  mexCallMATLAB(1, pOut, 3, pIn, "subsasgn");
> }
>
> mex myassignment.c
> A=zeros(1000);
> S.type = '()';
> S.subs = {1,1};
> A=myassignment(A, S, 1);
> A(1,1)
>
> ans =
>
>     1
>
> But now the time requiered is 0.020915 seconds:
>
> tic;A=myassignment(A, S, 1);toc;
> Elapsed time is 0.020915 seconds.
>
> It is too slow!
>
> I suppose in mexCallMATLAB MATLAB copies matrices and does not make
> the subscript assignment in-place!
>
> Any suggestions are welcome.