[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [slightly OT]: Octave featured in Free Software magazine
From: |
Alexander Barth |
Subject: |
Re: [slightly OT]: Octave featured in Free Software magazine |
Date: |
Tue, 05 Jun 2007 15:06:25 -0400 |
User-agent: |
Thunderbird 1.5.0.10 (X11/20070301) |
Hi Jordi,
Thank you for pointing this benchmark out.
Octave's speed can be improved quite significantly if lines like:
qgtfive= find(qRe > 5.);
zRe(qgtfive)=5.;
are replaced by:
zRe(qRe > 5.)=5.;
The code is also much clearer this way.
On my machine (AMD Opteron 244):
octave:1> tic; fractal_benchmark; toc
Elapsed time is 24.935944 seconds.
octave:2> tic; fractal_benchmark2; toc
Elapsed time is 14.843300 seconds.
In addition to this, the complex type can be used instead of real and imaginary
part separately.
Alex
Jordi Gutierrez Hermoso wrote:
> This isn't a question about help, but it's nice to see that Octave got
> mentioned in Free Software Magazine and was quite favourably compared
> as "an almost perfect clone of MATLAB."
>
> http://www.freesoftwaremagazine.com/articles/cool_fractals_with_perl_pdl_a_benchmark?page=0%2C4
>
> The code provided in the page, written somewhat in a Matlab-style,
> works in 2.9.12. Unfortunately, Octave was also the slowest one to
> generate a Mandelbro fractal, at least with the given code:
>
>
> http://www.freesoftwaremagazine.com/articles/cool_fractals_with_perl_pdl_a_benchmark?page=0%2C6
>
> I haven't grokked the code yet, but I do wonder if it's possible to
> vectorise that for-loop out... I doubt it, though. Loops that use the
> information from the previous iteration for the next iteration are the
> one kind of loop I have never been able to vectorise out.
>
> Hope this was interesting.
>
> - Jordi G. H.
> _______________________________________________
> Help-octave mailing list
> address@hidden
> https://www.cae.wisc.edu/mailman/listinfo/help-octave
>
--
_______________________________________________________________
Alexander Barth
Ocean Circulation Group
University of South Florida
College of Marine Science
140 Seventh Avenue South
St. Petersburg, Florida 33701
USA
Phone: +1-727-553-3508 FAX: +1-727-553-1189
_______________________________________________________________
% MATLAB and Octave code to generate a Mandelbrot fractal
% Number of points in side of image and
% number of iterations in the Mandelbrot
% fractal calculation
npts=1000;
niter=51;
% Generating z = 0 (real and
% imaginary part)
zRe=zeros(npts,npts);
zIm=zeros(npts,npts);
% Generating the constant k (real and
% imaginary part)
kRe=repmat(linspace(-1.5,0.5,npts),npts,1);
kIm=repmat(linspace(-1,1,npts)',1,npts);
% Iterating
for j=1:niter
% Calculating q = z*z + k in complex space
% q is a temporary variable to store the result
qRe=zRe.*zRe-zIm.*zIm+kRe;
qIm=2.*zRe.*zIm+kIm;
% Assigning the q values to z constraining between
% -5 and 5 to avoid numerical divergences
zRe=qRe;
qgtfive= find(qRe > 5.);
zRe(qgtfive)=5.;
qltmfive=find(qRe<-5.);
zRe(qltmfive)=-5.;
zIm=qIm;
hgtfive=find(qIm>5.);
zIm(hgtfive)=5.;
hltmfive=find(qIm<-5.);
zIm(hltmfive)=-5.;
end
% MATLAB and Octave code to generate a Mandelbrot fractal
% Number of points in side of image and
% number of iterations in the Mandelbrot
% fractal calculation
npts=1000;
niter=51;
% Generating z = 0 (real and
% imaginary part)
zRe=zeros(npts,npts);
zIm=zeros(npts,npts);
% Generating the constant k (real and
% imaginary part)
kRe=repmat(linspace(-1.5,0.5,npts),npts,1);
kIm=repmat(linspace(-1,1,npts)',1,npts);
% Iterating
for j=1:niter
% Calculating q = z*z + k in complex space
% q is a temporary variable to store the result
qRe=zRe.*zRe-zIm.*zIm+kRe;
qIm=2.*zRe.*zIm+kIm;
% Assigning the q values to z constraining between
% -5 and 5 to avoid numerical divergences
zRe=qRe;
zRe(qRe > 5.)=5.;
zRe(qRe<-5.)=-5.;
zIm=qIm;
zIm(qIm>5.)=5.;
zIm(qIm<-5.)=-5.;
end