For my application I need to extract both Q and R matrices from a QR decomposition.

It seems that the right routines for doing this in MAGMA are magma_dgeqrf_gpu and magma_dorgqr_gpu.However, the R matrix computed by magma_dgeqrf_gpu is not the same as returned by magma_dgeqrf2_gpuand LAPACK. Does magma_dgeqrf_gpu use a different scheme to store R?Also, which is the purpose of magma_dgeqrf3_gpu? The documentation talks about some parts of R storedseparately, but this is not quite clear to me.

Thanks for your wonderful library, its source code is an excellent way of learning how to use the GPU.

The reason for the different versions (which indeed can make use confusing!) is performance considerations. If you need to explicitly generate both Q and R you must use version 3. As an example of how to use it you can look in files dgels3_gpu.cpp and dgeqrs3_gpu.cpp. For example, you may have to call

The reason for this is that to make operations involving Q fast we put zeroes in the upper triangular parts of the panels and ones on the diagonals (and the Householder vectors are stored below, as in LAPACK). This destroys R though and therefore we had to store it separately (in dT). To regenerate R we provide the magmablas_dswapdblk routine (see above). Examples on how to avoid the above copies if you just need to solve a least squares problem is given in dgeqrs3_gpu.cpp (there we have multiplication with Q' and solve using R, where we first generate R in place, use it to solve, and move back the data to the original stage for direct application/use of Q if needed).Stan

Is there is a simpler way to read off just the diagonal elements of the R matrix that does not require creating a second copy of the dA matrix (require at least an additional dR matrix, the Q matrix can be calculate in the location of dA since I don't wish to keep this information)?

Also, I'm attempting to compile my code and keep getting an error that there is an undefined reference to magma_stream in libmagmablas.a. Any thoughts?

You can generate Q at the place of dA but you will loose R, unless you copy it somewhere else first. If you need just the diagonal elements of R you can get them as the diagonals of the nb x nb matrices starting from dT+min(m,n)*nb. magma_stream is defined as

From looking at the code magmablas_dswapdblk swaps values from dR and dT. It also seems to me from looking at the code and your reply that should I compute Q prior to grabbing R from dT I would destroy the information regarding R that is stored in dT, but that is precisely what is done in the code example above. Additionally, since magmablas_dswapdblk swaps values if I were to call this prior to computing Q I would destroy any information in dT that I would need to compute Q. Therefore, shouldn't it be dT that is temporarily copied, and not dA?

Lastly, I still don't understand why I continue to get an error stating that magma_stream is undefined. I've stripped testing_sgeqrf_gpu.cpp and testing_sorgqr.cpp to their respective bare minimums, and it seems the only header file that is necessary to execute magma_sgeqrf_gpu and magma_sorgqr_gpu is magma.h Additionally, I am linking all the same libraries when I try to compile my code as when I compile the two testing files. The testing files compile and run, but I continue to receive the same error.

The magma_stream variable is indeed not defined in the routines mentioned but is defiled in libmagma.a. Try the suggestion from Andreas of listing -lmagma twice during the linking.

You can try out the suggestion about the copies; I am not sure I understand what you need to keep and generate. The example in the code is working, but it may have copies that you would not need in your specific case; it is just to show how to use the routines. Another example is solving the least squares problem Q R x = b (see files dgels3_gpu.cpp and dgeqrs3_gpu.cpp) without generating Q (only the application of Q^T) and generating R in order to do a triangular solve.