Intel® C++ Compiler
Community support and assistance for creating C++ code that runs on platforms based on Intel® processors.
7957 Discussions

double free or corruption error when using AVX vectorization

Tingyu_W_
Beginner
699 Views

I was trying out different AVX compiler options on my workstation with Xeon Phi (KNL). My ICC version is 17.0.4 from Intel Parallel Studio XE Cluster Edition. Since my hardware support AVX, AVX2 and AVX512 intrinsic, I tried all of them (-mavx, -march=core-avx2 and -xMIC-AVX512) one by one on my code snippet:

#include <vector>
#include <cstdlib>
typedef double real_t;
struct Body {
  real_t G[4];
  real_t p;
  real_t F[3];
};

int main(int argc, char** argv) {
  int numBodies = atoi(argv[1]);
  std::vector<Body> bodies(numBodies);
  for (int b=0; b<bodies.size(); b++) {
    bodies.p = 0;
    for (int d=0; d<3; d++) bodies.F = 0;
  }
  return 0;
}

When I compiled with "icpc -xMIC-AVX512 mytest.cpp" and run "./a.out 2", the code executes and return 0. However when I used "-mavx" or "-march=core-avx2" instead of AVX512, I get the following error when running "./a.out 2":

*** Error in `./a.out': double free or corruption (out): 0x00000000021ef010 ***
======= Backtrace: =========
/lib64/libc.so.6(+0x7c503)[0x7ff1bf174503]
./a.out[0x401028]
/lib64/libc.so.6(__libc_start_main+0xf5)[0x7ff1bf119b35]
./a.out[0x400c29]
======= Memory map: ========
00400000-00405000 r-xp 00000000 08:03 4328106                            /home/test/a.out
00604000-00605000 r--p 00004000 08:03 4328106                            /home/test/a.out
00605000-00606000 rw-p 00005000 08:03 4328106                            /home/test/a.out
021ef000-02210000 rw-p 00000000 00:00 0                                  [heap]
7ff1b8000000-7ff1b8021000 rw-p 00000000 00:00 0
7ff1b8021000-7ff1bc000000 ---p 00000000 00:00 0
7ff1beef4000-7ff1beef6000 r-xp 00000000 08:03 919763                     /usr/lib64/libdl-2.17.so
7ff1beef6000-7ff1bf0f6000 ---p 00002000 08:03 919763                     /usr/lib64/libdl-2.17.so
7ff1bf0f6000-7ff1bf0f7000 r--p 00002000 08:03 919763                     /usr/lib64/libdl-2.17.so
7ff1bf0f7000-7ff1bf0f8000 rw-p 00003000 08:03 919763                     /usr/lib64/libdl-2.17.so
7ff1bf0f8000-7ff1bf2ae000 r-xp 00000000 08:03 919598                     /usr/lib64/libc-2.17.so
7ff1bf2ae000-7ff1bf4ae000 ---p 001b6000 08:03 919598                     /usr/lib64/libc-2.17.so
7ff1bf4ae000-7ff1bf4b2000 r--p 001b6000 08:03 919598                     /usr/lib64/libc-2.17.so
7ff1bf4b2000-7ff1bf4b4000 rw-p 001ba000 08:03 919598                     /usr/lib64/libc-2.17.so
7ff1bf4b4000-7ff1bf4b9000 rw-p 00000000 00:00 0
7ff1bf4b9000-7ff1bf4ce000 r-xp 00000000 08:03 941684                     /usr/lib64/libgcc_s-4.8.5-20150702.so.1
7ff1bf4ce000-7ff1bf6cd000 ---p 00015000 08:03 941684                     /usr/lib64/libgcc_s-4.8.5-20150702.so.1
7ff1bf6cd000-7ff1bf6ce000 r--p 00014000 08:03 941684                     /usr/lib64/libgcc_s-4.8.5-20150702.so.1
7ff1bf6ce000-7ff1bf6cf000 rw-p 00015000 08:03 941684                     /usr/lib64/libgcc_s-4.8.5-20150702.so.1
7ff1bf6cf000-7ff1bf7cf000 r-xp 00000000 08:03 919764                     /usr/lib64/libm-2.17.so
7ff1bf7cf000-7ff1bf9cf000 ---p 00100000 08:03 919764                     /usr/lib64/libm-2.17.so
7ff1bf9cf000-7ff1bf9d0000 r--p 00100000 08:03 919764                     /usr/lib64/libm-2.17.so
7ff1bf9d0000-7ff1bf9d1000 rw-p 00101000 08:03 919764                     /usr/lib64/libm-2.17.so
7ff1bf9d1000-7ff1bfaba000 r-xp 00000000 08:03 919645                     /usr/lib64/libstdc++.so.6.0.19
7ff1bfaba000-7ff1bfcba000 ---p 000e9000 08:03 919645                     /usr/lib64/libstdc++.so.6.0.19
7ff1bfcba000-7ff1bfcc3000 r--p 000e9000 08:03 919645                     /usr/lib64/libstdc++.so.6.0.19
7ff1bfcc3000-7ff1bfcc5000 rw-p 000f2000 08:03 919645                     /usr/lib64/libstdc++.so.6.0.19
7ff1bfcc5000-7ff1bfcda000 rw-p 00000000 00:00 0
7ff1bfcda000-7ff1bfcfa000 r-xp 00000000 08:03 919590                     /usr/lib64/ld-2.17.so
7ff1bfed8000-7ff1bfede000 rw-p 00000000 00:00 0
7ff1bfef7000-7ff1bfef9000 rw-p 00000000 00:00 0
7ff1bfef9000-7ff1bfefa000 r--p 0001f000 08:03 919590                     /usr/lib64/ld-2.17.so
7ff1bfefa000-7ff1bfefb000 rw-p 00020000 08:03 919590                     /usr/lib64/ld-2.17.so
7ff1bfefb000-7ff1bfefc000 rw-p 00000000 00:00 0
7fffa10f2000-7fffa1114000 rw-p 00000000 00:00 0                          [stack]
7fffa117f000-7fffa1181000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted (core dumped)

If I don't use any SIMD optimization option when compiling the code, it works fine. I guess the reason for this memory corrpution error is that I defined an array G in the struct Body without using it in main function. When I removed the line that defines G[4], I don't see this error. Also, when I run "./a.out 3" or with other odd numbers, this error also won't show up. Could someone explained to me why "-mavx" and "-march=core-avx2" behave like this, while "xMIC-AVX512" does not? Or did I make some mistake in using these SIMD optimizations?

This code is a toy one, however, my production code shares a similar structure and I observed some similar double free error when using -mavx option. Thank you in advance.

0 Kudos
5 Replies
SergeyKostrov
Valued Contributor II
699 Views
>>...*** Error in `./a.out': double free or corruption (out): 0x00000000021ef010 ***... I had a similar error about one month ago, however it was with explicit intrinsic functions and a software was compiled for MIC-AVX512. I suspect now that there is a bigger problem with Intel C++ compiler for Linux ( Update 2 and possibly Update 4 ) since non intrinsic codes also failed but for different ISAs. As soon as I install Update 4 will verify it.
0 Kudos
SergeyKostrov
Valued Contributor II
699 Views
>>...Also, when I run "./a.out 3" or with other odd numbers, this error also won't show up. Could someone explained to me >>why "-mavx" and "-march=core-avx2" behave like this, while "xMIC-AVX512" does not? Or did I make some mistake in >>using these SIMD optimizations? It looks like there is a bug but it needs to be reproduced / confirmed by Intel C++ software engineers first.
0 Kudos
Tingyu_W_
Beginner
699 Views

Sergey Kostrov wrote:

>>...Also, when I run "./a.out 3" or with other odd numbers, this error also won't show up. Could someone explained to me
>>why "-mavx" and "-march=core-avx2" behave like this, while "xMIC-AVX512" does not? Or did I make some mistake in
>>using these SIMD optimizations?

It looks like there is a bug but it needs to be reproduced / confirmed by Intel C++ software engineers first.

Thank you Sergey for the reply. Is here the right place to report an issue/bug? 

0 Kudos
SergeyKostrov
Valued Contributor II
699 Views
>>...Is here the right place to report an issue/bug?.. If Intel C++ software engineers will reproduce that problem using your test case then there is nothing else you need to do. Thank you.
0 Kudos
JenniferJ
Moderator
699 Views

please report it to https://supporttickets.intel.com/?lang=en-US

thanks,

Jennifer

0 Kudos
Reply