diff --git a/src/hqr.c b/src/hqr.c
index 1522aaf45cd322306846afb527a6fe5e24cadb26..d1b856d1b3d2d47bfabc97e937438f7d87fc9c42 100644
--- a/src/hqr.c
+++ b/src/hqr.c
@@ -806,8 +806,24 @@ libhqr_initfct_hqr( libhqr_tree_t *qrtree,
     }
 
     /* Compute parameters */
-    a = (a == -1) ? 4 : libhqr_imax( a, 1 );
-    p = libhqr_imax( p, 1 );
+    if ( a == -1) {
+        a = 4; /* TODO: add automatic computation */
+    }
+    else {
+        a = libhqr_imax( a, 1 );
+    }
+
+    if ( p == -1 ) {
+        if ( trans == LIBHQR_QR ) {
+            p = A->p;
+        }
+        else {
+            p = A->nodes / A->p;
+        }
+    }
+    else {
+        p = libhqr_imax( p, 1 );
+    }
 
     /* Domino */
     if ( domino >= 0 ) {