Reputation: 351
I'm using numba to speed up functions including many for loops. Than they are called in outside for loop.
One of the functions evaluates differently to not jited one when called in loop.
The function:
def collison(u, v, f, feq, omega, w, cx, cy, n, m):
for i in range(0, n):
for j in range(0, n):
t1 = u[i,j]*u[i,j] + v[i,j]*v[i,j]
for k in range(9):
t2 = u[i,j]*cx[k] + v[i,j]*cy[k]
feq[k,i,j] = rho[i,j]*w[k]*(1. + 3.*t2 + 4.5*t2**2 - 1.5*t1)
f[k,i,j] = omega*feq[k, i, j] + (1. - omega)*f[k, i, j]
return f
u
, v
- ndarray n x m
f
, feq
- ndarray 9 x n x m
I just add decorator: @nb.jit(nopython=True)
before declaration
The loop:
for tstep in range(mstep):
fk = collison(u, v, fw, feq, omega, w, cx, cy, n, m)
fs = stream(fk, n, m)
fw = wbrzeg(fs, n, m, u0)
rho, u, v = rhouv(fw, rho, u, v, cx, cy, n, m)
Could it be that fw
is not being updated when collision
is called ?
Upvotes: 2
Views: 87
Reputation:
In the jitted function rho
is taken as constant at the moment Numba compiles the function. This is different from the non-jitted function that always considers the updated rho
.
See this entry in the Numba FAQ.
Upvotes: 3
Reputation: 12187
I'm not exactly sure what you're trying to do here, but in the tstep loop, fw should be changed by collision, but it's never actually USED until after it's changed again by wbrzeg (whatever that is). So, in your code, it doesn't actually MATTER if fw is being updated by collision...
It's possible that this is just a typeo in your example somewhere, but fixing that might help someone who actually understands your problem (ie not me)...
Upvotes: 0