@@ -216,7 +216,7 @@ void frolladaptivemeanExact(const double *x, uint64_t nx, ans_t *ans, const int
216216 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 );
217217 bool truehasnf = hasnf > 0 ; // flag to re-run if NAs detected
218218 if (!truehasnf || !narm ) { // narm=FALSE handled here as NAs properly propagated in exact algo
219- #pragma omp parallel for num_threads(getDTthreads(nx, true))
219+ #pragma omp parallel for num_threads(getDTthreads(nx, true)) shared(truehasnf)
220220 for (uint64_t i = 0 ; i < nx ; i ++ ) { // loop on every observation to produce final answer
221221 if (narm && truehasnf ) {
222222 continue ; // if NAs detected no point to continue
@@ -239,6 +239,7 @@ void frolladaptivemeanExact(const double *x, uint64_t nx, ans_t *ans, const int
239239 if (!narm ) {
240240 ans -> dbl_v [i ] = (double ) w ;
241241 }
242+ #pragma omp atomic write
242243 truehasnf = true; // NAs detected for this window, set flag so rest of windows will not be re-run
243244 } else {
244245 ans -> dbl_v [i ] = (double ) w ; // Inf and -Inf
@@ -436,7 +437,7 @@ void frolladaptivesumExact(const double *x, uint64_t nx, ans_t *ans, const int *
436437 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 );
437438 bool truehasnf = hasnf > 0 ;
438439 if (!truehasnf || !narm ) {
439- #pragma omp parallel for num_threads(getDTthreads(nx, true))
440+ #pragma omp parallel for num_threads(getDTthreads(nx, true)) shared(truehasnf)
440441 for (uint64_t i = 0 ; i < nx ; i ++ ) {
441442 if (narm && truehasnf ) {
442443 continue ;
@@ -454,6 +455,7 @@ void frolladaptivesumExact(const double *x, uint64_t nx, ans_t *ans, const int *
454455 if (!narm ) {
455456 ans -> dbl_v [i ] = (double ) w ;
456457 }
458+ #pragma omp atomic write
457459 truehasnf = true; // NAs detected for this window, set flag so rest of windows will not be re-run
458460 } else {
459461 ans -> dbl_v [i ] = (double ) w ; // Inf and -Inf
@@ -671,7 +673,7 @@ void frolladaptiveprodExact(const double *x, uint64_t nx, ans_t *ans, const int
671673 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 );
672674 bool truehasnf = hasnf > 0 ;
673675 if (!truehasnf || !narm ) {
674- #pragma omp parallel for num_threads(getDTthreads(nx, true))
676+ #pragma omp parallel for num_threads(getDTthreads(nx, true)) shared(truehasnf)
675677 for (uint64_t i = 0 ; i < nx ; i ++ ) {
676678 if (narm && truehasnf ) {
677679 continue ;
@@ -689,6 +691,7 @@ void frolladaptiveprodExact(const double *x, uint64_t nx, ans_t *ans, const int
689691 if (!narm ) {
690692 ans -> dbl_v [i ] = (double ) w ;
691693 }
694+ #pragma omp atomic write
692695 truehasnf = true; // NAs detected for this window, set flag so rest of windows will not be re-run
693696 } else {
694697 ans -> dbl_v [i ] = (double ) w ; // Inf and -Inf
0 commit comments