# lapack dorgqr qr decomposition matrix $m\times n$ with $m<n$

I'd like to do a $A=QR$ decomposition of a matrix $A$, with $m\times n$. I use dgeqrf_ (or dgeqp3_) to proceed to the first part of the decomposition. Then, I can easily compute the matrix $R$ by taking the upper diagonal part of the output matrix.

If $A$ is such that $m > n$, the Lapack subroutine dorgqr_ create the correct $Q$ matrix.

But if $A$ is such that $m < n$, the same subroutine gives me an error :

** On entry to DORGQR parameter number  2 had an illegal value


I guess it's because $m<n$... should I use another routine for this case?

You seem to be confusing the input arguments for dorgqr. The second argument is the width of the orthogonal/unitary matrix which you would like to generate as the product of the Householder reflectors generated by dgeqrf or dgeqp3. While both of these routines support the $m \le n$ case, you should recognize that, when $m \le n$, the QR decomposition implies a $Q$ which is $m \times m$ and an $R$ which is $m \times n$, and $Q$ is implicitly defined as the product of the $m$ Householder transformations implied by each of the first $m$ columns of the output of dgeqrf/dgeqp3.
You should thus have the first, second, and third argument of dorgqr each equal to $m$. My guess is that you used the width of $A$, $n$, for the second argument, which would be illegal.
Usually people use the QR decomposition for tall/skinny matrices, as Jan pointed out. For short/fat matrices, the LQ decomposition is more appropriate. It is basically a QR on the transpose of the matrix, and you use routine dgelqf.