add numba example

This commit is contained in:
2026-11-28 10:07:24 +03:00
parent 0dee27cfed
commit 72c43268ad
+15
View File
@@ -0,0 +1,15 @@
from numba import cuda
@cuda.jit
def heat_step(u, v):
j, i = cuda.grid(2) # x → столбец j, y → строка i
if 1 <= i < u.shape[0] - 1 and 1 <= j < u.shape[1] - 1:
v[i, j] = 0.25 * (u[i - 1, j] + u[i + 1, j]
+ u[i, j - 1] + u[i, j + 1])
threads = (16, 16)
blocks = ((u.shape[1] + 15) // 16, (u.shape[0] + 15) // 16)
d_u = cuda.to_device(u)
d_v = cuda.to_device(u) # границы уже равны u
heat_step[blocks, threads](d_u, d_v)
cuda.synchronize()