Boost logo

Ublas :

From: Joris Peeters (peeters.joris_at_[hidden])
Date: 2006-01-03 08:26:48


Hello,

I'm compiling my program with g++ 4.0.2 on an Ubunt-machine (pentium IV). When I compile everything without any optimization flags, i get correct results. When I then try to run the same program with -O1 as a compiler-flag, the results are slightly different and accumulate to a completely useless outcome. I am relatively unexperienced with programming, so my conclusions may be wrong, but I have isolated at least one instance which I believe to be due to ublas. The code I compared, for instance, is this (it is not efficient, but it's for testing-purposes):

matrix<complex<double> > sub = prod(herm(B),B); //test1
double result = real(sub(0,0));

int N=B.size1(); //test2
double result2=0;
for (int c1=0;c1<N;c1++)
    result2+= real(conj(B(c1,0))*B(c1,0));

B is a matrix of size N x 1 (i could have used a vector, i know). The elements are of type complex<double>.

When i run this with -O0 result equals result2. When I run this with -O1 the two numbers differ (not much, only from the 12th number behind the comma do they drift apart)
There are many more instances where results differ between -O0 and -O1 and I'm not sure whether they are all due to ublas (if any is due to ublas at all, although the above example seems to suggest that), because I have not yet isolated them.
Has anyone experienced this as well, or something similar? I would very much appreciate any suggestions, as running the code with the optimization flags does have a large effect on the speed of the program.

I have manually added all the optimization flags of -O1, but the weird thing is that -O0 and running the program with all the optimization flags, without explicitly stating it as -O1, gives the same numeric result, allthough with almost no gain in speed.

Kind regards,
 Joris Peeters