Skip to content

Commit 4c4b210

Browse files
committed
proper skip omp parallel loops
1 parent 8d0faee commit 4c4b210

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/froll.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ void frollmeanExact(const double *x, uint64_t nx, ans_t *ans, int k, double fill
231231
}
232232
bool truehasnf = hasnf>0; // flag to re-run with NA support if NAs detected
233233
if (!truehasnf || !narm) {
234-
#pragma omp parallel for num_threads(getDTthreads(nx, true))
234+
#pragma omp parallel for num_threads(getDTthreads(nx, true)) shared(truehasnf)
235235
for (uint64_t i=k-1; i<nx; i++) { // loop on every observation with complete window, partial already filled in single threaded section
236236
if (narm && truehasnf) {
237237
continue; // if NAs detected no point to continue
@@ -251,6 +251,7 @@ void frollmeanExact(const double *x, uint64_t nx, ans_t *ans, int k, double fill
251251
if (!narm) {
252252
ans->dbl_v[i] = (double) w; // NAs should be propagated
253253
}
254+
#pragma omp atomic write
254255
truehasnf = true; // NAs detected for this window, set flag so rest of windows will not be re-run
255256
} else {
256257
ans->dbl_v[i] = (double) w; // Inf and -Inf
@@ -418,7 +419,7 @@ void frollsumExact(const double *x, uint64_t nx, ans_t *ans, int k, double fill,
418419
}
419420
bool truehasnf = hasnf>0;
420421
if (!truehasnf || !narm) {
421-
#pragma omp parallel for num_threads(getDTthreads(nx, true))
422+
#pragma omp parallel for num_threads(getDTthreads(nx, true)) shared(truehasnf)
422423
for (uint64_t i=k-1; i<nx; i++) {
423424
if (narm && truehasnf) {
424425
continue;
@@ -433,6 +434,7 @@ void frollsumExact(const double *x, uint64_t nx, ans_t *ans, int k, double fill,
433434
if (!narm) {
434435
ans->dbl_v[i] = (double) w;
435436
}
437+
#pragma omp atomic write
436438
truehasnf = true;
437439
} else {
438440
ans->dbl_v[i] = (double) w;
@@ -1065,7 +1067,7 @@ void frollprodExact(const double *x, uint64_t nx, ans_t *ans, int k, double fill
10651067
}
10661068
bool truehasnf = hasnf>0;
10671069
if (!truehasnf || !narm) {
1068-
#pragma omp parallel for num_threads(getDTthreads(nx, true))
1070+
#pragma omp parallel for num_threads(getDTthreads(nx, true)) shared(truehasnf)
10691071
for (uint64_t i=k-1; i<nx; i++) {
10701072
if (narm && truehasnf) {
10711073
continue;
@@ -1080,6 +1082,7 @@ void frollprodExact(const double *x, uint64_t nx, ans_t *ans, int k, double fill
10801082
if (!narm) {
10811083
ans->dbl_v[i] = (double) w;
10821084
}
1085+
#pragma omp atomic write
10831086
truehasnf = true;
10841087
} else {
10851088
ans->dbl_v[i] = (double) w;

src/frolladaptive.c

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)