magma_sporti_gpu row major or column major?

Open discussion for MAGMA

magma_sporti_gpu row major or column major?

Postby luiceur » Fri Jul 20, 2012 6:09 am

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?

Postby mgates3 » Fri Jul 20, 2012 12:17 pm

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: 336
Joined: Fri Jan 06, 2012 2:13 pm


Return to User discussion

Who is online

Users browsing this forum: Yahoo [Bot] and 3 guests