error in big matrix multiplication
4 ビュー (過去 30 日間)
古いコメントを表示
I have two matrices as Q a 4-by-4 matrix and x as a 4-by-10000 matrix . When I compute the multiplication as
Ans1 = Q * x;
the answer is different than having a for loop like
for i = 1 :10000
Ans2(:,i) = Q * x(:,i);
end
The order of error (Ans1 - Ans2) is 1e-16 for my special case of Q and x. I know it is small but I was wondering what is the source of this error and how I can eliminate it.
0 件のコメント
回答 (1 件)
Walter Roberson
2017 年 5 月 3 日
編集済み: Walter Roberson
2017 年 5 月 3 日
The 4*10000 case would be delegated to the highly optimized multi-threaded libraries such as LINPACK or BLAS. The additions could end up being done in a different order, leading to a slightly different round-off result. Also, potentially the highly optimized libraries could use an instruction such as Fused Multiply And Add, which does one fewer rounding operations, potentially leading to a more accurate -- but different -- result.
2 件のコメント
Walter Roberson
2017 年 5 月 3 日
What I described above does not use GPU.
If you are using gpuarray() or calling into gpu kernels you have built, then the result can certainly differ compared to serial operations.
Serial operations are not necessarily any more accurate than parallel operations. Even just for addition, you need special computation routines to achieve the effect of the rounding coming out as if the precision of the operands was indefinitely long. Knuth has a routine in The Art Of Computer Programming; unfortunately I never did understand how that routine worked.
参考
カテゴリ
Help Center および File Exchange で GPU Computing についてさらに検索
製品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!