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

Armadillo, Intel icpx and NaN's

Daniel_H
New Contributor I
877 Views

Hi,

 

When running the small piece of code given below, NaN's are reported as 0 when compiling with icpx in any optimization other than -O0.

Any other compiler (eg: g++, icpc, clang++) works as expected printing "nan" where required.

I'm using latest icpx (2022.1.0.20220316) and armadillo (11.2.1) on linux.

Already reported it at Armadillo's developer but I've been sent here!

Any help will be really appreciated,

thank

Daniel

 

#define ARMA_DONT_USE_WRAPPER

// Compile with eg:  icpx -O3 -qmkl=sequential

#include <armadillo>

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

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

 

0 Kudos
1 Solution
SantoshY_Intel
Moderator
817 Views

Hi,

 

As -O2 is the default optimization level for the Intel compilers, sometimes we might get some changes in the results. To overcome this issue, we can use the "-fp-model=precise" flag which tells the compiler to strictly adhere to value-safe optimizations when implementing floating-point calculations. It disables optimizations that can change the result of floating-point calculations, which is required for strict ANSI conformance.

 

For more information please refer to the below link:

https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-cpp-compiler-dev-guide-and-reference/top/compiler-reference/compiler-options/floating-point-options/fp-model-fp.html

 

Use the below command to get the correct results:

icpx -fp-model=precise sample.cpp
./a.out

 

We tried at our end and we are getting the correct results. Please find the attachment(icpx_log.txt) below.

 

If this resolves your issue, make sure to accept this as a solution. This would help others with a similar issue. Thank you!

 

Best Regards,

Santosh

 

View solution in original post

0 Kudos
4 Replies
SantoshY_Intel
Moderator
834 Views

Hi,


Thank you for posting in Intel Communities.


We were able to reproduce your issue at our end. We are working on your issue and will get back to you soon.


Thanks & Regards,

Santosh


0 Kudos
SantoshY_Intel
Moderator
818 Views

Hi,

 

As -O2 is the default optimization level for the Intel compilers, sometimes we might get some changes in the results. To overcome this issue, we can use the "-fp-model=precise" flag which tells the compiler to strictly adhere to value-safe optimizations when implementing floating-point calculations. It disables optimizations that can change the result of floating-point calculations, which is required for strict ANSI conformance.

 

For more information please refer to the below link:

https://www.intel.com/content/www/us/en/develop/documentation/oneapi-dpcpp-cpp-compiler-dev-guide-and-reference/top/compiler-reference/compiler-options/floating-point-options/fp-model-fp.html

 

Use the below command to get the correct results:

icpx -fp-model=precise sample.cpp
./a.out

 

We tried at our end and we are getting the correct results. Please find the attachment(icpx_log.txt) below.

 

If this resolves your issue, make sure to accept this as a solution. This would help others with a similar issue. Thank you!

 

Best Regards,

Santosh

 

0 Kudos
Daniel_H
New Contributor I
807 Views

Thanks Santosh,

 

It indeed solves the problem.

 

Daniel

0 Kudos
SantoshY_Intel
Moderator
800 Views

Hi,


Thanks for accepting our solution. If you need any additional information, please post a new question as this thread will no longer be monitored by Intel.


Thanks & Regards,

Santosh


0 Kudos
Reply