Intel® oneAPI Threading Building Blocks
Ask questions and share information about adding parallelism to your applications when using this threading library.

checking FPE occurred

Juan
Beginner
346 Views
Is there a standard way to test if an FPE had occurred in one of the TBB threads? I'd like to start using the parallel foreach to do some numerical operations, and I need to know when the processing is done, if an FPE had occurred during any of the calculations. In my serial code on Windows and Linux I am clearing the floating point flags before doing a vector operation, and then checking the result flag afterward.
0 Kudos
2 Replies
ARCH_R_Intel
Employee
346 Views
There isno built-in way to do the test.The best solution is totreat the problem as reduction, where the reduction operation combines FPE flags from different portions of the calculation.

I've attached an example that does this. I tested it on Linux. It calculates A/B. Initially both A and B are one. Successive runs perturb the values. It should print:
[cpp]No exceptions
Setting B[N/2]=3
Exceptions occurred: FE_INEXACT
Setting B[N/2]=0
Exceptions occurred: FE_DIVBYZERO
Setting A[N/2]=0
Exceptions occurred: FE_INVALID
Setting A[N/2]=1E37
Setting B[N/2]=1E-37
Exceptions occurred: FE_INEXACT FE_OVERFLOW
Setting A[N/2]=1E-37
Setting B[N/2]=1E37
Exceptions occurred: FE_INEXACT FE_UNDERFLOW[/cpp]
The key part to study is the functor Body, and how it manipulates Body::fp_excepts. Also look at where the parallel_reduce is invoked.
0 Kudos
Juan
Beginner
346 Views
Thanks for the example. I think your approach makes a lot of sense and the code was clear.

Juan

Quoting - Arch Robison (Intel)
There isno built-in way to do the test.The best solution is totreat the problem as reduction, where the reduction operation combines FPE flags from different portions of the calculation.



0 Kudos
Reply