Page 1 of 1

QR Decomposition

PostPosted: Wed Jul 05, 2017 4:59 am
by quanghieu
I am trying to perform the QR Decomposition of a square, complex matrix with pivoting. Can I use cqeqp3_gpu to get R and the pivoting vector, followed by cungqr_gpu to output Q? The cungqr_gpu description mentions that it uses the outputs of cgeqrf_gpu, but does not mention cgeqp3_gpu.

Re: QR Decomposition

PostPosted: Wed Jul 26, 2017 2:55 pm
by mgates3
Yes and no. Yes, you can use ungqr, just realize that the matrix A has been permuted. No, unfortunately, magma_zungqr_gpu takes the extra dT parameter that magma_zgeqrf_gpu generates, but magma_zgeqp3_gpu does not. You will have to use magma_zungqr2, which is a CPU interface (the input/output memory is on the CPU) instead of a GPU interface. It would not be difficult to create a GPU interface magma_zungqr2_gpu, if that is needed. Or you could use magma_zunmqr2_gpu with input dC = identity.

Attached is a small tester showing use of geqp3 and ungqr2 (or orgqr2, in real), including error checks. Here is how I compiled it and the output.

Code: Select all
prompt>  g++ -DADD_ -Wall -o qp3 qp3.cpp -I$MAGMADIR/include -I $CUDADIR/include -L$MAGMADIR/lib -lmagma -Wl,-rpath,$MAGMADIR/lib -L $CUDADIR/lib -lcublas -lcudart -framework Accelerate

prompt>  ./qp3 8 4
A = [
   0.1319   0.6621   0.1762   0.7866
   0.2338   0.4633   0.3565   0.2583
   0.3216   0.4809   0.9981   0.0476
   0.7105   0.9500   0.9680   0.9427
   0.0211   0.0234   0.5485   0.4750
   0.5844   0.4816   0.4999   0.6066
   0.2109   0.2395   0.6751   0.7507
   0.5567   0.2708   0.9892   0.9649
];
QP3 = [
  -2.0191  -1.5928  -1.1711  -1.0461
   0.1624   1.0619   0.4124   0.2288
   0.4547   0.8691   0.7800   0.2423
   0.4410   0.0895  -0.1784  -0.4138
   0.2499   0.1005   0.4464  -0.2164
   0.2277  -0.0545  -0.0552   0.5091
   0.3075  -0.0160   0.3575  -0.0863
   0.4506   0.0902   0.5806   0.3753
];
tau = [    1.0873   1.1206   1.1771   1.3752 ];
jpvt = [   3   4   2   1];
R = [
  -2.0191  -1.5928  -1.1711  -1.0461
   0.       1.0619   0.4124   0.2288
   0.       0.       0.7800   0.2423
   0.       0.       0.      -0.4138
];
Q = [
  -0.0873   0.6098   0.3954   0.4707
  -0.1766  -0.0216   0.3403   0.0686
  -0.4944  -0.6966   0.2426   0.2293
  -0.4794   0.1686   0.4090  -0.1723
  -0.2717   0.0398  -0.3990   0.4243
  -0.2476   0.1999   0.1400  -0.5937
  -0.3344   0.2054  -0.3037   0.2715
  -0.4900   0.1737  -0.4804  -0.2919
];
AP = [
   0.1762   0.7866   0.6621   0.1319
   0.3565   0.2583   0.4633   0.2338
   0.9981   0.0476   0.4809   0.3216
   0.9680   0.9427   0.9500   0.7105
   0.5485   0.4750   0.0234   0.0211
   0.4999   0.6066   0.4816   0.5844
   0.6751   0.7507   0.2395   0.2109
   0.9892   0.9649   0.2708   0.5567
];
% Error || AP - QR || / (m ||A||) = 4.27e-17
% Error || I - Q^H Q || / m       = 7.69e-17


Sorry for the delay in responding; this got stuck in my spam folder for some reason.

-mark