Reputation: 111
This is more of a design question. I am involved with a project that requires us to solve a bunch of first order differential equations. I know the python has modules to this and we have been using those functions.
However, we need the integrator to be fast, so we want to use adaptive step sizes and test some other routines not included in the scipy packages. To that end, I had a f2py question since it seems to make sense to write the ODE solver in fortran or C, and wrap it using f2py. Where does the 'slow down' occur in interfacing between fortran, for example, and python? Is it in transferring memory back and forth? I am wondering what I need to consider at the front end. Of course, I could write this directly in python (for starters), but I have heard that looping in python is very slow.
Anyway, just looking for general advice and things to consider.
Thank you.
Upvotes: 0
Views: 358
Reputation: 1355
I'm not familiar with f2py, but have you considered trying Cython first? If you're not familiar with it, it lets you write code in a superset of the standard Python language, and then it translates that into C code which is then compiled. If your code is mostly loops, this might speed it up quite a bit. Keep in mind, though, that any time you call a pure Python function from within Cython (or from regular C code, for that matter) it will create a bottleneck. (I believe that this is the slowdown you were referring to.)
That being said, I recently threw out a Cython module I'd written and replaced it with a hand-written C++ library using the Python/C API. This was better since it gave me more control over the C++ code's interaction with NumPy, which was a bit challenging with Cython.
Upvotes: 1