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

Same numbers differente signal

Fábio_A_
Beginner
500 Views

Dear MKL forum,

     I am rewriting some code using the MKL library from a fortran + open source math library, in the validation process i realize the function LAPACKE_dgesv giving the exact solution from the former code. But, in the eigenvectors some signals are changed, where is positive should be negative in several cases.

    The input matrix is exact the same, the fortran code:

         call dsyev ( jobz , uplo , m, dd , m, w, work , lm, info )

     The C code:

    LAPACKE_dgesv(LAPACK_COL MAJOR,jobz, uplo, m, temp, m,w);


The parameters to each function is the same. Is the some configuration, bug or specification to solve this ?

 

Best regards

0 Kudos
7 Replies
mecej4
Honored Contributor III
500 Views

LAPACKE_dgesv is for solving simultaneous equations. In writing "signals" did you mean signs?

Did you mean to write "LAPACKE_dsyev"? Please be specific regarding which example you tried and what the differences in the output were.

Different Lapack routines, especially those of different year of creation and authorship, can yield different eigenvectors, depending on the scaling used. After all, if v is an eigenvector, so is c.v, where c is any non-zero constant.

0 Kudos
Fábio_A_
Beginner
500 Views

Dear mecej4,

     Sorry for the misunderstand, is a little late when i am posted the message, i mean signs, some number should be positive and they appearing negative. I am rewrite one application from fortran to C who uses LAPACKE_dgesv.

The former application was using open source lapack and now i am using MKL.

  Best regards.

0 Kudos
Ying_H_Intel
Employee
500 Views

Hi Fabio A,

Could you please tell some basic information, like the OS and hardware, link option, etc ,  include the code (&the input) so we can verify?

Best Regards,

Ying H.

Intel MKL Support

0 Kudos
Fábio_A_
Beginner
500 Views

Dear Ying H.

(the input and output are too in https://drive.google.com/open?id=0BxS_wsfvM3LeX2xtVFI1eGFyZGc&authuser=0)

Both code is running in x86_64 intel core i3, Linux asdfrec 3.16.0-4-amd64 #1 SMP Debian 3.16.7-ckt9-3~deb8u1 (2015-04-24) x86_64 GNU/Linux and mkl and icc from composer_xe_2015.3.187

Matrix input for the C and fortran code:

5.553227, -2.776614, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,;
-2.776614, 5.553227, -2.776614, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,;
0.000000, -2.776614, 5.553227, -2.776614, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,;
0.000000, 0.000000, -2.776614, 5.553227, -2.776614, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,;
0.000000, 0.000000, 0.000000, -2.776614, 5.553227, -2.776614, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000,;
0.000000, 0.000000, 0.000000, 0.000000, -2.776614, 5.553227, -2.776614, 0.000000, 0.000000, 0.000000, 0.000000,;
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, -2.776614, 5.553227, -2.776614, 0.000000, 0.000000, 0.000000,;
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, -2.776614, 5.553227, -2.776614, 0.000000, 0.000000,;
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, -2.776614, 5.553227, -2.776614, 0.000000,;
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, -2.776614, 5.553227, -2.776614,;
0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, 0.000000, -2.776614, 5.553227,;

Fortran code:

jobz='V'
uplo='U'
lm = 5*m
m = 11
call dsyev ( jobz , uplo , m, dd , m, w, work , lm, info )

Ouput from fortran code:

-0.1056624327 -0.2041241452 -0.2886751346 0.3535533906 0.3943375673 0.4082482905 0.3943375673 0.3535533906 0.2886751346 -0.2041241452 0.1056624327
-0.2041241452 -0.3535533906 -0.4082482905 0.3535533906 0.2041241452 1.87E-017 -0.2041241452 -0.3535533906 -0.4082482905 0.3535533906 -0.2041241452
-0.2886751346 -0.4082482905 -0.2886751346 7.49E-017 -0.2886751346 -0.4082482905 -0.2886751346 2.11E-016 0.2886751346 -0.4082482905 0.2886751346
-0.3535533906 -0.3535533906 -2.03E-016 -0.3535533906 -0.3535533906 6.06E-017 0.3535533906 0.3535533906 1.12E-015 0.3535533906 -0.3535533906
-0.3943375673 -0.2041241452 0.2886751346 -0.3535533906 0.1056624327 0.4082482905 0.1056624327 -0.3535533906 -0.2886751346 -0.2041241452 0.3943375673
-0.4082482905 -5.27E-016 0.4082482905 -1.64E-016 0.4082482905 -2.54E-016 -0.4082482905 -1.21E-017 0.4082482905 -7.77E-016 -0.4082482905
-0.3943375673 0.2041241452 0.2886751346 0.3535533906 0.1056624327 -0.4082482905 0.1056624327 0.3535533906 -0.2886751346 0.2041241452 0.3943375673
-0.3535533906 0.3535533906 3.71E-016 0.3535533906 -0.3535533906 4.68E-016 0.3535533906 -0.3535533906 -1.20E-015 -0.3535533906 -0.3535533906
-0.2886751346 0.4082482905 -0.2886751346 1.65E-016 -0.2886751346 0.4082482905 -0.2886751346 -2.02E-016 0.2886751346 0.4082482905 0.2886751346
-0.2041241452 0.3535533906 -0.4082482905 -0.3535533906 0.2041241452 -9.45E-017 -0.2041241452 0.3535533906 -0.4082482905 -0.3535533906 -0.2041241452
-0.1056624327 0.2041241452 -0.2886751346 -0.3535533906 0.3943375673 -0.4082482905 0.3943375673 -0.3535533906 0.2886751346 0.2041241452 0.1056624327

 

The C code with MKL:
char jobz = 'V';
char uplo = 'U';
m = 11

LAPACKE_dsyev(LAPACK_ROW_MAJOR,jobz, uplo,   m,  temp, m,w);

Output from C code:

0.105662, -0.204124, -0.288675, 0.353553, -0.394338, 0.408248, -0.394338, 0.353553, -0.288675, 0.204124, -0.105662,;
0.204124, -0.353553, -0.408248, 0.353553, -0.204124, -0.000000, 0.204124, -0.353553, 0.408248, -0.353553, 0.204124,;
0.288675, -0.408248, -0.288675, 0.000000, 0.288675, -0.408248, 0.288675, -0.000000, -0.288675, 0.408248, -0.288675,;
0.353553, -0.353553, 0.000000, -0.353553, 0.353553, 0.000000, -0.353553, 0.353553, 0.000000, -0.353553, 0.353553,;
0.394338, -0.204124, 0.288675, -0.353553, -0.105662, 0.408248, -0.105662, -0.353553, 0.288675, 0.204124, -0.394338,;
0.408248, 0.000000, 0.408248, 0.000000, -0.408248, -0.000000, 0.408248, 0.000000, -0.408248, -0.000000, 0.408248,;
0.394338, 0.204124, 0.288675, 0.353553, -0.105662, -0.408248, -0.105662, 0.353553, 0.288675, -0.204124, -0.394338,;
0.353553, 0.353553, -0.000000, 0.353553, 0.353553, 0.000000, -0.353553, -0.353553, -0.000000, 0.353553, 0.353553,;
0.288675, 0.408248, -0.288675, -0.000000, 0.288675, 0.408248, 0.288675, -0.000000, -0.288675, -0.408248, -0.288675,;
0.204124, 0.353553, -0.408248, -0.353553, -0.204124, -0.000000, 0.204124, 0.353553, 0.408248, 0.353553, 0.204124,;
0.105662, 0.204124, -0.288675, -0.353553, -0.394338, -0.408248, -0.394338, -0.353553, -0.288675, -0.204124, -0.105662,;

Compiler options:

-L/opt/intel/composer_xe_2015.3.187/mkl/lib/intel64 -lmkl_intel_ilp64 -lmkl_core -lmkl_sequential -lpthread -D MKL  -DMKL_ILP64 -openmp - I/opt/intel/composer_xe_2015.3.187/mkl/include -g -traceback -O0  -debug all -traceback -debug all  -D INTEL

 

 Best reagrds.

 

0 Kudos
Ying_H_Intel
Employee
500 Views

Hi Fabio A, 

I can see the result with c code. will investigate  it and update you if any result. 

Thanks

Ying

0 Kudos
Alexander_K_Intel3
500 Views

There is no error in that. Eigenvectors for both cases correct, since A*v(j) = lambda(j)*v(j), and thus eigenvectors are sign irrelevant.
Different sign could be results of roundoff errors, resulted by different array alignments in the code.

Best regards,
Alexander

 

0 Kudos
mecej4
Honored Contributor III
500 Views

Fábio, here is what I suggest as a solution for your complaint about 'wrong' signs for eigenvectors.

Although in principle the eigenvectors can be multiplied by an arbitrary (but not zero) constant, I can see that imposing some scaling convention can be useful when you want to compare results from different eigenvalue-eigenvector decomposition routines.

To impose such a convention, all that you have to do is, for example, to scale each eigenvector returned by DSYEV or LAPACKE_dsyev by the 2-norm of that vector and make the largest magnitude element of the vector positive.

0 Kudos
Reply