[Numpy-discussion] ising model: f2py vs cython comparison

Ondrej Certik ondrej@certik...
Sat Dec 22 19:32:54 CST 2007


On Dec 23, 2007 2:29 AM, Ondrej Certik <ondrej@certik.cz> wrote:
> Hi,
>
> I need to write 2D Ising model simulation into my school, so I wrote
> it in Python, then rewrote it in Fortran + f2py, and also Cython:
>
> http://hg.sharesource.org/isingmodel/
>
> And Cython solution is 2x faster than f2py. I understand, that I am
> comparing many things - wrappers, my fortran coding skills
> vs Cython C code generation and gcc vs gfortran. But still any ideas
> how to speed up fortran+f2py solution is very welcomed.
>
> How to play with that - just do this (after installing Mercurial):
>
> $ hg clone http://hg.sharesource.org/isingmodel/
> [...]
> $ hg up db7dd01cdc26                                 # just to be sure
> that we are talking about the same revision / code
> $ cd isingmodel

The last two lines should have been interchanged of course:

$ cd isingmodel
$ hg up db7dd01cdc26

Also you may want to edit the Makefile:

all:
	f2py --fcompiler=gnu95 --f77flags="-W -Wall -fdefault-real-8" -c -m
mcising mcising.f
	cython pyising.pyx
	gcc -fPIC -O3 -I/usr/include/python2.4/
-I/usr/share/python-support/python-numpy/numpy/core/include/numpy/ -c
-o pyising.o pyising.c
	gcc -shared pyising.o -o pyising.so


Especially the include path to numpy/*.h files.

Ondrej


More information about the Numpy-discussion mailing list