- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
i am using Intel C++ Compiler XE version 12.0 Update 1 for Windows
with Visual Studio 2010 integration. I wrote a piece of C++ code that
produced incorrect results upon compilation. The attached program
illustrates the problem: Two vectors of doubles are calculated. The vectors
should contain identical elements. In method 1 i construct the vectors inside
a class, in vector 2 they are constructed in the main program. The two methods
lead to different results!! The results of method 1 clearly are incorrect!
Grateful if anyone could explain what i am doing wrong. I insert the .cpp source,
the results i am getting and the project file below (they are reasonably small).
Thanks & Regards
.CPP - FILE
//----------------------------------------------------------------
#include
#include
#include
using namespace std;
class Ggb
{
public:
Ggb() {};
void initialize( std::vector< double > const& params )
{
range_ = params[0];
bgts_ = vector
agts_ = vector
double norm = 0.;
for( int i = 0; i < 10; ++i )
{
double x = exp( (double)(i) - range_ );
bgts_ = 0.5 * (1. - (x-1./x)/(x+1./x));
norm += bgts_;
}
for( int i = 0; i < 10; ++i )
{
bgts_ /= norm;
agts_ = bgts_;
}
}
void main()
{
for( int i = 0; i < 10; ++i )
cout << i << '\\t' << setprecision(6) << bgts_ << '\\t' << agts_ << endl;
}
private:
std::vector
std::vector
double range_;
};
int main()
{
// method 1:
Ggb fgb_;
double range = 8.02;
std::vector
params.push_back(range);
fgb_.initialize(params);
cout << "method 1" << endl;
fgb_.main();
// method 2:
std::vector
std::vector
double norm = 0.;
for( int i = 0; i < 10; ++i )
{
double x = exp( (double)(i) - range );
bgts_ = 0.5 * (1. - (x-1./x)/(x+1./x));
norm += bgts_;
}
for( int i = 0; i < 10; ++i )
{
bgts_ /= norm;
agts_ = bgts_;
}
cout << "method 2" << endl;
for( int i = 0; i < 10; ++i )
cout << i << '\\t' << setprecision(6) << bgts_ << '\\t' << agts_ << endl;
return 0;
}
//----------------------------------------------------------------
OUTPUT:
method 1
0 0.11767 1
1 0.11767 0.999999
2 0.117669 0.999994
3 0.117665 0.999956
4 0.117632 0.999678
5 0.11739 0.997624
6 0.115635 0.982707
7 0.10413 0.884933
8 0.0600114 0.509999
9 0.0145283 0.123467
method 2
0 0.11767 0.11767
1 0.11767 0.11767
2 0.117669 0.117669
3 0.117665 0.117665
4 0.117632 0.117632
5 0.11739 0.11739
6 0.115635 0.115635
7 0.10413 0.10413
8 0.0600114 0.0600114
9 0.0145283 0.0145283
VISUAL STUDIO PROJECT-FILE
<_ProjectFileVersion>10.0.30319.1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It looks like an optimizer bug in the IA-32 compiler. Investigation is still ongoing and once it's nailed down I'll enter a defect in our database. For now you could add compiler option /Qinline-forceinline as a temporary workaround.
Does this help?
Hubert.
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thomas,
I see this problem on IA32 only with optimizations /O2 or /O3. No problem on 64-bit (Intel 64) platforms.
Let me check.
Regards, Hubert.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
It looks like an optimizer bug in the IA-32 compiler. Investigation is still ongoing and once it's nailed down I'll enter a defect in our database. For now you could add compiler option /Qinline-forceinline as a temporary workaround.
Does this help?
Hubert.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
A comment, but I am not sure if it helps with your actual problem.
You did not include
Regards
Andreas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks. The code i submitted compiled ok without including cmath.
Including cmath did not change the behaviour.
Kind Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
thanks for the update. The additional compiler option cures the problem.
If there are any new developments, please keep me posted.
Kind Regards
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Thomas,
I'll inform you once we have a compiler update with a fix for the problem.
Meanwhile you can apply another workaround with no impact for the application (while /Qinline-forceinline might have side effects since it forces the compiler to inline in any case whereas otherwise it's at the compiler's discretion whether it's goodto inline or not).
The crucial part is the loop
for( int i = 0; i < 10; ++i )
{
bgts_ /= norm;
agts_ = bgts_;
}
within initialize(). Since it's an optimization bug, you can make the loop-local variable i static
for( static int i = 0; ......
to protect it against any high-level optimizations that affects the calculation of the vector array agts_. 'i' has very low trip count and so this workaround will not have any performance impact on the application.
Hubert.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
it's been a while since we discussed the compiler problem described above in this thread
which you identified as a IA 32 optimization bug.
I would like to ask whether there is any news on compiler updates which include a fix for
this problem. Any feedback is highly appreciated.
Thanks & Regards
Thomas
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry for not having come back to this earlier. I'll check.
Hubert.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
The problem is fixed in newer versions of the compiler. Let me check when the next release including this bugfix will be available.
Hubert.

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page