|
| 1 | +## init.R: Startup |
| 2 | +## |
| 3 | +## Copyright (C) 2023 Dirk Eddelbuettel |
| 4 | +## |
| 5 | +## This file is part of RcppArmadillo. |
| 6 | +## |
| 7 | +## RcppArmadillo is free software: you can redistribute it and/or modify it |
| 8 | +## under the terms of the GNU General Public License as published by |
| 9 | +## the Free Software Foundation, either version 2 of the License, or |
| 10 | +## (at your option) any later version. |
| 11 | +## |
| 12 | +## RcppArmadillo is distributed in the hope that it will be useful, but |
| 13 | +## WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | +## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | +## GNU General Public License for more details. |
| 16 | +## |
| 17 | +## You should have received a copy of the GNU General Public License |
| 18 | +## along with RcppArmadillo. If not, see <http://www.gnu.org/licenses/>. |
| 19 | + |
| 20 | +.pkgenv <- new.env(parent=emptyenv()) |
| 21 | + |
| 22 | +.onLoad <- function(libname, pkgname) { |
| 23 | + .pkgenv[["omp_threads"]] <- armadillo_get_number_of_omp_threads() |
| 24 | +} |
| 25 | + |
| 26 | +##' Throttle (or Reset) (Rcpp)Armadillo to Two Cores |
| 27 | +##' |
| 28 | +##' Helper functions to throttle use of cores by RcppArmadillo-internal |
| 29 | +##' code on systems with OpenMP. On package load, the initial value is |
| 30 | +##' saved and used to reset the value. |
| 31 | +##' @param n Integer value of desired cores, default is two |
| 32 | +armadillo_throttle_cores <- function(n = 2) { |
| 33 | + armadillo_set_number_of_omp_threads(n) |
| 34 | +} |
| 35 | + |
| 36 | +##' @rdname armadillo_throttle_cores |
| 37 | +armadillo_reset_cores <- function() { |
| 38 | + n <- .pkgenv[["omp_threads"]] |
| 39 | + armadillo_set_number_of_omp_threads(n) |
| 40 | +} |
0 commit comments