[SciPy-user] LU: linalg.solve vs. dgetrf/dgetrs fortran subroutines

fred fredmfp@gmail....
Mon Jul 9 13:32:12 CDT 2007


Hi,

I want to compare execution times between linalg.solve from scipy
and dgetrf/dgetrs fortran subroutines (before using cvxopt...)

Here my functions:

    def calc_KW_LU(self, KV):
        from scipy.linalg import solve
        from sys import stdout
        t0 = time.time()
        print 'Computing kriging weights (scipy LU version)...',
        stdout.flush()
        KW = solve(self.KM, KV)
        self.KW = KW[:-1].squeeze()
        print '('+str(time.time()-t0)+' s)',
        print 'done !'
        stdout.flush()


subroutine calc_KW(KW, KM, KV, nbx, nby, nbz)
  
  implicit none
  
!f2py real intent(in, out) :: KW
!f2py real*8 intent(in) :: KM, KV
!f2py integer intent(in) :: nbx, nby, nbz
  
  integer :: nbx, nby, nbz
  real :: KW((2*nbx+1)*(2*nby+1)*(2*nbz+1))
  real*8 :: KM((2*nbx+1)*(2*nby+1)*(2*nbz+1)+1, (2*nbx+1)*(2*nby+1)*(2*nbz+1)+1)
  real*8 :: KV((2*nbx+1)*(2*nby+1)*(2*nbz+1)+1)
  
  integer :: ndim
  integer :: info
  integer, dimension(:), allocatable :: ipvt
  
  ndim = (2*nbx+1)*(2*nby+1)*(2*nbz+1)+1
  
  allocate(ipvt(ndim))
  
  call dgetrf(ndim, ndim, KM, ndim, ipvt, info)
  call dgetrs('N', ndim, 1, KM, ndim, ipvt, KV, ndim, info)
  
  KW = KV(1:size(KV)-1)
  
end subroutine calc_KW

This last is called by my python method:

    def calc_KW_LU_Fmodule(self, KV):
        from scipy import float32, zeros
        from sys import stdout
        from calc_KW_LU import calc_kw
        t0 = time.time()
        nbx, nby, nbz = self.nbx, self.nby, self.nbz
        ndx, ndy, ndz = (2*nbx+1), (2*nby+1), (2*nbz+1)
        ndt = ndx*ndy*ndz
        KM, KV = self.KM, self.KV
        print 'Computing kriging weights (LU Fortran module version)...',
        stdout.flush()
        KW = zeros((ndt,1), dtype=float32)
        KW = calc_kw(KW, KM, KV, nbx, nby, nbz)
        self.KW = KW.squeeze()
        print '('+str(time.time()-t0)+' s)',
        print 'done !'
        stdout.flush()

The execution times are very different:

1) On my Core 2 Duo T7200 (i686, Debian etch):

Computing kriging weights (LU version)... (142.409274817 s) done !

Computing kriging weights (LU Fortran module version)... (157.362993002 s) done !

2) On my Pentium 930 D (x86_64, Debian etch), differences are bigger:

Computing kriging weights (LU version)... (283.214334011 s) done !

Computing kriging weights (LU Fortran module version)... (583.182439089 s) done !

Could someone give me any clues ?

TIA.


Cheers,

-- 
http://scipy.org/FredericPetit


More information about the SciPy-user mailing list