error in big matrix multiplication

1 回表示 (過去 30 日間)
TOSA2016
TOSA2016 2017 年 5 月 3 日
コメント済み: Walter Roberson 2017 年 5 月 3 日
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.

回答 (1 件)

Walter Roberson
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 件のコメント
TOSA2016
TOSA2016 2017 年 5 月 3 日
Is using GPU makes this worse due to data structure it is using?
Walter Roberson
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 ExchangeGPU Computing についてさらに検索

タグ

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by