cuda matrix inverse gaussian jordan

后端 未结 1 1862
小蘑菇
小蘑菇 2020-12-20 06:22

I didn\'t find any similar question to mine. I\'m trying to write the gaussian-jordan inverse matrix algorithm. The idea of the algorithm is simple:)

I want to inver

相关标签:
1条回答
  • 2020-12-20 06:32

    It seems the problem was in your gaussjordan kernel.

    When you are doing gauss-jordan elimination on the original (L) matrix, it is acceptable to work only on the row elements to the right of the pivot point.

    But when you are applying the same row operations to the identity matrix to create the inverse (I), it's necessary to apply the equivalent row operations to every member of the row, not just those to the right of the pivot point.

    So if you modify your gaussjordan kernel like this:

     __global__ void gaussjordan(float *A,  float *I,int n, int i)
    {
        int x = blockIdx.x * blockDim.x + threadIdx.x;
        int y = blockIdx.y * blockDim.y + threadIdx.y;
        float P;
    
        if(x<n && y<n)
            if(x>i){ // this limits operation to rows below the pivot point
                P=A[x*n+i]/A[i*n+i];
                I[x*n+y] -= I[i*n+y]*P;  // apply for every row member
                if(y>=i){ //limits  to row members to the right of the pivot
                    A[x*n+y] -= A[i*n+y]*P;  // apply only to members right of pivot
                }
            }
     }
    

    I believe you'll have better results. With the above changes, I was able to duplicate your expected results within the accuracy of float vs. double, I believe.

    0 讨论(0)
提交回复
热议问题