1

My project is about finding Q in QR decomposition for very large matrices (e.g. 500*500) in C++. I've started to use Lapack package recently and its especial function "dgeqrf". I started by a simple matrix as below in Code:blocks:

 #include <iostream>
 #include <lapacke.h>

using namespace std;

int main()
{
    double a[6][2] = {{0,2},{2,-1},{2,-1},{0,1.5},{2,-1},{2,-1}};
    int m=6;
    int n=2;
    int info = 0;
    int lda = m;
    int lwork = n;
    double *work;
    double *tau;
    dgeqrf_(&m, &n, a, &lda, tau, work, &lwork, &info);

}

After running the code, I saw this error in "dgeqrf" line:

error: cannot convert 'double (*)[2]' to 'double*' for argument '3' to 'void dgeqrf_(int*, int*, double*, int*, double*, double*, int*, int*)'

Who can help me about this error?Do I have mistake in parameter definition? Also, after running, how I can work with the Q matrix? Can I define a new matix double q[][]=dgeqrf(....) and use it in my project? I'm sorry if my question was very basic but I couldn't find the solution.

Ham82
  • 665
  • 1
  • 4
  • 16
  • seems like dgeqrf_ is expecting `a` to be a flattened array – tinkertime Dec 03 '16 at 14:45
  • Welcome to Stackoverflow. @yankee2905's answer fixes the error you reported . You don't want to accept his answer because it reveals your *next* problem. One question at a time on SO. If you simply want your problems solved until your project is complete, I'm afraid this is the wrong place. Your next problem is that you are not linking the library in which `dgeqrf_` is defined. Your next *question* is [How do I link to a library with Code::Blocks?](http://stackoverflow.com/q/5862757/1362568) – Mike Kinghan Dec 03 '16 at 17:55
  • @MikeKinghan Thanks for your response. I have done the procedure in recommended link before. Also, I tried the "Armadillo " library and I can do some simple computation there, but I couldn't do QR decomposition there by this error : "undefined references to _gfortran_compare_string" . Also I have this problem in DEV C++ .It seems the problem is in installation step. – Ham82 Dec 04 '16 at 02:21

1 Answers1

4
double a[12] = {0, 2, 2,  0, 2, 2,  // row1
                2,-1,-1,1.5,-1,-1}; // row2
tinkertime
  • 2,972
  • 4
  • 30
  • 45
  • I did it. But it does not work yet. Now code::Blocks shows the new error : "undefined reference to `dgeqrf_'". It has confused me. – Ham82 Dec 03 '16 at 15:06