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..e77678a31c --- /dev/null +++ b/src/omp-flags.c @@ -0,0 +1,107 @@ +#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