关于高斯消元法求线形方程组问题

先贴代码。。。这是一个按列分配thread的用高斯消元法解线形方程组的代码


//kernel函数 matrixHeight=matrixWidth
__global__ static void reduceLine3(float *matrix,int Pos)
{
__shared__ float temp[matrixHeight];
int tid=blockDim.x*blockIdx.x+threadIdx.x;
if(tid<matrixHeight)
{
  temp[tid]=matrix[tid*(matrixWidth+1)+Pos]/matrix[Pos*(matrixWidth+1)+Pos];
}
if(Pos==tid)
{
  temp[tid]=0.0;
}
__syncthreads();
if(tid<matrixWidth+1-Pos)
{
  float postemp=matrix[Pos*(matrixWidth+1)+Pos+tid];
  for(int i=0;i<matrixHeight;i++)
  {
   matrix[i*(matrixWidth+1)+Pos+tid]-=temp[i]*postemp;
  }
}
}
//主机端调用部分,d_matrix已经传到global memory了,是Ax=b的系数矩阵
for(int i=0;i<matrixHeight;i++)
{
  reduceLine3<<<(matrixHeight+blockSize-1)/blockSize,blockSize>>>(d_matrix,i);
}

在运行只有一个block(thread数小于512)的情况下答案是正确的。
索引越界什么的都检查过了,不知道为什么用2个block的时候就出错了,跪求大神前来解释。。。。。
同时求一个更好版本的高斯消元解线形方程组kernel学习下。