Problem for using zggev in C

Open discussion regarding features, bugs, issues, vendors, etc.

Problem for using zggev in C

Postby bachelard_nicolas » Fri May 11, 2012 12:35 pm

Dear all,

I am trying to use zggev in C, this is a lapack function for generalized eigenvalues problem. Unfortunately I have a core dumped when I execute my code.
I am pretty sure my declaration is ok and I am working on it for a while now.

I am running a very basic example of two 4*4 matrices:

Code: Select all
struct _fcomplex { float re, im; };
typedef struct _fcomplex fcomplex;

extern "C"
        void zggev_(char *jobvl, char *jobvr, int *n, fcomplex *a,
                int *lda, fcomplex *b, int *ldb, fcomplex *alpha, fcomplex *beta, fcomplex *vl,
                int *ldvl, fcomplex *vr, int *ldvr, fcomplex *work, int *lwork, float *rwork, int *info);

/* Parameters */
#define N 4
#define LDA N
#define LDVL N
#define LDVR N

int main(int argc, char *argv[])
fcomplex ca[LDA*N] = {
        {-21.10f, -22.50f}, {53.50f, -50.50f}, {-34.50f, 127.50f}, {7.50f, 0.50f},
        {-0.46f, -7.78f}, {3.50f, -37.50f}, {-15.50f, 58.50f}, {-10.50f,-1.50f},
        {4.30f,-5.50f}, {39.70f,-17.10f}, {-68.50f,12.50f}, {-7.50f,-3.50f},
        {5.50f,4.40f}, {14.40f,43.30f}, {-32.50f,-46.00f}, {-19.00f,-32.50f}

fcomplex cb[LDA*N] = {
        {1.00f,-5.00f}, {1.60f,1.20f}, {-3.00f,0.00f}, {0.00f,-1.00f},
        {0.80f,-0.60f}, {3.00f,-5.00f}, {-4.00f,3.00f}, {-2.40f,-3.20f},
        {1.00f,0.00f},  {2.40f,1.80f}, {-4.00f,-5.00f}, {0.00f,-3.00f},
        {0.00f,1.00f}, {-1.80f,2.40f}, {0.00f,-4.00f},  {4.00f,-5.00f}

       char jobvl = 'V', jobvr = 'N';
        int n, lda, ldb, ldvl, ldvr, lwork, info;
        n = N;
        ldb = N;
        ldvl = N;
        ldvr = n;
        lwork = std::max(1,40*n); // This may be choosen better!

        fcomplex *work;
        work = (fcomplex*)malloc(2*lwork*sizeof(fcomplex));
        float *rwork; // This may be choosen better
        rwork = (float*)malloc(8*n*sizeof(float));
        fcomplex *alpha, *beta;
        alpha = (fcomplex*)malloc(n*sizeof(fcomplex));
        beta = (fcomplex*)malloc(n*sizeof(fcomplex));
        fcomplex *vl, *vr;
        vl = (fcomplex*)malloc(ldvl*n*sizeof(fcomplex));
        vr = (fcomplex*)malloc(ldvr*n*sizeof(fcomplex));

zggev_(&jobvl, &jobvr, &n, ca, &lda, cb, &ldb, alpha, beta, vl, &ldvl, vr, &ldvr, work, &lwork, rwork, &info);

return 0;

Does any one get an idea?

Best regards
Posts: 1
Joined: Fri May 11, 2012 12:22 pm

Re: Problem for using zggev in C

Postby CyLith » Mon May 21, 2012 7:27 pm

You're using float precision with zggev which requires double precision. Either call sggev, or change your complex data type to using doubles.
Posts: 35
Joined: Sun Feb 08, 2009 7:23 am
Location: Stanford, CA

Return to User Discussion

Who is online

Users browsing this forum: Bing [Bot] and 3 guests