33 #define lapack_int long 48 int nrhs,
const mxArray *prhs[])
53 mwSize sizeAm, sizeAn;
54 mwSize sizeBm, sizeBn;
59 lapack_complex_double *a, *b, *alpha, *beta, *l_eigvec, *r_eigvec;
61 double *ar, *ai, *br, *bi;
62 double *alphar, *alphai, *betar, *betai;
63 double *l_eigvec_r, *l_eigvec_i, *r_eigvec_r, *r_eigvec_i;
77 mexErrMsgIdAndTxt (
"MATLAB:zggev:nInput",
"Two inputs required.");
80 mexErrMsgIdAndTxt (
"MATLAB:zggev:nOutput",
"Too many output arguments.");
86 if ((mxIsDouble(prhs[0]) == 0) && (mxIsDouble(prhs[1]) == 0)) {
87 mexErrMsgIdAndTxt (
"MATLAB:zggev:NonDouble",
"Inputs must be both a double.");
91 if ((mxIsComplex(prhs[0]) == 0) && (mxIsComplex(prhs[1]) == 0)) {
92 mexErrMsgIdAndTxt (
"MATLAB:convec:NonReal",
"Inputs must be both complex");
96 sizeAm = mxGetM(prhs[0]);
97 sizeAn = mxGetN(prhs[0]);
98 sizeBm = mxGetM(prhs[1]);
99 sizeBn = mxGetN(prhs[1]);
101 ar = mxGetPr(prhs[0]);
102 br = mxGetPr(prhs[1]);
103 ai = mxGetPi(prhs[0]);
104 bi = mxGetPi(prhs[1]);
107 plhs[0] = mxCreateDoubleMatrix(sizeAm, 1, mxCOMPLEX);
108 plhs[1] = mxCreateDoubleMatrix(sizeAm, 1, mxCOMPLEX);
109 plhs[2] = mxCreateDoubleMatrix(sizeAm, sizeAn, mxCOMPLEX);
110 plhs[3] = mxCreateDoubleMatrix(sizeAm, sizeAn, mxCOMPLEX);
113 alphar = mxGetPr(plhs[0]);
114 alphai = mxGetPi(plhs[0]);
115 betar = mxGetPr(plhs[1]);
116 betai = mxGetPi(plhs[1]);
117 l_eigvec_r = mxGetPr(plhs[2]);
118 l_eigvec_i = mxGetPi(plhs[2]);
119 r_eigvec_r = mxGetPr(plhs[3]);
120 r_eigvec_i = mxGetPi(plhs[3]);
129 if ( sizeAm != sizeAn || sizeAm != sizeBm || sizeAm != sizeBn ) {
130 mexErrMsgIdAndTxt (
"MATLAB:dggev:MatrixSize",
"Inputs must be square matrices and must have the same dimensions.");
134 mexPrintf(
"Size of the matrix: %d\n", sizeAm_mkl);
138 a = (lapack_complex_double*)malloc(sizeAm_mkl*sizeAm_mkl*
sizeof(lapack_complex_double));
140 mexErrMsgIdAndTxt (
"MATLAB:zggev:malloc",
"Failed to allocate space for matrix A.");
143 b = (lapack_complex_double*)malloc(sizeBm_mkl*sizeBm_mkl*
sizeof(lapack_complex_double));
145 mexErrMsgIdAndTxt (
"MATLAB:zggev:malloc",
"Failed to allocate space for matrix B.");
148 for( idx=1; idx<=sizeBm_mkl*sizeBm_mkl; idx++) {
149 a[idx-1].real = ar[idx-1];
150 a[idx-1].imag = ai[idx-1];
151 b[idx-1].real = br[idx-1];
152 b[idx-1].imag = bi[idx-1];
155 l_eigvec = (lapack_complex_double*)malloc(sizeBm_mkl*sizeBm_mkl*
sizeof(lapack_complex_double));
156 if ( l_eigvec == NULL ) {
157 mexErrMsgIdAndTxt (
"MATLAB:zggev:malloc",
"Failed to allocate space for matrix l_eigvec.");
160 r_eigvec = (lapack_complex_double*)malloc(sizeBm_mkl*sizeBm_mkl*
sizeof(lapack_complex_double));
161 if ( r_eigvec == NULL ) {
162 mexErrMsgIdAndTxt (
"MATLAB:zggev:malloc",
"Failed to allocate space for matrix r_eigvec.");
166 alpha = (lapack_complex_double*)malloc(sizeBm_mkl*
sizeof(lapack_complex_double));
167 if ( alpha == NULL ) {
168 mexErrMsgIdAndTxt (
"MATLAB:zggev:malloc",
"Failed to allocate space for matrix alpha.");
171 beta = (lapack_complex_double*)malloc(sizeBm_mkl*
sizeof(lapack_complex_double));
172 if ( beta == NULL ) {
173 mexErrMsgIdAndTxt (
"MATLAB:zggev:malloc",
"Failed to allocate space for matrix beta.");
175 mkl_set_num_threads_local(12);
176 info = LAPACKE_zggev( LAPACK_COL_MAJOR,
'V',
'V',
177 sizeAm_mkl, a, sizeAn_mkl, b,
179 beta, l_eigvec, sizeAm_mkl, r_eigvec,
186 for( idx=1; idx<=sizeAm_mkl; idx++) {
187 alphar[idx-1] = alpha[idx-1].real;
188 alphai[idx-1] = alpha[idx-1].imag;
189 betar[idx-1] = beta[idx-1].real;
190 betai[idx-1] = beta[idx-1].imag;
194 for( idx=1; idx<=sizeAm_mkl*sizeAm_mkl; idx++) {
195 l_eigvec_r[idx-1] = l_eigvec[idx-1].real;
196 l_eigvec_i[idx-1] = l_eigvec[idx-1].imag;
197 r_eigvec_r[idx-1] = r_eigvec[idx-1].real;
198 r_eigvec_i[idx-1] = r_eigvec[idx-1].imag;
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[])
Gateway routine to call the zggev function from LAPACKE package.