help-octave
[Top][All Lists]
Advanced

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

Re: An example of poor C++ performance


From: Steve C. Thompson
Subject: Re: An example of poor C++ performance
Date: Wed, 23 Feb 2005 15:08:55 -0800
User-agent: Mutt/1.3.28i

Todd,

Thanks for looking at this.

If the m-file was to be written with randn(1) it wouldn't be vectorized
and would run very slow.

It sounds like you are suggesting that the C++ code needs to be
vectorized.  But isn't this a compounded hassle?  I thought that C++
code was just supposed to be ``fast''!

Has anyone had experience using generators from this page:

http://www.agner.org/random/

Steve


On Feb 23 16:13PM, Todd Neal wrote:
> Steve C. Thompson wrote:
> >Hello Group,
> >
> >My previous posts have been leading up to this.  I have successfully 
> >converted my m-file simulation code to C++, which can then be loaded
> >as an .oct module.  To test speed improvements, I've made a simple
> >example comparing the simulation with two approaches:
> >
> >1) pure m-file (vectorized) 2) m-file/C++ hybrid
> >
> >Each approach generates about 1e9 random numbers.  The pure m-file is
> > vectorized by crunching numbers in 1e4 blocks (which I've found to
> >be optimum on my machine).  However, over 50,000 loops are required.
> >The hybrid m-file/C++ diverts the looping C++.
> 
> I may be wrong, but I think that the problem is that the comparison is
> not quite valid.  randn() is called as randn(1,v) , with v being 10000.
>  This appears to call octave_rand::nd_array which runs in a tight loop
> calling a Fortran function and filling the array.
> 
> 
> >This approach only has 46 m-file loops and the rest is done in the
> >compiled module.  For each C++ loop a couple random number are
> >generated with the command octave_rand::scalar().
> >
> >I was expecting C++ implementation to outperform the pure m-file 
> >approach, but this isn't the case.
> >
> 
> The C++ version doesn't take advantage of octave_rand::nd_array and
> instead calls octave_rand::scalar which as I detailed in an earlier
> email calls maybe_initialize() which checks a flag, and then calls the
> Fortran function.  You get many more function calls and returns this way
> including redundant calls to maybe_initialize().
> 
> I haven't tested this theory but if you wrote the m-file program in the
> same way, calling rand(1) for each pseudo-random number needed, it would
> probably take much more time than the C++ program.
> 
> Todd
> 
> 
> 
> -------------------------------------------------------------
> Octave is freely available under the terms of the GNU GPL.
> 
> Octave's home on the web:  http://www.octave.org
> How to fund new projects:  http://www.octave.org/funding.html
> Subscription information:  http://www.octave.org/archive.html
> -------------------------------------------------------------
> 



-------------------------------------------------------------
Octave is freely available under the terms of the GNU GPL.

Octave's home on the web:  http://www.octave.org
How to fund new projects:  http://www.octave.org/funding.html
Subscription information:  http://www.octave.org/archive.html
-------------------------------------------------------------



reply via email to

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