Intel® oneAPI Math Kernel Library
Ask questions and share information with other developers who use Intel® Math Kernel Library.

MKL LAPACKE (SVD)!

zavataafnan
Beginner
2,172 Views
I want to calculate the SVD of huge matrix,
My code is:
[bash]double superb[55-1];
m_numberOfPixel = 121815;
m_numberOfImages = 9;
double * InAA = new double[m_numberOfPixel*m_numberOfImages*55];
double * w = new double[55];
double * v = new double[55*55];

int m = m_numberOfPixel*m_numberOfImages, n = 55, lda = m_numberOfPixel*m_numberOfImages, ldu = 1, ldvt = 55,
info, lwork; info = LAPACKE_dgesvd( LAPACK_COL_MAJOR, 'N', 'A', m, n, InAA, lda, w, NULL, ldu, v, ldvt, superb );[/bash]
where,
I do not want to calculate the U matrix so i set ldu =1 and NULL as an input to LAPACKE_dgesvd function, is that right?
the return value of info, in this case, is -6
I used these libraries
mkl_intel_lp64.lib
mkl_sequential.lib
mkl_core.lib
Another problem :
when i select (mkl_intel_ilp64.lib, mkl_intel_thread.lib, mkl_core.lib) the return value is always -5 !!!
I think the documentation for mkl is not very strong for anyone who is beginner like me!!!
Best Regards,
MJM
0 Kudos
11 Replies
mecej4
Honored Contributor III
2,172 Views
Which compiler version, which MKL version?

I agree that the MKL documentation can be difficult to use for a C/C++ user, because the usage description attempts to cover calling from all the covered languages (F77, F9X, C and C++) with one block of text. Since some parameters (e.g., WORK, LWORK) do not apply to the C interfaces, and some other parameters do not apply to the Fortran interfaces, it can be hard work to read a description in which irrelevant parts are interleaved with the relevant parts.

When passing 2D arrays with the C/C++ interface, the usual description of

"ldA INTEGER. The first dimension of the array A"

is at least confusing to follow; worse, if the array A is stored as a native 2D C array (i.e.,row-major), it is also wrong -- for such an array, ldA should be the declared row-length of the argument, which would be the second dimension.

The error message indicates that the input matrix is not seen as suitable. Did you set its elements properly?

You cannot switch from LP64 to ILP64 at will. To use the latter, you must compile your sources such that integer arguments to MKL routines have the proper length, for example by using -DMKL_ILP64 .

Here is a simple C example that you may find helpful.

[cpp]#include 
#include 
#include 
int main(void){
double superb[4-2];  
lapack_int m = 3, n = 4;
double A[] = { 2.0,-1.0, 0.0, 1.0,
              -1.0, 2.0,-1.0,-1.0,
               0.0,-1.0, 2.0, 1.0};  
double s[3];
double v[4*4]; 

lapack_int ldu = 1, ldvt = 4, info, lwork, lda=4;  

info = LAPACKE_dgesvd( LAPACK_ROW_MAJOR, 'N', 'A', m, n, A, lda,  
             s, NULL, ldu, v, ldvt, superb );
if(info==0)printf("s = %e %e %en",s[0],s[1],s[2]);
}
[/cpp]
The result of compiling and running this program is

[bash]s = 3.819519e+00 2.000000e+00 6.413085e-01
[/bash]

0 Kudos
zavataafnan
Beginner
2,172 Views
Thanks for your reply.
I had another exprience that could be useful for this solution. when i reduce the size of matrix from 121815 to 12181 (about ten times). the function returns 0 and it performs SVD!!!!!

At first, I agree with you about the documentation of MKL. But what is the solution?
Is that good to write FORTRAN code and create a DLL file to use it in the program?


Best Regards,
MJM
0 Kudos
zavataafnan
Beginner
2,172 Views
Excuse me i forgot to mention the version of compiler!
MKL 10.3
COMPILER : Intel Composer XE 2011

0 Kudos
Gennady_F_Intel
Moderator
2,172 Views
- by another words your original matrix (121815 x 55 ) crashed even after mesej4 recommendation?
What is RAM's size available on your system?
0 Kudos
zavataafnan
Beginner
2,172 Views
Windows 7 Ultimate 64 bit
RAM : 24 GBytes, DDR3, Triple.
CPU: i7 950
MainBoard : Rampage III Extreme
I am in doubt that the amount of RAM is problem. I calculate the SVD of matrix 3 times bigger than that one with matlab.
At the end, I am really confused!
Best Regards,
MJM
0 Kudos
zavataafnan
Beginner
2,172 Views
I also changed the order to row major, but the code did not run correctly and i got -6.
By the way, I hope it is my fault not a bug in the MKL library.

Best Regards,
MJM
0 Kudos
mecej4
Honored Contributor III
2,172 Views
I hope it is my fault not a bug in the MKL library

In either case, we should like to find the error and remove it, shouldn't we?

If you can present a complete "reproducer", i.e., a complete program source that can be compiled and run by someone here, which will produce the same errors as those that you saw, while being as short as possible, it may be possible to diagnose and remove the error.

You will also need to provide any data needed by the program to run, and document the compiler and linker switches used to build the application, and the OS configuration (version, CPU, RAM, .. -- most of this you have already provided above, but it would be convenient to have everything needed to reproduce the bug available together in one posting).
0 Kudos
Gennady_F_Intel
Moderator
2,172 Views
YES. Itotallyagree withyou, mecej4!!!.
0 Kudos
zavataafnan
Beginner
2,171 Views
First of all, Thanks for your replies. I have not seen your messeges! (I think your website should have email notification service for a new post. Is that right?)

Second, I wrote this simple sample code that the array was not initialized. When i run, the return of the function is -1011. I can not find why the return value is this number. Unfortunately, we are not accessed the source code and we can not understand the meaning of this type of return, Am i right?

[sectionBody]
#include "stdio.h"
#include "mkl_lapacke.h"

int main(void)
{
	double * InA;
	int size1 = 55 , size2 = 1096330;
	//InA = Read_Two_Dimension_File("d:\test.dat",&size1, &size2);
	InA = new double[size1*size2];

	double * superb = new double[size1-2];
	double w[55];
	double v[55*55];

	int m = size1, n = size2, lda = size2, ldu = 1, ldvt = size2, info, lwork;

	//double * u = new double[55*m_numberOfPixel*m_numberOfImages];
	info = LAPACKE_dgesvd( LAPACK_ROW_MAJOR, 'N', 'A', m, n, InA, lda,
		w, NULL, ldu, v, ldvt, superb );


	delete [] InA;
	delete [] superb;

	if( info > 0 ) {
		printf( "The algorithm computing SVD failed to converge.n" );

	}
	return 0;
}[/sectionBody]



[sectionBody]Third, My system is:
Windows 7 Ultimate 64 bit SP1
RAM : 24 GBytes of DDR3.
MainBoard : Rampage III Extreme
Hard : two SATA6 (RAID 0)

Visual Studio 2010 Ultimate.
Intel Composer XE 2011 Update 1


Best Regards,
MJM[/sectionBody]


0 Kudos
zavataafnan
Beginner
2,172 Views
I see a message in console window may be helpful,

Not enough memory to transpose matrix in LAPACKE_dgesvd_work

0 Kudos
mecej4
Honored Contributor III
2,172 Views
The source code for the LapackE C interfaces has been (generously) donated by Intel to Netlib. See also the thread

C interface for LAPACK routines? posted in October 2008 in this forum.

and

the documentation at Netlib (a description of the Lapack library and its variants).

The error -6 corresponds to NaNs being found in the input matrix. Since a check for their presence is made, you cannot pass an uninitialized matrix to the routine and expect it to work.

I suggest that you restart your work and build a program with fairly small matrices with the proper configuration. After this test program is functioning properly, you can increase the size to whatever is needed in your application.
0 Kudos
Reply