Search code examples
intelarmadillointel-oneapidpc++

NaN's are getting reported as 0 while compiling with icpx and not as NaN


On running this program, in the output Nan"s are being reported as 0, when building with icpx V2022.1, it is working fine with other compilers.

Compiling with the command:  icpx -O3 -qmkl=sequential

#define ARMA_DONT_USE_WRAPPER

#include <armadillo>

int main() {
  
  arma::Col<double> var;

  var.randu(4);
  var.print();
  
  std::cout << std::endl;
  
  var[0] = arma::datum::nan; 
  // Same with var[0] = std::numeric_limits<double>::quiet_NaN()
  var.print();
  
  return 0;
}


Solution

  • The Intel compilers' default optimization setting is -O2. As suggested by Peter Cordes in the above comment, You can use the command"-fp-model=precise" flag, to instruct the compiler to strictly follow value-safe optimizations when implementing floating-point computations. Hope this solves the issue.