## magma_sporti_gpu row major or column major?

Open discussion for MAGMA library (Matrix Algebra on GPU and Multicore Architectures)

### magma_sporti_gpu row major or column major?

I am trying to generate the inverse of a square matrix using magma_sportf_gpu + magma_sporti_gpu. However, I am not getting the right results and I suspect the reason is the way I populate the matrix. Can anyone help me out here?

Code: Select all
`  magma_int_t N = 4;  int n2 = N*N;  const char  *uplo = MagmaLowerStr;  magma_int_t info;  TESTING_MALLOC( h_A,  float, n2 );  TESTING_MALLOC( h_C,  float, n2 );  TESTING_DEVALLOC( d_A, float, n2);/*Populate the matrix*/ for (i =0; i < N; i++){    for (j = 0; j < N; j++){       h_A[i*N + j]=(float)(i*N+j);    }  }  /* Transfering data to the GPU*/   magma_ssetmatrix( N, N, h_A, N, d_A, N );  /* Calculate Matrix Inverse */  magma_spotrf_gpu(uplo[0], N, d_A, N, &info);  magma_spotri_gpu(uplo[0], N, d_A, N, &info);  if (info != 0)    printf("Argument %d of magma_spotri had an illegal value.\n", (int) -info);  /* Get results */ magma_sgetmatrix( N, N, d_A, N, h_C, N );/* Verify results */ for (i = 0; i < N; i++) {    for (j = 0; j < N; j++) {      printf("h_C[%d] = %f \n", i*N+j, h_C[i*N+j]);    }  }`

What am I doing wrong? I've followed the testing example but I don't really get the difference with my code. Any ideas?
luiceur

Posts: 26
Joined: Tue Jul 10, 2012 4:38 am

### Re: magma_sporti_gpu row major or column major?

Magma and Lapack are column-wise (so called fortran order). So the i,j entry is A[i + j*lda], for a matrix with leading dimension of lda. The lda >= m, for the number of rows m. If you allocate m*n space, then lda==m.

That particular matrix, with Aij == i*n + j, is probably very ill-conditioned, so the results won't be very accurate.

Also, if your goal is to solve a system Ax=b, that is, x = A^-1 b, please use potrf / potrs (or equivalently posv) as that will be both faster and more accurate than forming the inverse and multiplying.

-mark
mgates3

Posts: 547
Joined: Fri Jan 06, 2012 2:13 pm