Parallel Programming Guide for HP-UX Systems

Troubleshooting
Floating-point imprecision
Chapter 9184
.
.
.
ENDDO
C$DIR NEXT_TASK
DO I = 1, 10000
X = X + C(I) + D(I)
ENDDO
C$DIR CRITICAL_SECTION(ACCUM_LOCK)
ACCUM = ACCUM/X
C$DIR END_CRITICAL_SECTION
C$DIR END_TASKS
Here, three parallel tasks are all manipulating the real variable ACCUM,
using real variables which have themselves been manipulated. Each
manipulation is subject to roundoff error, so the total roundoff error here
might be substantial.
When the program runs in serial, the tasks execute in their written
order, and the roundoff errors accumulate in that order. However, if the
tasks run in parallel, there is no guarantee as to what order the tasks
run in. This means that the roundoff error accumulates in a different
order than it does during the serial run.
Depending on machine conditions, the tasks may run in different orders
during different parallel runs also, potentially accumulating roundoff
errors differently and yielding different answers.
Problems with floating-point precision can also occur when a program
tests the value of a variable without allowing enough tolerance for
roundoff errors. To solve the problem, adjust the tolerances to allow for
greater roundoff errors or declare the variables to be of a higher precision
(use the double type instead of float in C and C++, or REAL*8 rather
than REAL*4 in Fortran). Testing floating-point numbers for exact
equality is strongly discouraged.