@@ -202,7 +202,7 @@ void frolladaptivemeanExact(const double *x, uint64_t nx, ans_t *ans, const int
202202 snprintf (end (ans -> message [0 ]), 500 , _ ("%s: running in parallel for input length %" PRIu64 ", hasnf %d, narm %d\n" ), "frolladaptivemeanExact" , (uint64_t )nx , hasnf , (int ) narm );
203203 bool truehasnf = hasnf > 0 ; // flag to re-run if NAs detected
204204 if (!truehasnf || !narm ) { // narm=FALSE handled here as NAs properly propagated in exact algo
205- #pragma omp parallel for num_threads(getDTthreads(nx, true))
205+ #pragma omp parallel for num_threads(getDTthreads(nx, true)) shared(truehasnf)
206206 for (uint64_t i = 0 ; i < nx ; i ++ ) { // loop on every observation to produce final answer
207207 if (narm && truehasnf ) {
208208 continue ; // if NAs detected no point to continue
@@ -225,6 +225,7 @@ void frolladaptivemeanExact(const double *x, uint64_t nx, ans_t *ans, const int
225225 if (!narm ) {
226226 ans -> dbl_v [i ] = (double ) w ;
227227 }
228+ #pragma omp atomic write
228229 truehasnf = true; // NAs detected for this window, set flag so rest of windows will not be re-run
229230 } else {
230231 ans -> dbl_v [i ] = (double ) w ; // Inf and -Inf
@@ -422,7 +423,7 @@ void frolladaptivesumExact(const double *x, uint64_t nx, ans_t *ans, const int *
422423 snprintf (end (ans -> message [0 ]), 500 , _ ("%s: running in parallel for input length %" PRIu64 ", hasnf %d, narm %d\n" ), "frolladaptivesumExact" , (uint64_t )nx , hasnf , (int ) narm );
423424 bool truehasnf = hasnf > 0 ;
424425 if (!truehasnf || !narm ) {
425- #pragma omp parallel for num_threads(getDTthreads(nx, true))
426+ #pragma omp parallel for num_threads(getDTthreads(nx, true)) shared(truehasnf)
426427 for (uint64_t i = 0 ; i < nx ; i ++ ) {
427428 if (narm && truehasnf ) {
428429 continue ;
@@ -440,6 +441,7 @@ void frolladaptivesumExact(const double *x, uint64_t nx, ans_t *ans, const int *
440441 if (!narm ) {
441442 ans -> dbl_v [i ] = (double ) w ;
442443 }
444+ #pragma omp atomic write
443445 truehasnf = true; // NAs detected for this window, set flag so rest of windows will not be re-run
444446 } else {
445447 ans -> dbl_v [i ] = (double ) w ; // Inf and -Inf
@@ -657,7 +659,7 @@ void frolladaptiveprodExact(const double *x, uint64_t nx, ans_t *ans, const int
657659 snprintf (end (ans -> message [0 ]), 500 , _ ("%s: running in parallel for input length %" PRIu64 ", hasnf %d, narm %d\n" ), "frolladaptiveprodExact" , (uint64_t )nx , hasnf , (int ) narm );
658660 bool truehasnf = hasnf > 0 ;
659661 if (!truehasnf || !narm ) {
660- #pragma omp parallel for num_threads(getDTthreads(nx, true))
662+ #pragma omp parallel for num_threads(getDTthreads(nx, true)) shared(truehasnf)
661663 for (uint64_t i = 0 ; i < nx ; i ++ ) {
662664 if (narm && truehasnf ) {
663665 continue ;
@@ -675,6 +677,7 @@ void frolladaptiveprodExact(const double *x, uint64_t nx, ans_t *ans, const int
675677 if (!narm ) {
676678 ans -> dbl_v [i ] = (double ) w ;
677679 }
680+ #pragma omp atomic write
678681 truehasnf = true; // NAs detected for this window, set flag so rest of windows will not be re-run
679682 } else {
680683 ans -> dbl_v [i ] = (double ) w ; // Inf and -Inf
0 commit comments