[Matrix-SIG] Fortran to Python Interface Generator
Pearu Peterson
pearu@ioc.ee
Mon, 12 Jul 1999 16:44:58 +0300 (EETDST)
Travis and others interested in doing fast math in Python:
Now I have a first working alpha version of f2py.py --- a Fortran to
Python Interface Generator.
Travis: you can checkout f2py.py from the CVS server under module named
f2py.
I think you will be interested in the test results below.
For a first test I took ddot.f --- it contains Level 1 BLAS function ddot
for finding a dot product of two vectors.
Now
> f2py.py -mblas tests/ddot.f
will create a file blasmodule.c, that is a Python-C API module and can be
compiled in a standard way.
Below you will find two sets of test results. One uses standard BLAS
library and the other optimized BLAS library for Intel. In both cases
comparison is carried out against Numeric function Numeric.dot.
In all test cases 10 000 iterations were made.
These tests show that blas.ddot is approx 80% faster than Numeric.dot for
small length vectors (length<=500). For standard BLAS the difference
decreases approx to 60% for vectors having length of few thousand. And
then rapidly decreases to 14% (to be still faster) for vectors with
a length of 10 thousand.
But note that when using optimized BLAS this rapid decrease is not
happening: blas.ddot will remain to be more than 50% faster than
Numeric.dot for very lengthy vectors.
Pearu
********* Standard BLAS **********
> python test.py
retval = _ddot(n,dx,incx,dy,incy)
Numeric.dot(x,y)= 249.301376637
blas.ddot(x,y)= 249.301376637
Length of vectors = 10
Numeric.dot: 1.0199 seconds
blas.ddot: 0.1447 seconds
blas.ddot is 85.81% faster.
Length of vectors = 50
Numeric.dot: 0.858 seconds
blas.ddot: 0.1546 seconds
blas.ddot is 81.98% faster.
Length of vectors = 100
Numeric.dot: 0.892 seconds
blas.ddot: 0.1685 seconds
blas.ddot is 81.11% faster.
Length of vectors = 500
Numeric.dot: 1.0237 seconds
blas.ddot: 0.2575 seconds
blas.ddot is 74.85% faster.
Length of vectors = 1000
Numeric.dot: 1.3121 seconds
blas.ddot: 0.4935 seconds
blas.ddot is 62.39% faster.
Length of vectors = 5000
Numeric.dot: 2.2982 seconds
blas.ddot: 1.8268 seconds
blas.ddot is 20.51% faster.
Length of vectors = 10000
Numeric.dot: 4.4357 seconds
blas.ddot: 3.8062 seconds
blas.ddot is 14.19% faster.
*********** Optimized BLAS ***********
> python test.py
retval = _ddot(n,dx,incx,dy,incy)
Numeric.dot(x,y)= 254.269018269
blas.ddot(x,y)= 254.269018269
Length of vectors = 10
Numeric.dot: 0.872 seconds
blas.ddot: 0.1411 seconds
blas.ddot is 83.81% faster.
Length of vectors = 50
Numeric.dot: 0.8596 seconds
blas.ddot: 0.1471 seconds
blas.ddot is 82.89% faster.
Length of vectors = 100
Numeric.dot: 0.893 seconds
blas.ddot: 0.1559 seconds
blas.ddot is 82.55% faster.
Length of vectors = 500
Numeric.dot: 1.0232 seconds
blas.ddot: 0.2043 seconds
blas.ddot is 80.03% faster.
Length of vectors = 1000
Numeric.dot: 1.2427 seconds
blas.ddot: 0.3484 seconds
blas.ddot is 71.97% faster.
Length of vectors = 5000
Numeric.dot: 2.275 seconds
blas.ddot: 1.0139 seconds
blas.ddot is 55.43% faster.
Length of vectors = 10000
Numeric.dot: 4.2813 seconds
blas.ddot: 2.0242 seconds
blas.ddot is 52.72% faster.