Community
cancel
Showing results for
Did you mean: Beginner
60 Views

## Glibc error for dgesvd

Hi, I am using MKL to compute SVD of a real matrix. I use C++ code with std::vectors. Here is a portion of my code related to SVD

void Decompose_InterpolMatrix_To_SVD(int rows, int columns, std::vector<double> &Interp_matrix) {
/* Locals */
int m = rows, n = columns, lda = m, ldu = m, ldvt = m, info, lwork;
int i,j,k;

double wkopt;
double* work;
double *a,alpha=1.0e0,beta=0.0e0,tausq=1.0e-4;
//double s[columns], u[rows*rows], vt[columns*columns];
std::vector<double> u, s, vt;

a = &(Interp_matrix);
s.resize(columns);
u.resize(rows*rows);
vt.resize(columns*columns);
//inverse_s_ut.resize(columns*rows);

double *vtran;
vtran = &(vt);

/* Query and allocate the optimal workspace */
lwork = -1;
dgesvd( "All", "All", &m, &n, a, &lda, &(s), &(u), &ldu, &(vt), &ldvt, &wkopt, &lwork,
&info );
lwork = (int)wkopt;
work = (double*)malloc( lwork*sizeof(double) );
/* Compute SVD */
dgesvd( "All", "All", &m, &n, a, &lda, &(s), &(u), &ldu, &(vt), &ldvt, work, &lwork,
&info );
/* Check for convergence */
if( info > 0 ) {
std::cerr << "The algorithm computing SVD failed to converge." << std::endl;
exit( 1 );
}

/* Free workspace */
free( (void*)work );

}

When I run this code I get :

*** glibc detected *** ./checkmkl1: munmap_chunk(): invalid pointer: 0x000000001a43e610 ***
======= Backtrace: =========
/lib64/libc.so.6(cfree+0x166)[0x3693672886]
./checkmkl1[0x40206a]
./checkmkl1(__gxx_personality_v0+0x29a)[0x401d22]
/lib64/libc.so.6(__libc_start_main+0xf4)[0x369361d994]
./checkmkl1(_ZNSt8ios_base4InitD1Ev+0x41)[0x401b29]

I do not get this error when I declare s,u,vt as proper arrays. This is strange as one can use vectors of primitive types as arrays. Any help is greatly appreciated.

Suman  