Skip to content

Commit e023ba3

Browse files
Update src/omp-flags.c
Co-authored-by: Benjamin Schwendinger <[email protected]>
1 parent ee6fb9d commit e023ba3

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/omp-flags.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,33 @@ void benchmark_omp_flag(const int variant, int len, int halt, int th, int *cnt)
6868
skip = true;
6969
}
7070
}
71+
} else if (variant == 6) {
72+
// reduction-based approach
73+
bool skip = false;
74+
#pragma omp parallel for num_threads(th) reduction(||:skip)
75+
for (int i=0; i<len; i++) {
76+
if (skip)
77+
continue;
78+
int tid = omp_get_thread_num();
79+
cnt[tid]++;
80+
if (i == halt) {
81+
skip = true;
82+
}
83+
}
84+
} else if (variant == 7) {
85+
// cancellation with flag
86+
bool skip = false;
87+
#pragma omp parallel for num_threads(th) shared(skip)
88+
for (int i=0; i<len; i++) {
89+
#pragma omp cancellation point for
90+
int tid = omp_get_thread_num();
91+
cnt[tid]++;
92+
if (i == halt) {
93+
#pragma omp atomic write
94+
skip = true;
95+
#pragma omp cancel for
96+
}
97+
}
7198
}
7299
}
73100

0 commit comments

Comments
 (0)