Commit 77dcdf60 authored by ulrich_y's avatar ulrich_y

Added MPL caching system

This is currently disabled. There is no real point
here, it's fast either way.
parent 97358215
......@@ -4,6 +4,18 @@ MODULE mpl_module
use ieps
implicit none
#ifdef MPL_CACHE
! Max weight, no. cache
integer,parameter :: cachesize(2) = (/ 4, 2500 /)
type el
integer :: m(cachesize(1))
complex(kind=prec) :: c(cachesize(1))
complex(kind=prec) :: ans
end type el
type(el) cache(cachesize(1),abs(cachesize(2)))
integer cacheind(cachesize(1))
#endif
CONTAINS
FUNCTION MPL_converges(m,x)
......@@ -19,12 +31,42 @@ CONTAINS
end if
END FUNCTION MPL_converges
#ifdef MPL_CACHE
FUNCTION CHECK_CACHE(m, x, res)
integer m(:)
complex(kind=prec) :: x(:), res
logical check_cache
integer k, j, i
j = size(x)
if (j<=4) then
do k=1,cacheind(j)
if (all(cache(j,k)%m(:j) == m)) then
do i=1,j
if( abs(cache(j,k)%c(i)-x(i)).gt.zero ) goto 123
enddo
res = cache(j,k) % ans
check_cache = .true.
return
endif
123 continue
enddo
endif
check_cache = .false.
END FUNCTION
#endif
FUNCTION MPL(m, x) result(res)
integer :: m(:)
complex(kind=prec) :: x(:)
complex(kind=prec) :: res
complex(kind=prec) :: t(size(x))
integer :: q, j, k
#ifdef MPL_CACHE
if (check_cache(m,x,res)) return
#endif
j = size(x)
......@@ -49,6 +91,18 @@ CONTAINS
res = t(1)
#ifdef MPL_CACHE
if (j<=cachesize(1)) then
if (cacheind(j)+1 > abs(cachesize(2))) then
if (cachesize(2) < 0) print*,"MPL cache for depth=",j," is full. Try increasing cachesize(2)"
return
endif
cacheind(j) = cacheind(j) + 1
cache(j,cacheind(j)) = el( reshape(m, (/cachesize(1)/), pad=[ 0 ]), &
reshape(x, (/cachesize(1)/), pad=[cmplx(0.)]), &
res )
endif
#endif
END FUNCTION MPL
END MODULE mpl_module
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment