From ee6fb9d0f79630af93784d58904a77be7e6a5914 Mon Sep 17 00:00:00 2001 From: Jan Gorecki Date: Fri, 17 Oct 2025 09:02:44 +0200 Subject: [PATCH 1/2] benchmarks --- R/utils.R | 10 ++++++ src/data.table.h | 2 ++ src/init.c | 1 + src/omp-flags.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 93 insertions(+) create mode 100644 src/omp-flags.c diff --git a/R/utils.R b/R/utils.R index 39a623b36d..5279a1a725 100644 --- a/R/utils.R +++ b/R/utils.R @@ -227,3 +227,13 @@ formula_vars = function(f, x) { # .formula2varlist is not API and seems to have attr(terms, "term.labels") ) } + +omp_flags = function(variant, len, halt, th) { + th = as.integer(th) + halt = as.integer(halt) + len = as.integer(len) + variant = as.integer(variant) + stopifnot(is.integer(th)) + stopifnot(th <= parallel::detectCores(), th > 0L) + .Call("Cbenchmark_omp_flagR", variant, len, halt, th) +} diff --git a/src/data.table.h b/src/data.table.h index 775d492aac..75c38864f3 100644 --- a/src/data.table.h +++ b/src/data.table.h @@ -410,3 +410,5 @@ SEXP dt_has_zlib(void); SEXP startsWithAny(SEXP, SEXP, SEXP); SEXP convertDate(SEXP, SEXP); SEXP fastmean(SEXP); + +SEXP benchmark_omp_flagR(SEXP, SEXP, SEXP, SEXP); diff --git a/src/init.c b/src/init.c index ef81a7a0e0..c8870ca12e 100644 --- a/src/init.c +++ b/src/init.c @@ -160,6 +160,7 @@ R_CallMethodDef callMethods[] = { {"CmemcpyDTadaptive", (DL_FUNC)&memcpyDTadaptive, -1}, {"Csetgrowable", (DL_FUNC)&setgrowable, -1}, {"Cfrolladapt", (DL_FUNC)&frolladapt, -1}, +{"Cbenchmark_omp_flagR", (DL_FUNC)&benchmark_omp_flagR, -1}, {NULL, NULL, 0} }; diff --git a/src/omp-flags.c b/src/omp-flags.c new file mode 100644 index 0000000000..121d199736 --- /dev/null +++ b/src/omp-flags.c @@ -0,0 +1,80 @@ +#include "data.table.h" + +void benchmark_omp_flag(const int variant, int len, int halt, int th, int *cnt) { + if (variant == 1) { + // plain as is now + bool skip = false; + #pragma omp parallel for num_threads(th) + for (int i=0; i Date: Fri, 17 Oct 2025 19:44:32 +0200 Subject: [PATCH 2/2] Update src/omp-flags.c Co-authored-by: Benjamin Schwendinger <52290390+ben-schwen@users.noreply.github.com> --- src/omp-flags.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/omp-flags.c b/src/omp-flags.c index 121d199736..e77678a31c 100644 --- a/src/omp-flags.c +++ b/src/omp-flags.c @@ -68,6 +68,33 @@ void benchmark_omp_flag(const int variant, int len, int halt, int th, int *cnt) skip = true; } } + } else if (variant == 6) { + // reduction-based approach + bool skip = false; + #pragma omp parallel for num_threads(th) reduction(||:skip) + for (int i=0; i