Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Thomas8
Beginner
94 Views

Unexpected Behaviour of Intel Composer XE-2011

Jump to solution
Hi

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( 10, 0. );
agts_ = vector( 10, 0. );
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 bgts_;
std::vector agts_;
double range_;
};

int main()
{
// method 1:
Ggb fgb_;
double range = 8.02;
std::vector params;
params.push_back(range);
fgb_.initialize(params);
cout << "method 1" << endl;
fgb_.main();

// method 2:
std::vector bgts_ = vector( 10, 0. );
std::vector agts_ = vector( 10, 0. );
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




IntelRelease
Win32






{D2204995-77F0-4ABE-A62D-3810C790F5E6}
xxxLibTestServer
Win32Proj
IntelBug



Application
Unicode
Intel C++ Compiler XE 12.0










<_ProjectFileVersion>10.0.30319.1

$(Configuration)\\
$(Configuration)\\
false
true







%(AdditionalIncludeDirectories)
_WIN32_WINNT;%(PreprocessorDefinitions)
MultiThreadedDLL
false
true


Level3
ProgramDatabase
true
false


wsock32.lib;%(AdditionalDependencies)
$(Configuration)\\Server\\Bug-i.exe
%(AdditionalLibraryDirectories)
false
Console




MachineX86






0 Kudos
1 Solution
Hubert_H_Intel
Employee
94 Views
Thomas,
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.

View solution in original post

9 Replies
Hubert_H_Intel
Employee
94 Views

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.

Hubert_H_Intel
Employee
95 Views
Thomas,
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.

View solution in original post

Andreas_Klaedtke
Beginner
94 Views
Thomas,

A comment, but I am not sure if it helps with your actual problem.
You did not include , but you use exp. If I am not mistaken, this requires cmath.

Regards
Andreas
Thomas8
Beginner
94 Views
Andreas

thanks. The code i submitted compiled ok without including cmath.
Including cmath did not change the behaviour.

Kind Regards
Thomas8
Beginner
94 Views
Hubert

thanks for the update. The additional compiler option cures the problem.
If there are any new developments, please keep me posted.

Kind Regards
Hubert_H_Intel
Employee
94 Views

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.

Thomas8
Beginner
94 Views
Hello Hubert

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
Hubert_H_Intel
Employee
94 Views
Thomas,
Sorry for not having come back to this earlier. I'll check.
Hubert.
Hubert_H_Intel
Employee
94 Views
Thomas,
The problem is fixed in newer versions of the compiler. Let me check when the next release including this bugfix will be available.
Hubert.
Reply