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

Error svd result is different between singlethread and multithreads

xlds1994
Beginner
1,469 Views

I use LAPACKE_zgesdd(LAPACK_ROW_MAJOR, 'A', m, n, a, n, s, u, m, v, n) compute svd for a matrix.

But the result is different between singlethread and multithreads. I compute md5 for the result. They are all different.

I try mkl version 2023.1, 2021.4 & 2022.1, all of these have this error.picture1.PNG

Labels (1)
0 Kudos
5 Replies
xlds1994
Beginner
1,465 Views

my code and CMakeLists are here

#include <mkl.h>
#include <iostream>
#include <fstream>
#include <istream>
#include <complex>

using namespace std;

int main(){

int inputsize=41*41;
ifstream input("input.svd");
complex<double>* svndinput=(complex<double>*)malloc(inputsize*inputsize*sizeof(complex<double>));
input.read((char*)svndinput, inputsize*inputsize*sizeof(complex<double>));
input.close();

int m=inputsize;
int n=inputsize;
complex<double>* a=svndinput;
complex<double>* u=new complex<double>[inputsize*inputsize]();
complex<double>* v=new complex<double>[inputsize*inputsize]();
double* s=new double[inputsize]();

typedef lapack_complex_double lcd;
auto result=LAPACKE_zgesdd(LAPACK_ROW_MAJOR, 'A', m, n, (lcd*)a, n, (double*)s, (lcd*)u, m, (lcd*)v, n);
cout<<"result: "<<result<<endl;

ofstream saves("s.svd");
saves.write((char*)s, inputsize*sizeof(s[0]));
saves.flush();
saves.close();

ofstream savev("v.svd");
savev.write((char*)v, inputsize*inputsize*sizeof(v[0]));
savev.flush();
savev.close();

 

return 0;
}

 

CMakeLists

project (Demo2)

add_compile_options(-fPIC)


SET(INTEL_MKL_INSTALL_DIR "/opt/intel/oneapi/mkl/latest")

SET(MKL_LINK static)
find_package(MKL PATHS /opt/intel/oneapi/mkl/latest NO_DEFAULT_PATH)
INCLUDE_DIRECTORIES(/home/grp4data/anaconda3/envs/smitopc20221111/include)
INCLUDE_DIRECTORIES(${MKL_INCLUDE})

add_executable(testsvd main.cpp)
target_link_libraries(testsvd $<LINK_ONLY:MKL::MKL>)

0 Kudos
ShanmukhS_Intel
Moderator
1,386 Views

Hi,

 

Thanks for posting in Intel communities. We have run the shared files and have generated the testsvd, s.svd, v.svd files which results 0 as mentioned below. Could please let us know the actual vs expected results of your issue? In addition, We could see an input.svd being generated at your end which was not generated in our environment. Could you please let us know the significance of that file? It would be a great help if you provide if (if it was missing here)

 

-- Configuring done

-- Generating done

-- Build files have been written to: /home/<uname>/shan/mkl/05907190/build

 

Scanning dependencies of target testsvd

[ 50%] Building CXX object CMakeFiles/testsvd.dir/main.cpp.o

[100%] Linking CXX executable testsvd

[100%] Built target testsvd

 

path:~/shan/mkl/05907190/build$ taskset 0xFF ./testsvd

result: 0

path:~/shan/mkl/05907190/build$ taskset 0x3 ./testsvd

result: 0

path:~/shan/mkl/05907190/build$ taskset 0xF ./testsvd

result: 0

 

Best Regards,

Shanmukh.SS

 

0 Kudos
xlds1994
Beginner
1,372 Views

I put demo.tar.gz in attachment, when you decompress it, you will see main.cpp CMakeLists.txt and input.svd. Then you should compile them use cmake. And then, you should put 'input.svd' and executable file 'testsvd' in same dir. 

cout result 0 means the svd is successful.

Please use 'taskset 0x01 ./testsvd ' to execute 'testsvd', it means use one cpu for this executable. then you will get the output s.svd and v.svd, please use md5sum compute the md5 of these file and remeber these.

Then use 'taskset 0x03 ./testsvd ' to execute 'testsvd', it means use two cpu for this executable. then you will get the output s.svd and v.svd, please use md5sum compute the md5 of these file and remeber these. 

you will find the result s.svd and v.svd between twice commend are different. you can see the result I had tried before in the first floor image.

I try 1,2,4,8 thread for LAPACKE_zgesdd, the result are all different. I think this is a serious bug. For a parallel computing library, the first thing to ensure is that the result is exactly the same as a single thread.

If you think my description is not clear enough, please contact me in time.

0 Kudos
Gennady_F_Intel
Moderator
1,297 Views

As you compare the output results by md5sum hash function, I ques you would like to have bit to bit outputs.

It is not possible with the current version of MKL for ?gesdd routine.

MKL doesn’t guarantee that results are identical under normal (non-CNR) mode.

Please check MKL Developer Guide follow this link: https://www.intel.com/content/www/us/en/docs/onemkl/developer-guide-linux/2023-0/reproducibility-conditions.html.

 

With CNR mode you could obtain the same results from run to run with some conditions and one of such conditions is using the same number of OpenMP threads from run to run.

Therefore, applying sequential and multithreaded modes You will not obtain exactly the same results from run – to – run.

-Gennady

0 Kudos
ShanmukhS_Intel
Moderator
1,243 Views

Hi,


A gentle reminder:

Has the information provided helped? If this resolves your issue, please accept this as a solution. It would help other users with similar issues.


Best Regards,

Shanmukh.SS



0 Kudos
Reply