Re: [SciPy-User] help speeding up a Runge-Kuta algorithm (cython, f2py, ...)
I am sure properly coded Cython is great, but I really struggled when I tried to use it. I found that it allows you to write really slow code without errors or warnings. I found the profiling tools to be only marginally helpful. So many different ways to do the same thing... which is the best? All the documentation is nice, but very long and dense. I am having much more success with f2py (using F90 syntax). Either your code runs fast, or it simply will not compile (excepting segfault bugs that can sometimes be difficult to track down). Improved and updated documentation would be helpful, but otherwise f2py is now what I turn to when speed is crucial. My 2 cents. YMMV. Jonathan On 08/04/2012 02:45 AM, scipy-user-request@scipy.org wrote:
Date: Sat, 04 Aug 2012 03:03:38 +0200 From: Sturla Molden Subject: Re: [SciPy-User] help speeding up a Runge-Kuta algorithm (cython, f2py, ...)
Den 03.08.2012 21:05, skrev Pauli Virtanen:
It's Fortran 77. You need to declare
double precision dzdt
I'd suggest writing Fortran 90 --- no need to bring more F77 code into existence;)
With the new typed memoryviews in Cython, there is no need to bring more Fortran of any sort into existance.;-)
Den 04.08.2012 21:35, skrev Jonathan Stickel:
I am sure properly coded Cython is great, but I really struggled when I tried to use it.
I uses np.ndarray declarations and array expressions. Those will be slow. To write fast and numpyonic Cython, use typed memoryviews instead, and write out all loops. I.e. there is no support for array expressions with these yet. And unfortunately there is a huge lack of documentation on how to use typed memoryviews efficiently. Here is an example code of how to use Cython as a Fortran killer: https://github.com/sturlamolden/memview_benchmarks/blob/master/memview.pyx In this case, the performance with -O2 was just 2.2% slower than "plain C" with pointer arithmetics. It is possible to write very fast array code with Cython, but you must do it right. For comparison, this is very slow: https://github.com/sturlamolden/memview_benchmarks/blob/master/cythonized_nu... What this mean is this: For anything but trivial code, the NumPy syntax is just too slow and should be avoided! I breiefly looked at the Cython code posted in this thread, and it suffers form all these issues. Sturla
On Sat, Aug 04, 2012 at 01:35:17PM -0600, Jonathan Stickel wrote:
I am sure properly coded Cython is great, but I really struggled when I tried to use it. I found that it allows you to write really slow code without errors or warnings. I found the profiling tools to be only marginally helpful.
To write fast cython code, compile it with 'cython -a', open the resulting html file in a web browser. The yellow lines are where the problems are: click on them and you'll find that they correspond to lines of Cython code that lead to long and complex C code. Improve your code (by making sure that it relies on typed variables and fast array access) until it has not yellow lines. HTH, Gael
participants (3)
-
Gael Varoquaux -
Jonathan Stickel -
Sturla Molden