- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
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[0]);
s.resize(columns);
u.resize(rows*rows);
vt.resize(columns*columns);
//inverse_s_ut.resize(columns*rows);
double *vtran;
vtran = &(vt[0]);
/* Query and allocate the optimal workspace */
lwork = -1;
dgesvd( "All", "All", &m, &n, a, &lda, &(s[0]), &(u[0]), &ldu, &(vt[0]), &ldvt, &wkopt, &lwork,
&info );
lwork = (int)wkopt;
work = (double*)malloc( lwork*sizeof(double) );
/* Compute SVD */
dgesvd( "All", "All", &m, &n, a, &lda, &(s[0]), &(u[0]), &ldu, &(vt[0]), &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
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi. Sorry for the false alarm. I gave ldvt a value of m instead of n.
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page