- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I have been trying to debug a code for the last two weeks, and I have narrowed it down to this simple code which reproduces the issue.
#include <cassert> template <class T> class Vector{ public: Vector(){dim=0;} ~Vector(){}; inline int Dim() const{return dim;} private: int dim; }; int main(int argc, char **argv){ Vector<int> v; #pragma omp parallel for for(int trg=0;trg<v.Dim();trg++){ assert(trg<v.Dim()); Vector<int> vbuff[2]; } return 0; }
I compile the code with icpc version 12.1.6 as follows:
icpc -O0 -openmp main.cpp
When I run the executable, I get:
a.out: main.cpp:17: int main(int, char **): Assertion `trg<v.Dim()' failed.
Can someone help me figure out what is going on?
Additional details: OS is Scientific Linux release 6.6 (Carbon). CPU is Intel(R) Xeon(R) CPU E5-2687W 0 @ 3.10GHz
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've reproduce it with v12 compiler (12.1.4, composer 2011 sp1 update 11), and debug with gdb, it looks like 'trg' is not initialized correctly.
Breakpoint 1, L_main_17__par_loop0_2_30 () at temp.cpp:21 21 assert(trg<v.Dim()); (gdb) display trg 1: trg = 4 (gdb) display v.Dim() 2: v.Dim () = 0 (gdb)
Logically, the for loop should never been executed as v.Dim() is 0. Also, adding something like "printf("%d\n", trg)" inside the loop, it works and nothing printed as expected.
Summary: It seems to be a bug of old compiler (maybe OpenMP library?), you may have to upgrade to a new version.
Thanks,
Shenghong
Link Copied
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I cannot reproduce it with v14.0 or v15.0 compiler, and the code pass with GCC too. I assume it may be a bug of v12.1 compiler. Do you have a chance to try a newer compiler release?
@Qiaoming, dim is initialized as zero in the ctor, the loop should not even be executed in this case. Even dim is not initialized (a random value), the assertion should pass.....
Thanks,
Shenghong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I've reproduce it with v12 compiler (12.1.4, composer 2011 sp1 update 11), and debug with gdb, it looks like 'trg' is not initialized correctly.
Breakpoint 1, L_main_17__par_loop0_2_30 () at temp.cpp:21 21 assert(trg<v.Dim()); (gdb) display trg 1: trg = 4 (gdb) display v.Dim() 2: v.Dim () = 0 (gdb)
Logically, the for loop should never been executed as v.Dim() is 0. Also, adding something like "printf("%d\n", trg)" inside the loop, it works and nothing printed as expected.
Summary: It seems to be a bug of old compiler (maybe OpenMP library?), you may have to upgrade to a new version.
Thanks,
Shenghong
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Many thanks for the quick response. I will ask system admins to install newer version of the compiler.
Thanks,
Dhairya
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi Dairya,
Yes I tried as well and this test will fail with all versions of 12.X, 13.X but will pass with 14.X and the latest 15.X version. There were some changes made to countable loops if I recall and hence the only way is for you to upgrade to newer version :-(
_Kittur
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page