Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
New Contributor I
51 Views

ICC 16.0.3: Options -O2 -qopenmp break std::sort

Dear all,

I am using Intel Compiler 16.0.3 combined with GCC 4.9 as backend on Linux x86_64. I have found that compiling this program:

#include <fstream>
#include <vector>
#include <algorithm>
#include <iostream>

int main(int argc, char** argv) {

  std::vector<std::pair<int,int>> selectedEvents;

  std::ifstream infile("test.txt");
  while (true) {
    int Run, Event;
    infile >> Run >> Event;
    if (infile.eof())
      break;
    selectedEvents.push_back(std::pair<int,int>(Run,Event));
  }

  std::cout << "Before sorting..." << std::endl;
  for (unsigned int i = 0; i < selectedEvents.size(); ++i ) {
    int Run = selectedEvents.first;
    int Event = selectedEvents.second;
    if (Run == 780100000) {
      if (Event == 4850674)
        std::cout << "Foo1: Run " << Run << " Event " << Event << " *** <<<------ ***" << std::endl;
      else
        std::cout << "Foo1: Run " << Run << " Event " << Event << std::endl;
    }
  }

  std::cout << "Sorting list of events..." << std::endl;
  std::sort(selectedEvents.begin(), selectedEvents.end());

  std::cout << "After sorting..." << std::endl;
  for (unsigned int i = 0; i < selectedEvents.size(); ++i ) {
    int Run = selectedEvents.first;
    int Event = selectedEvents.second;
    if (Run == 780100000) {
      if (Event == 4850674)
        std::cout << "Foo2: Run " << Run << " Event " << Event << " *** <<<------ ***" << std::endl;
      else
        std::cout << "Foo2: Run " << Run << " Event " << Event << std::endl;
    }
  }

  return 0;
}

Compiled with icpc -std=c++11 -O2 -qopenmp -o test test.C

Note that we are not using openmp code in this little program. When run with the attached (test.txt) input text file the following happens: After sorting the vector the pair <780100000,4850674> vanishes (along with varoius others) and instead there are duplicated entries, which were not there before.

Compiling with -O1 -qopenmp or with -O2 (without -qopenmp) does not exhibitit this bad behaviour. g++ also does not show the problem.

0 Kudos
3 Replies
Highlighted
Employee
51 Views

Hi Bastian,

I am not able to reproduce this issue with 16.0.3 (GCC4.9.2, 64 bit) with compiler options -std=c++11 -O2 -qopenmp. Are you able to reproduce this in a deterministic manner?

Thanks and Regards
Anoop

0 Kudos
Highlighted
New Contributor I
51 Views

Hello Anoop,

thanks for looking into this. Yes, I can reproduce this issue in a deterministic manner on three different machines, using various ICC versions as well: 16.0.2, 16.0.3 and 17 Beta. I have also tried GCC backends 4.9.3 and 5.4.0 and they all show the issue.

It seems strange to me that you cannot reproduce this :-( Any other ideas about information I could provide?

Thanks

Bastian

0 Kudos
Highlighted
Beginner
51 Views

I see the same issue.

The bug appears in my different code involving std::sort in both ICPC 2017-4 and ICPC 2019-0, with GCC 5.5 or 6.4 or 7.4 or 8.2.

The bug does not appear in system-default gcc (gcc 4.8.5 under CentOS 7)

The bug appears in various c++ modes, including std=c++11,c++14,gnu++14, etc.

The bug appears in various customized comp() functors.

The bug appears when the array size (being sorted) is 18 or larger. The index out of bound is the same everytime, with the same array size:

array_size    out-of-bound-index:

18                81

30                129

50                209

100              417

 

std::stable_sort does not trigger this bug.

 

0 Kudos