Path: news.mathworks.com!not-for-mail
From: "Victor kasaksha" <viphe@mail.ru>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Is it a bug or what is it?
Date: Mon, 28 Sep 2009 12:20:19 +0000 (UTC)
Organization: TU
Lines: 66
Message-ID: <h9q9m3$fe5$1@fred.mathworks.com>
References: <h9f9u0$elc$1@fred.mathworks.com> <h9hrk6$plp$1@fred.mathworks.com> <h9hs6v$46e$1@fred.mathworks.com> <h9iaad$p3i$1@fred.mathworks.com> <h9ic4f$ng6$1@fred.mathworks.com> <h9icla$aa$1@fred.mathworks.com> <h9ijb2$7dp$1@fred.mathworks.com> <h9in8n$198$1@fred.mathworks.com> <h9iocc$ge4$1@fred.mathworks.com> <h9is4a$r9p$1@fred.mathworks.com> <h9j0dl$enm$1@fred.mathworks.com> <h9p9a4$8gr$1@fred.mathworks.com>
Reply-To: "Victor kasaksha" <viphe@mail.ru>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1254140419 15813 172.30.248.37 (28 Sep 2009 12:20:19 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Mon, 28 Sep 2009 12:20:19 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1369356
Xref: news.mathworks.com comp.soft-sys.matlab:573328

Hello all, I apologize for the late answer:

first: 
----------------------------------------------------------------------------------------
which mtimes
built-in (/usr/local/matlab09b/toolbox/matlab/ops/@double/mtimes)  % double method

which rand
built-in (/usr/local/matlab09b/toolbox/matlab/randfun/rand)
-----------------------------------------------------------------------------------------

second:
-----------------------------------------------------------------------------------------
consider/execute following code:

n = 2000;

a = 1e8; b = 2e8;

A = a + (b - a).*rand(n,'single');
B = a + (b - a).*rand(n,'single');
A = mod(A,10);
B = mod(B,10);

maxnumcompthreads(1);
Cs1 = A*B;
Cd1 = double(A)*double(B);

maxnumcompthreads(2);
Cs2 = A*B;
Cd2 = double(A)*double(B);

Aint = uint32(A);
Bint = uint32(B);
Cint = uint32(zeros(n));
i = 1;
for j = 1:n
    for k = 1:n
        Cint(i,j) = Cint(i,j) + Aint(i,k)*Bint(k,j);
    end
end

isequal(Cs1,Cs2)
isequal(Cd1,Cd2)

Cd1(1,100)
Cd2(1,100)
Cint(1,100)

ans =
     1 %-> single is O.K.
ans =
     0 %-> double is not O.K.
ans =
       32288 % one thread is wrong
ans =
       31504 % 2 threads and 
ans =
       31504 % my own integer computation are equal, 
                   % so I think single thread product  is wrong

---------------------------------------------------------------------------
third: code from above produces:

md= 0/1999
OK