From help-request at octave dot org Fri Feb 18 14:11:05 2005 Subject: Re: C++ using Octave headers, mkoctfile From: Przemek Klosowski To: help at octave dot org, sct@ucsd.edu Date: Fri, 18 Feb 2005 15:16:09 -0500 (EST) Francesco said > Perhaps, before trying to produce C++ code, you should try to learn how > to use Octave's vector abilities at their best. For example, the code > you wrote can be vectorialised as: > > N=30; W=exp(j*2*pi*[0:N-1]'*[1:N]/N); > > and it runs faster. You are absolutely correct. But this code snippet was to serve as an example only. Let me simplify the question: Francesco's point may have been obscured by his wording--so at a risk of restating the obvious, I would like to observe this: on vectorized code, octave takes a small interpretation hit when parsing the vector statement, and then it dives into usually well-optimized execution loop, often simply passing into super-optimized basic linear algebra library routines. The consequence of that is that hand-written C++ code might end up being slower than a vectorized Octave statement---I will tip my hat to anyone who can sit down and write competitive matrix multiplication code in C++ that would outrun Atlas. I am not saying it's impossible, just unlikely; after all, Atlas is known to be sometimes faster than vendor libraries. I think that for optimization, the recommended course is to vectorize the heck out of it, before rewriting. When rewriting, vectorization should be actually helpful in writing concise and fast code. I am reminded of those two rules of optimization that I have seen somewhere: Rule 1: don't Rule 2: not yet ------------------------------------------------------------- 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 -------------------------------------------------------------