help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: HELP with octave-to-cpp conversion


From: Francesco Potortì
Subject: Re: HELP with octave-to-cpp conversion
Date: Wed, 23 Feb 2011 11:02:58 +0100

>I was wondering if there is any good soul out there willing to help me
>converting this function into C++, which, if I understood right should speed
>up the execution of the function.
[...]
>function qc_acs=Qc_acs(D, lambda_vac, cost)
>
>    global theta x Qscat S11 sin_theta theta0_acs 
>
>    lambda=lambda_vac/1000/1.339;    % [um]  
>    XX=D*pi/lambda;
>    [m n]=size(XX);
>     
>    fm=find(x>max(XX),1);
>
>    Qc = interp1( x(1:fm), Qscat(1:fm), XX, 1);
>    S_11 = interp1( x(1:fm), S11(1:fm,:), XX, 1);  
>     S_11_sin_theta= 2*pi*S_11'.*sin_theta; 
>     S11_fwd_ACs=trapz(theta(theta0_acs:end,:), S_11_sin_theta(
>theta0_acs:end,:))';
>
>    qc_acs=Qc.*S11_fwd_ACs;
>
>endfunction

I have some experience in optimising Octave functions, but I never
resorted to C++.  In your case, I fear that going to C++ at this stage
would buy you little advantage, as most probably the problem is not in
the function itself, but in those called from it: interp1 and trapz.

So the first thing to do is trying to avoid the calls and do the work
inside the function itself, which will avoid the argument checking
overhead of those functions, and probably will also reduce them by
restricting the code to exactly what you need.  My suggestion, then, is
to try to rewrite your function by avoiding calls to interp1 and trapz.
If you don't know where to start, just try to copy code from those
functions into yours, and then try to reduce and optimise it.

-- 
Francesco Potortì (ricercatore)        Voice: +39 050 315 3058 (op.2111)
ISTI - Area della ricerca CNR          Fax:   +39 050 315 2040
via G. Moruzzi 1, I-56124 Pisa         Email: address@hidden
(entrance 20, 1st floor, room C71)     Web:   http://fly.isti.cnr.it/


reply via email to

[Prev in Thread] Current Thread [Next in Thread]