debug模式下与正常模式运算结果不一样

我在尝试编写一个简单的二维随机游走模拟,但是在不用debug的情况下代码会输出完全错误的结果,使用debug才是预期值,而且没有任何警告或提示,现在我完全不知道哪里出了问题,希望大佬们可以帮忙看看qwq

import taichi as ti
from matplotlib import pyplot as plt
import numpy as np
num=1000
xmax=10000
ti.init(arch=ti.gpu)
temp=ti.Vector.field(n=2, dtype=int, shape=(xmax+1, num))
back2zero=ti.field(shape=(xmax+1),dtype=float)
first_back2zero=ti.field(shape=(xmax+1,num),dtype=float)
test=ti.Vector([0,1])
length=ti.field(shape=(xmax+1),dtype=float)
@ti.kernel
def compute():
temp.fill(0)
back2zero.fill(0)
first_back2zero.fill(0)

for x in range(10,xmax+1):
    for i in range(num):
        for j in range(x):
            r1,r2= abs(ti.random(ti.i32)%2), abs(ti.random(ti.i32)%2)
            temp[x,i][r1]+=2*r2-1
            if (temp[x,i][0]==0) and (temp[x,i][1]==0):
                back2zero[x]+=1
                if first_back2zero[x,i]==0:
                    first_back2zero[x,i]=j+1
for x in range(10,xmax+1):
    back2zero[x]/=num
for x in range(10,xmax+1):
    for i in range(num):
        first_back2zero[x,0]+=first_back2zero[x,i]
    first_back2zero[x,0]/=num
for x in range(10,xmax+1):
    for i in range(num):
        length[x]+=(temp[x,i][0]**2+temp[x,i][1]**2)**0.5
    length[x]/=num

compute()
plt.plot(range(10,xmax+1),length.to_numpy()[10:])
plt.plot(range(10,xmax+1),back2zero.to_numpy()[10:])
plt.plot(range(10,xmax+1),first_back2zero.to_numpy()[10:,0])
plt.show()

用cpu是正常的,只有在gpu情况下才会出现这种奇怪问题

你可以排版一下你的代码吗?现在的格式别人不方便阅读。

import taichi as ti
from matplotlib import pyplot as plt
import numpy as np
num=20
xmax=10000
ti.init(arch=ti.gpu)
temp=ti.Vector.field(n=2, dtype=int, shape=(xmax+1, num))
back2zero=ti.field(shape=(xmax+1),dtype=float)
first_back2zero=ti.field(shape=(xmax+1,num),dtype=float)
test=ti.Vector([0,1])
length=ti.field(shape=(xmax+1),dtype=float)
@ti.kernel
def compute():
    temp.fill(0)
    back2zero.fill(0)
    first_back2zero.fill(0)

    for x in range(10,xmax+1):
        for i in range(num):
            for j in range(x):
                r1,r2= abs(ti.random(ti.i32)%2), abs(ti.random(ti.i32)%2)
                temp[x,i][r1]+=2*r2-1
                if (temp[x,i][0]==0) and (temp[x,i][1]==0):
                    back2zero[x]+=1
                    if first_back2zero[x,i]==0:
                        first_back2zero[x,i]=j+1
    for x in range(10,xmax+1):
        back2zero[x]/=num
    for x in range(10,xmax+1):
        for i in range(num):
            first_back2zero[x,0]+=first_back2zero[x,i]
        first_back2zero[x,0]/=num
    for x in range(10,xmax+1):
        for i in range(num):
            length[x]+=(temp[x,i][0]**2+temp[x,i][1]**2)**0.5
        length[x]/=num


compute()
plt.plot(range(10,xmax+1),length.to_numpy()[10:])
plt.plot(range(10,xmax+1),back2zero.to_numpy()[10:])
plt.plot(range(10,xmax+1),first_back2zero.to_numpy()[10:,0])
plt.show()

非常抱歉不太熟悉怎么帖代码()