Convergence problems with Intel's 8.0 C++ compiler
Felix E. Klee
felix.klee.gmp at gmx.net
Thu Feb 26 22:28:56 CET 2004
On 25 Feb 2004 16:16:24 +0100 Torbjorn Granlund wrote:
> Most likely bugs in one of the compilers.
No, fortunately not. After some debugging, I found that the culprit
seems to be the C++ "complex" class. GCC includes a different
implementation than ICC. The way they initialize and store the real and
imaginary parts is illustrated below.
template<typename type> class ICC_complex_tp {
public:
ICC_complex_tp(const type &re, const type &im) {
z[0] = re, z[1] = im;
}
type real() { return z[0]; }
type imag() { return z[1]; }
private:
type z[2];
};
template<typename type> class GCC_complex_tp {
public:
GCC_complex_tp(const type &re, const type &im) : r(re), i(im) {}
type real() { return r; }
type imag() { return i; }
private:
type r, i;
};
The result is that, in the ICC case, the precision of the real and
imaginary parts is the default MPF precision. In the GCC case, the
precision of the real and imaginary parts is the precision of the MPF
values that were used for initialization.
Obviously, the ICC implementation isn't very suitable for MPF
calculations. Which version is standards conforming, though? Looking at
the C++ standard, I'm not quite sure. It sais that the postcondition of
the constructor must be
real() == re && image() == im
Because of the design of the MPF class this condition is satisfied with
both classes, so it doesn't answer the question. In addition, one can
always create a data type that breaks the postcondition for either
implementation. I guess, I'll take that issue to the C++ news group.
Now, how can I circumvent the problem if I don't want the outcome of the
simulation to be dependent on the implemenation of the complex class?
Three possibilities come into my mind:
1. Specialize the complex class for MPF types (probably too much
trouble).
2. Build a simple complex_MPF implementation (seems to be feasible).
3. Eliminate all complex number arithmetics (also feasible).
> You can always play with optimization levels.
First, I want the program to run realiably with optimizations turned off
(-O0).
Felix
PS: Torbjorn, the moderation bit is set to?
PPS: To contact me off list don't reply but send mail to "felix.klee" at
the domain "inka.de". Otherwise your email to me might get automatically
deleted!
More information about the gmp-discuss
mailing list