recast complex<double> to complex16

Hello,

I am writing a program, which uses routines from the linear algebra package LAPACK. I am calling one of the complex functions (namely zgeev), which needs a pointer to an array of complex values. According to LAPACK documentation the data type should be an array of Complex*16. I am using complex<double> and call zgeev with this array. When compiling, I get


error: cannot convert ‘std::complex<double>*’ to ‘__complex__ double*’ for argument ‘5’ to ‘int LAPACKE_zgeev(int, char, char, int, __complex__ double*, int, __complex__ double*, __complex__ double*, int, __complex__ double*, int)’


My question is: how can I recast the complex<double> to a __complex__ double*?


The important code pieces:

inclusions:

1
2
3
4
5
6
7
8
9
10
11
12
13
  #define NUM_THREADS 4
#include <cstdlib>
#include<pthread.h>
#include <iostream>
#include "structures.h"
extern "C"{
#include "./lapack-3.6.0/LAPACKE/include/lapacke.h"
#include "./mr3smp-master/INCLUDE/mrrr.h"
}


using namespace std;


Definition of complex<double> array and function

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
 
    complex<double> matrix[nd*nd];
    double wmax=1000.;
    
    vwwp vwwp(n);
    
    pthread_t threads[NUM_THREADS];
    pthread_attr_t attr;
    void *status;
    
    pthread_attr_init(&attr);
    pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_JOINABLE);
    
    for (int i=0; i<NUM_THREADS; ++i){
        argstrs[i].datamatrix = matrix;
        argstrs[i].potential = &vwwp;
        argstrs[i].nd = nd;
        argstrs[i].deltaw=wmax/double(nd);
        argstrs[i].temperature=T;
        argstrs[i].imin = i*perthread;
        // cout << "arguments.imin is " << argstrs[i].imin << endl;
        argstrs[i].imax = (i+1)*perthread;
        // cout << "arguments.imax is " << argstrs[i].imax << endl;
        pthread_create(&threads[i], &attr, &matrixelements, (void*)&argstrs[i]);
    }
    
    pthread_attr_destroy(&attr);
    
    for(int t=0; t<NUM_THREADS; t++) {
        int rc = pthread_join(threads[t], &status);
        if (rc) {
            cout <<"ERROR; return code from pthread_join() is "<< rc << endl;
            exit(-1);
        }
        }
 
    char jobz='N';
    double Eigenvalues[nd];
    double EigenvaluesIm[nd];
    cout << "matrixtrans:" << LAPACKE_zgeev(LAPACK_ROW_MAJOR, jobz, jobz, nd, 
                                            matrix, nd, Eigenvalues, 
                                            EigenvaluesIm, Eigenvalues, nd, 
                                            Eigenvalues, nd)
        << endl;
C++ guarantees that an array of std::complex<double> can be reinterpreted as an array of double, with reals at positions 0,2,4,... and imags at positions 1,3,5,...

C guarantees the same for an array of double complex (which your gcc, I am guessing, is displaying as "__complex__ double ")

So.. you should be able to simply reintepret_cast
Yes, that solved it. Thank you very much. The function is now called by

LAPACKE_zgeev(LAPACK_ROW_MAJOR, jobz, jobz, nd,
reinterpret_cast <__complex__ double*> ( matrix ),
nd, Eigenvalues, EigenvaluesIm,
Eigenvalues, nd,
Eigenvalues, nd)
Topic archived. No new replies allowed.