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
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.