Different results on different computers, Matlab 2021b - 64 bit, windows 64 bit, both Intel chips
Mostrar comentarios más antiguos
Hello together,
I was testing some code on two different machines, both 64 bit windows, both Matlab 2021b with 64 bit.
I was suprised, that a simple operation with the same variables, the same precision, reproduces slightly different results.
It is not a huge operation, actually just a matrix vector multiplication of a vector A with size 1x16 and a matrix B with 16x3, both in single format, resulting in a vector C of 1x3.
I tested the bit representation of both, the vector A and the matrix B entries, and they are exactly the same.
But when I perform the matrix vector multiplication C = A*B; , the first entry is different on the two machines.
The funny thing is, that, when I perform C(1) = A*B(:,1); I get the same value on both machines, and I get also the same value (but the other different result) when I perform C(1) = sum(A.*B(:,1)');
So summarized:
- when I perform C = A*B, the first entries are different on the two machines ('10111101111101110110011011110110' and '10111101111101110110011011111000')
- when I perform C(1) = A*B(:,1), the values are the same on the two machines ('10111101111101110110011011111000')
- when I perform C(1) = sum(A.*B(:,1)'), the values are the same on the two machines ('10111101111101110110011011110110')
How does this come, and which value to trust?
Thanks!
4 comentarios
Walter Roberson
el 1 de Dic. de 2021
Does one have AMD and the other one have Intel?
Roman Foell
el 1 de Dic. de 2021
Editada: Roman Foell
el 2 de Dic. de 2021
Roman Foell
el 1 de Dic. de 2021
Editada: Roman Foell
el 1 de Dic. de 2021
James Tursa
el 1 de Dic. de 2021
Editada: James Tursa
el 1 de Dic. de 2021
Can you post some actual small examples that demonstrate this? Either post the hex versions of the numbers, or maybe a mat file. I.e., post something so that we can use the exact same numbers to start with.
Do the two machines use different BLAS libraries? Or maybe the floating point rounding mode is set differently on the two machines for some reason.
Respuesta aceptada
Más respuestas (1)
Roman Foell
el 1 de Dic. de 2021
Editada: Roman Foell
el 2 de Dic. de 2021
0 votos
6 comentarios
Roman Foell
el 5 de Dic. de 2021
I can reproduce the results (R2021a+b, i7-3635QM)
>> whos A, whos B
Name Size Bytes Class Attributes
A 1x16 64 single
Name Size Bytes Class Attributes
B 16x3 192 single
>> dec2bin(typecast( (A*B) * [1;0;0], 'uint32'))
ans =
'10111101111101110110011011110110'
>> dec2bin(typecast( A*B(:,1), 'uint32'))
ans =
'10111101111101110110011011111000'
>> dec2bin(typecast( sum(A.*B(:,1)'), 'uint32'))
ans =
'10111101111101110110011011110110'
>> N1 = (A*B) * [1;0;0] - A*B(:,1)
N1 =
single
1.4901e-08
Roman Foell
el 6 de Dic. de 2021
Editada: Roman Foell
el 6 de Dic. de 2021
Roman Foell
el 6 de Dic. de 2021
Editada: Roman Foell
el 6 de Dic. de 2021
Andres
el 7 de Dic. de 2021
I can also confirm different results on different computers.
Matlab Online gave the same results as in my previous comment, but
R2020a and R2021b on Intel(R) Core(TM) i5-7300U:
C1 = dec2bin(typecast( (A*B) * [1;0;0], 'uint32'))
C2 = dec2bin(typecast( A*B(:,1), 'uint32'))
C3 = dec2bin(typecast( sum(A.*B(:,1)'), 'uint32'))
N1 = (A*B) * [1;0;0] - A*B(:,1)
C1 =
'10111101111101110110011011111000'
C2 =
'10111101111101110110011011111000'
C3 =
'10111101111101110110011011110110'
N1 =
single
0
Roman Foell
el 7 de Dic. de 2021
Categorías
Más información sobre Sources en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!