agrobta.blogg.se

Gauss seidel python code
Gauss seidel python code








gauss seidel python code

In particular, is well suited to compile numpy expressions, like the offending line, into fast code. There are several tools to speed code up in numpy (Cython, numexpr, weave.). It turned out that over 80% of the time was spent in the line that does "internal updates".Ĭhoose a way to optimise it. I profiled the code using line_profiler from the IPython console to find the lines that took most time. I've been able to reduce the running time in my laptop from 66 to 21 seconds by following this process:įind the bottleneck. I tried the solution from the previous question, changing v to a column-major order array, but there was no performance increase.Įdit: The Matlab code for reference is: % geometry 9s simulation times respectively in Numpy and MATLAB). The speed drawbacks in Numpy are more pronounced for the full version (17s vs. The full algorithm uses successive overrelaxation and a checkerboard iteration scheme to improve speed and remove solver directionality, but for purposes of simplicity I provided this easier to understand version. This is actually not the full algorithm which I use. It finishes when the maximum difference between updates on the mesh is less than the indicated tolerance. The algorithm simply solves the discretized Laplace equation on a rectangular mesh (in cylindrical coordinates). I would like to use Numpy, however, since this code is part of a larger program, the almost twice as long simulation time is a significant drawback. The Matlab code runs in ~20 s whereas the Numpy codes takes ~30 s. The code was originally written in MATLAB and then transferred to Python. I currently have a Gauss-Seidel solver implemented in both MATLAB and Numpy which acts on a 2D axisymmetric domain (cylindrical coordinates).

gauss seidel python code gauss seidel python code

This question is a follow-up to a recent question posted regarding MATLAB being twice as fast as Numpy.










Gauss seidel python code