Page 1 of 1

magma_dgeqp3 parameter 2 incorrect

Posted: Fri Sep 15, 2017 7:18 pm
by nheavner
I am having trouble performing a column-pivoted QR factorization using magma_dgeqp3. On exit, info=-2, but I don't see how the second input parameter could be incorrect as it is rather straightforward, and I am using an example code from what seems a trustworthy source. Testing_dgeqp3 in the downloaded magma-2.2.0 directory runs perfectly, and I have used other magma functions (magma_dgeqrf, magma_dgesdd) successfully, so I think the install itself is ok.

Below is my minimal code to test magma_dgeqp3:

Code: Select all

# include <stdio.h>
# include <cuda.h>
# include "magma.h"
# include "magma_lapack.h"

# define min(a, b ) ((( a ) <( b ))?( a ):( b ))
# define max(a, b ) ((( a ) <( b ))?( b ):( a ))

int main( int argc , char ** argv )
  magma_init(); // initialize Magma

  double gpu_time = 0.0 , cpu_time = 0.0;

  magma_int_t m = 100 , n = m, n2=m*n;

  double *a, *r; // a, r - mxn matrices on the host
  double * h_work ; // workspace
  double *tau ; // scalars defining the elementary reflectors

  magma_int_t * jpvt ; // pivoting information
  magma_int_t i, j, info, nb;
  magma_int_t min_mn = min(m, n);
  magma_int_t ione = 1 , lwork ; // lwork - workspace size
  magma_int_t ISEED [4] = {0 ,0 ,0 ,1}; // seed

  double c_neg_one = MAGMA_D_NEG_ONE ;

  nb = magma_get_dgeqp3_nb( m, n ); // optimal blocksize

  jpvt =( magma_int_t *) malloc(n* sizeof( magma_int_t )); // host mem .
  // for jpvt

  magma_dmalloc_cpu(& tau , min_mn ); // host memory for tau
  magma_dmalloc_pinned(&a,n2 ); // host memory for a
  magma_dmalloc_pinned(&r,n2 ); // host memory for r

  lwork = 2*n + ( n+1 )* nb;
  lwork = max(lwork , m * n + n);
  magma_dmalloc_cpu(& h_work , lwork ); // host memory for h_work

  // Random matrix a, copy a -> r
  lapackf77_dlarnv(& ione ,ISEED ,&n2 ,a);
  lapackf77_dlacpy( MagmaUpperLowerStr ,&m ,&n,a ,&m,r ,&m); // a- >r

  // MAGMA
  lapackf77_dlacpy( MagmaUpperLowerStr ,&m ,&n,a ,&m,r ,&m);
  for (j = 0; j < n; j++)
  jpvt[j] = 0 ;

  // QR decomposition with column pivoting , Magma version
  printf("info = %d \n", info);
  printf(" MAGMA time : %7.3f sec .\n",gpu_time ); // Magma time

  // Free memory
  free( jpvt ); // free host memory
  free( tau ); // free host memory
  magma_free_pinned(a); // free host memory
  magma_free_pinned(r); // free host memory
  free( h_work ); // free host memory
  magma_finalize( ); // finalize Magma
  return EXIT_SUCCESS ;
and the Makefile I am using:

Code: Select all

# Definitions of variables

CC      = nvcc
LD              = nvcc
GENCODE_FLAGS = -arch=sm_35 -gencode arch=compute_35,code=compute_35

# Definitions of rules
testing-dgeqp3.x : testing-dgeqp3.o
        @$(LD) $(GENCODE_FLAGS) \
        -o testing-dgeqp3.x \
        testing-dgeqp3.o \
        -L/usr/local/cuda/lib64 \
        -L/usr/local/magma/lib \
        -lmagma -lcudart -lcusolver -lcublas -lgomp \
        /opt/intel/mkl/lib/intel64/libmkl_intel_lp64.a \
        /opt/intel/mkl/lib/intel64/libmkl_gnu_thread.a \
        /opt/intel/mkl/lib/intel64/libmkl_core.a \
        -ldl -lpthread -lgomp

testing-dgeqp3.o : testing-dgeqp3.cpp
        @$(CC) $(GENCODE_FLAGS) -c testing-dgeqp3.cpp \
        -I/opt/intel/mkl/include \
        -I/usr/local/magma/include \

clean : FORCE
        rm -f a.out *.o *~ core

Any thoughts would be greatly appreciated, thanks!

Re: magma_dgeqp3 parameter 2 incorrect

Posted: Fri Sep 15, 2017 10:39 pm
by Stan Tomov
This is interesting. I took your example and the way you compile and link it,
and managed to run the code without problem. I would have guessed there is
problem with MKL, but you say the testing_dgeqp3 in magma-2.2.0 runs fine.

Re: magma_dgeqp3 parameter 2 incorrect

Posted: Mon Sep 18, 2017 12:48 pm
by nheavner
Hmmm, then that is odd. Yes, testing_dgeqp3 runs fine. Is there any possibility that my install of magma requires a different compile and/or link line? I'd still be surprised if this is the issue since I've been able to get dgesdd and dgeqrf to work with no problem.

Is there maybe a way to back out what the compile and link lines were when I compiled the files in testing? I tried to read it from the makefiles, but they are far too complicated for me.

Re: magma_dgeqp3 parameter 2 incorrect

Posted: Mon Sep 18, 2017 1:11 pm
by Stan Tomov
You can just recompile - remove testing_dgeqp3 and testing_dgeqp3.o, and do
make testing_dgeqp3
to see how it is compiled and linked through the magma testers. The way you have it is a little different but still worked on the system that I tested. Compiling and linking the same way indeed sounds like a good idea that can give you a hint. You can also inspect to what libraries the executable is linked, e.g.,
ldd testing_dgeqp3
and see if everything is the same in both cases.

Re: magma_dgeqp3 parameter 2 incorrect

Posted: Mon Sep 18, 2017 3:45 pm
by nheavner
After following your advice, I found that I needed to pass in -DMKL_ILP64 when compiling and add -lmkl_intel_ilp64 when linking, as the mkl library wasn't correctly linked in the executable. Things appear to be running smoothly now, thanks for the pointers and quick responses!