|
Boost : |
From: Zdenek Hurak (z.hurak_at_[hidden])
Date: 2003-05-13 08:59:42
Hello Patrick,
I would be pretty much happy to learn that my testing code includes some
blunder:
==============================start of listing=============================
#include <iostream>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <boost/timer.hpp>
//g++ bench.cc -o test -I/usr/local/lib/boost_1_29_0/ -O3 -DNDEBUG
namespace ublas = boost::numeric::ublas;
using namespace std;
//using namespace ublas;
int main(int argc, char *argv[]) {
int size;
if (argc < 2)
size = 100;
else {
size = atoi(argv[1]);
if (size == 0) {
cout << "wrong input argument" << endl;
return 0;
}
}
boost::timer t;
double time;
ublas::matrix<double> A(size,size), B(size,size), C(size,
size), D(size,size), X(size,size);
for(int i = 0; i<size; i++)
for(int j = 0; j<size; j++) {
A(i,j) = 1.0*rand();
B(i,j) = 1.0*rand();
C(i,j) = 1.0*rand();
D(i,j) = 1.0*rand();
}
cout << "size of metrices - " << size << "x" << size << endl;
// A*B
cout << "computing X = A*B" << endl;
t.restart();
X = prod(A,B);
time = t.elapsed();
cout << "elapsed time - " << time << "s" << endl << endl;
// A*B*C
cout << "computing X = A*B*C" << endl;
t.restart();
//X = prod(A, prod(B,C)); // - !!!!!!!!!!!
X = prod(A, ublas::matrix<double> (prod(B,C)));
time = t.elapsed();
cout << "elapsed time - " << time << "s" << endl << endl;
// A*B*C*D
cout << "computing X = A*B*C*D" << endl;
t.restart();
//B = prod(A ,prod(B, prod(C,D))); // !!!!!!!!!
X = prod(A, ublas::matrix<double> (prod(B, ublas::matrix<d
ouble> (prod(C,D)))));
time = t.elapsed();
cout << "elapsed time - " << time << "s" << endl;
cout << "end" << endl;
return 0;
}
==============================end of listing=============================
Best regards,
Zdenek Hurak
Patrick Kowalzick wrote:
> Thats really interesting and I got quite shocked. So I multiplied two
> matrices with uBlas. I was too lazy to compile a non debug version, so it
> is really not optimized. While I never get my profiler to do what I want I
> counted the seconds ;-).
>
> It took less than 5 sec for the multiplication of 2000x2000 and less than
> 1 sec for 1000x1000. 5000x5000 took about a minute but it swapped all the
> time.
>
> I have 256MB memory and hmm, i do not know but I think 1.6Ghz P4 and a
> Riva TNT2 ;-).
>
> Not any more shocked,
> Patrick
>
> "Zden?k Hurák" <z.hurak_at_[hidden]> wrote in message
> news:b9o3k5$bcm$1_at_main.gmane.org...
>> Dear uBLAS friends,
>>
>> I have performed some benchmarking on matrix multiplication and compared
>> results for uBLAS, Matlab 6.5, Matlab 5.3 and ATLAS. The results are
>> quite surprising. If anybody is interested, I can send him/her an
>> electronic
> copy
>> (in pdf) of the tests.
>>
>> An excerpt (possibly not nicely aligned) summarizing computation times
>> for matrix multiplication (in seconds) and the details on computational
> platform
>> are pasted bellow.
>>
>> Please, have a look at this. It is really very disapointing. Note that I
>> switched NDEBUG correctly for this test and yet the multiplication of two
>> matrices of size 1000 x 1000 takes about 2 seconds in Matlab but about 40
>> seconds in uBLAS. ATLAS needs 1 second only on my machine. For matrices
> 2000
>> x 2000 Matlab needs about 20 seconds but uBLAS need sixty times more
>> (1139 s). ATLAS only requires 10 seconds. Is this in agreement with your
>> own experience?
>>
>> Are there any other things that I have to switch on or off to make uBLAS
> run
>> reasonably fast? I believe that this huge gap in performance cannot only
> be
>> caused by some cache issue. Or can it? Sixty times slower than Matlab? I
> am
>> looking forward to reading your experience with competitivness of uBLAS
>> performance.
>>
>>
>> size of matrices 500x500 MATLAB6.5 MATLAB5.3 uBLAS ATLAS:
>> X = A*B: 0.313 2.5 3.7 0.17
>>
>> X = A*B*C: 0.625 5 7.41
>>
>> X = A*B*C*D: 0.937 7.5 11.5
>>
>> size of matrices 750x750 MATLAB MATLAB uBLAS ATLAS:
>>
>> X = A*B: 1.047 8.17 14.33 0.53
>>
>> X = A*B*C: 2.078 16.32 28.47
>>
>> X = A*B*C*D: 3.14 24.52 42.95
>>
>> size of matrices 1000x1000 MATLAB MATLAB uBLAS ATLAS:
>>
>> X = A*B: 2.375 19.3 39.5 1.22
>>
>> X = A*B*C: 4.829 38.61 78.4
>>
>> X = A*B*C*D: 7.125 57.84 117.8
>>
>> size of matrices 2000x2000 MATLAB MATLAB uBLAS ATLAS:
>>
>> X = A*B: 19.328 151 1139 9.27
>>
>> X = A*B*C: 38.735
>>
>> X = A*B*C*D: 58.062
>>
>> testing architecture AMD Duron 1,2GHz, 512MB SDRAM
>>
>> MATLAB version - 6.5.0.180913a (R13), OS - WinXP
>>
>> MATLAB 5.3 version - 5.3.1.29215a (R11.1), OS - WinXP
>>
>> UBLAS version - 2003_05_10, OS - Red Hat Linux 9, compiler - G++ (GCC)
> 3.2.2
>>
>> ATLAS version - 3.4.1, OS - Red Hat Linux 9, compiler - G++ (GCC) 3.2.2
>>
>>
>>
--------------------------------------------------------------------------
> --
>> -------------------------------
>> Zdenek Hurak
>> Center for Applied Cybernetics, Czech Technical University
>>
--------------------------------------------------------------------------
> --
>> -------------------------------
>>
>>
>> ---
>> Odchozí zpráva neobsahuje viry.
>> Zkontrolováno antivirovým systémem AVG (http://www.grisoft.cz).
>> Verze: 6.0.476 / Virová báze: 273 - datum vydání: 24.4.2003
>>
>>
>>
>> _______________________________________________
>> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>>
>
>
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk