- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hello!
I use Intel C++ compiler 64 bit Professional Build 20090827 Package ID: l_cproc_p_11.1.056 running on Linux x86_64.
I wrote the following program:
#include
#include
const int N = 10;
class LUTest {
public:
double a;
//
LUTest()
{
srand(25);
for(int i=0; i for(int j=0; j a = rand() % N;
}
void LU()
{
for(int i=0; i for(int j=i+1; j a /= a;
a[i+1] -= a[i+1]*a;
// std::cout << a[i+1];
}
for(int j=i+2; j for(int k=i+1; k a -= a*a;
}
}
void save()
{
std::ofstream f;
//
f.open("test.out");
for(int i=0; i for(int j=0; j f << a << std::endl;
f.close();
}
};
int main()
{
LUTest test;
//
test.LU();
test.save();
//
return 0;
}
Now, if I compile it with -O0 or -O1 options, then it works fine and produce correct results. However, if I try to compile it with -O2 or -O3 options, then it produce another (incorrect) results.
Further, if you uncomment the line with "std::cout", then it'll produce correct results even with -O2 or -O3 options. Can it be the bug in loops optimization?
Thank you.
Sergey
I use Intel C++ compiler 64 bit Professional Build 20090827 Package ID: l_cproc_p_11.1.056 running on Linux x86_64.
I wrote the following program:
#include
#include
const int N = 10;
class LUTest {
public:
double a
//
LUTest()
{
srand(25);
for(int i=0; i
}
void LU()
{
for(int i=0; i
a[i+1]
// std::cout << a[i+1]
}
for(int j=i+2; j
}
}
void save()
{
std::ofstream f;
//
f.open("test.out");
for(int i=0; i
f.close();
}
};
int main()
{
LUTest test;
//
test.LU();
test.save();
//
return 0;
}
Now, if I compile it with -O0 or -O1 options, then it works fine and produce correct results. However, if I try to compile it with -O2 or -O3 options, then it produce another (incorrect) results.
Further, if you uncomment the line with "std::cout", then it'll produce correct results even with -O2 or -O3 options. Can it be the bug in loops optimization?
Thank you.
Sergey
1 Solution
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry to get to you so late.
Yes, it's a bug in the vectorizer. I'll file a bug report for it.
Adding the "cout ..." turns off the optimization. That's why it works. Or you can add "#pragma novector" in front of the loop and it should work around the problem as well.
Thanks,
Jennifer
Yes, it's a bug in the vectorizer. I'll file a bug report for it.
Adding the "cout ..." turns off the optimization. That's why it works. Or you can add "#pragma novector" in front of the loop and it should work around the problem as well.
Thanks,
Jennifer
Link Copied
8 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
[cpp]>>a[i+1]-= a[i+1]*a ;
[/cpp]
On last iteration of i, you are indexing outside the bounds of the array (that is one problem)
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - jimdempseyatthecove
[cpp]>>a[i+1]-= a[i+1]*a ;
[/cpp]
On last iteration of i, you are indexing outside the bounds of the array (that is one problem)
Jim
Hello Jim,
Thank you for reply.
I don't think that I'm indexing outside the bounds of the array. The last iteration of i is when i = N-1. In that case, j=i+1 = N-1+1 = N. So j = N, the condition j
Sergey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry to get to you so late.
Yes, it's a bug in the vectorizer. I'll file a bug report for it.
Adding the "cout ..." turns off the optimization. That's why it works. Or you can add "#pragma novector" in front of the loop and it should work around the problem as well.
Thanks,
Jennifer
Yes, it's a bug in the vectorizer. I'll file a bug report for it.
Adding the "cout ..." turns off the optimization. That's why it works. Or you can add "#pragma novector" in front of the loop and it should work around the problem as well.
Thanks,
Jennifer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
a is dimensioned
void LU()
{
for(int i=0; i
a[i+1]
// std::cout << a[i+1]
}
On last iteration of i, the for j loop will write an entire row of a[row][col] beyond array bounds when executing
a[i+1]
IOW you will be depositing into
a
Jim Dempsey
P.S. A close brace } seems to be missing from your posted code.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Quoting - jimdempseyatthecove
a is dimensioned (indexes (0:N-1, 0:N-1)
On last iteration of i, the for j loop will write an entire row of a[row][col] beyond array bounds when executing
a[i+1] -= a[i+1]*a;
IOW you will be depositing into
a -= a*a[N-1];
On last iteration of i, the for j loop will write an entire row of a[row][col] beyond array bounds when executing
a[i+1]
IOW you will be depositing into
a
If expand the last two iterations of "i", they're like following.
i = N-1
j = i+1 = N-1 +1 = N --- for (... j < N... ): condition false, so "N-1" is not the last iteration for inner loop
i = N-2
j = i+1 = N-2 +1 = N-1 --- for (... j < N ...): condition true, this is the last iteration. But it writes to a[N-1][N-1].
a[i+1]
Right?
Jennifer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Your right (not enough coffee this morning).
Jim
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sergey,
First verify that the input data is consistent (table of srand's). Try
#pragma intel optimization_level 1
LUTest()
{
srand(25);
for(int i=0; i
}
// returns to option switch optimization here
Jim Dempsey
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Dear Jennifer and Jim,
Many thanks for your help.
I think my question is answered.
All the best,
Sergey
Many thanks for your help.
I think my question is answered.
All the best,
Sergey
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page