Skip to content

Commit

Permalink
add utility to detect if openmp is enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
m-murphy committed Oct 9, 2024
1 parent b852b24 commit 4d5a583
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
4 changes: 4 additions & 0 deletions R/RcppExports.R
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ run_mcmc_rcpp <- function(args) {
.Call(`_moire_run_mcmc`, args)
}

openmp_enabled <- function() {
.Call(`_moire_openmp_enabled`)
}

start_profiler <- function(str) {
.Call(`_moire_start_profiler`, str)
}
Expand Down
11 changes: 11 additions & 0 deletions src/RcppExports.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,16 @@ BEGIN_RCPP
return rcpp_result_gen;
END_RCPP
}
// openmp_enabled
SEXP openmp_enabled();
RcppExport SEXP _moire_openmp_enabled() {
BEGIN_RCPP
Rcpp::RObject rcpp_result_gen;
Rcpp::RNGScope rcpp_rngScope_gen;
rcpp_result_gen = Rcpp::wrap(openmp_enabled());
return rcpp_result_gen;
END_RCPP
}
// start_profiler
SEXP start_profiler(SEXP str);
RcppExport SEXP _moire_start_profiler(SEXP strSEXP) {
Expand All @@ -45,6 +55,7 @@ END_RCPP

static const R_CallMethodDef CallEntries[] = {
{"_moire_run_mcmc", (DL_FUNC) &_moire_run_mcmc, 1},
{"_moire_openmp_enabled", (DL_FUNC) &_moire_openmp_enabled, 0},
{"_moire_start_profiler", (DL_FUNC) &_moire_start_profiler, 1},
{"_moire_stop_profiler", (DL_FUNC) &_moire_stop_profiler, 0},
{NULL, NULL, 0}
Expand Down
10 changes: 10 additions & 0 deletions src/mcmc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,13 @@ void MCMC::finalize()
float MCMC::get_llik() { return chains[swap_indices[0]].get_llik(); }
float MCMC::get_prior() { return chains[swap_indices[0]].get_prior(); }
float MCMC::get_posterior() { return chains[swap_indices[0]].get_posterior(); }

// [[Rcpp::export]]
SEXP openmp_enabled()
{
#ifdef _OPENMP
return Rcpp::wrap(true);
#else
return Rcpp::wrap(false);
#endif
}

0 comments on commit 4d5a583

Please sign in to comment.