Intel® oneAPI Data Parallel C++
Support for Intel® oneAPI DPC++ Compiler, Intel® oneAPI DPC++ Library, Intel® DPC++ Compatibility Tool, and GDB*
382 Discussions

valarray with exp instruction error in Intel OneApi Developer Tools 2021.4?

JerzyP
Beginner
661 Views

Hi,
I found that Intel OneApi Developer Tools 2021.4 (from w_BaseKit_p_2021.4.0.3421_offline.exe + w_HPCKit_p_2021.4.0.3340_offline.exe packages) has a problem with the generation of good code when valarrays type is used together with exp instructions, i.e. generate the bad results.
This problem appears, when we use /O2 and /fp:fast options using Intel oneAPI DPC++/C++ Compiler 2021 (but does not appear when we use Intel C++ Compiler Clasic 19.2 from Intel OneApi Developer Tools 2021.4 package).
See the “textexp.cpp” code:
-----------------------
#include <iostream>
#include <cmath>
#include <valarray>
#include <random>
int main() {
  using namespace std;
  mt19937_64 engine;
  engine.seed(0); //0 to have reproducible results
  uniform_real_distribution<double> uniform0_1(0, 1);

// Random size is used to protect from unrolling loop instructions (e.g. for "for" instructions)
// If replace this line by "int size = 20;", compiler unrolls "for" instructions.
  int size = 20 + int(0.001 * uniform0_1(engine)); //size=20.

  valarray<double> x, y;
  x.resize(size);
  y.resize(size);
  for (int i = 0; i < y.size(); ++i)
    y[i] = x[i] = 1.0;

  for (int i = 0; i < y.size(); ++i)
    y[i] *= exp(-x[i]); //All y[i] should be equal to 0.367978...
  //... but for i equal to 2, 3, 6, 7, 10, 11, 14, 15 and so on y[i]=1.44467 !!!???
  //if program is compiled by oneAPI DPC++/C++ Compiler from Intel OneApi Developer Tools 2021.4
  //(w_BaseKit_p_2021.4.0.3421_offline.exe + w_HPCKit_p_2021.4.0.3340_offline.exe) using MS Visual Studio 2019 envirenment.

  for (int i = 0; i < y.size(); ++i)
    cout << y[i] << endl; //We obtain 0.367978, 0.367978, 1.44467, 1.44467, 0.367978, 0.367978, 1.44467, 1.44467, 0.367978, 0.367978, 1.44467, 1.44467...???
  return 0;
}
-----------------
Compile options: /GS /W3 /Gy /Zi /O2 /fp:fast /D "NDEBUG" /D "_CONSOLE" /D "_UNICODE" /D "UNICODE" /Qipo /Zc:forScope /std:c17 /Oi /MT /Fa"x64\Release\" /EHsc /nologo /Fo"x64\Release\" //fprofile-instr-use "x64\Release\" /Fp"x64\Release\testexp.pch"

Please help me,
Thanks a lot.
Jerzy

0 Kudos
4 Replies
JerzyP
Beginner
651 Views

The program was compiled and run on a PC with Windows 10 (i7 3770K processor).

Jerzy

VarshaS_Intel
Moderator
583 Views

Hi,


Thanks for reporting us.


We are able to reproduce your issue using "release" mode. However, we observed that with "debug" mode we are getting expected/correct results.

We are working on your issue internally and will get back to you soon.


Thanks & Regards

Varsha


ayu1
Employee
519 Views

The issue has been escalated our engineers and we will work on it internally. We will get back to you when update is available.


ayu1
Employee
193 Views

The problem cannot be reproduced for icx compiler 2022.0 in oneAPI Base Toolkit 2022.1.2. I'm closing this issue as fixed. Please feel free to reopen or file a new issue if you find any more problems.


Reply