Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize
Important This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here.

Compiler Warning (level 4) C4938

Error Message

'var' : Floating point reduction variable may cause inconsistent results under /fp:strict or #pragma fenv_access

You should not use /fp:strict or fenv_access with OpenMP floating-point reductions, because the sum is computed in a different order. Thus, results can differ from the results without /openmp.

The following sample generates C4938:

// C4938.cpp
// compile with: /openmp /W4 /fp:strict /c
// #pragma fenv_access(on)
extern double *a; 

double test(int first, int last) { 
   double sum = 0.0; 
   #pragma omp parallel for reduction(+: sum)   // C4938
   for (int i = first ; i <= last ; ++i) 
      sum += a[i]; 
   return sum; 
}

Without explicit parallelization, the sum is computed as follows:

sum = a[first] + a[first + 1] + ... + a[last]; 

With explicit parallelization (and two threads), the sum is computed as follows:

sum1 = a[first] + ... a[first + last / 2]; 
sum2 = a[(first + last / 2) + 1] + ... a[last]; 
sum = sum1 + sum2;

Community Additions

ADD
Show:
© 2015 Microsoft