Intel® C++ Compiler
Support and discussions for creating C++ code that runs on platforms based on Intel® processors.
7700 Discussions

Problems when combining OpenMP with AVX/SIMD instructions

Stefan_I_
Beginner
315 Views

I have a strange problem when I try to use AVX/SIMD instructions in the kernel of an OpenMP parallel for loop. While the program works perfectly when compiled with g++ or clang++, it fails when compiled with icpc (Version 17.0.4 under Ubuntu Linux 16.04).

I was able to reduce the problematic code to the following simple (but senseless) C++ program:

-----------------------------------------------
#include <immintrin.h>
#include <iostream>
using namespace std;

int main(int argc, char **argv)
{
#pragma omp parallel for
  for (int i = 1; i <= 2; ++i)
  {
    const __m256d x = _mm256_set1_pd(1.0);
    cout << x[0] << endl;
  }
  return 0;
}
-----------------------------------------------

If I compile this with "icpc -O0 -xavx ..." (OpenMP disabled), I get two times the result "1" - as expected.

If I compile it with "icpc -O0 -xavx -fopenmp ..." (OpenMP enabled), I get two time the result "3.11147e-317". The result varies somehow randomly, but is always positve and very small (around 1e-317).

What is going on here? Is there a possibility to mitigate this strange behaviour?

Thanks & best regards!

 

0 Kudos
1 Reply
Viet_H_Intel
Moderator
315 Views

 

Hi Stefan,

It looks like a bug to me. Can you please report it at https://supporttickets.intel.com 

 

Regards,

Viet Hoang

Reply