-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
2023-10-29 Dirk Eddelbuettel <[email protected]> | ||
|
||
* src/RcppArmadillo.cpp (armadillo_get_number_of_omp_threads) | ||
(armadillo_set_number_of_omp_threads): New helper functions | ||
* src/RcppExports.cpp: Regenerated | ||
* R/RcppExports.R: Idem | ||
* man/armadillo_get_number_of_omp_threads.Rd: Documentation | ||
|
||
* R/init.R (.onLoad): Store initial thread count | ||
* R/init.R (armadillo_throttle_cores, armadillo_reset_cores): | ||
Tread throtte and reset helper functions | ||
* man/armadillo_throttle_cores.Rd: Documentation | ||
|
||
* man/fastLm.Rd: Illustration of use of throttle and reset function | ||
* NAMESPACE: Export new functions | ||
|
||
2023-10-14 Dirk Eddelbuettel <[email protected]> | ||
|
||
* DESCRIPTION (Version, Date): RcppArmadillo 0.12.6.5.0 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
## init.R: Startup | ||
## | ||
## Copyright (C) 2023 Dirk Eddelbuettel | ||
## | ||
## This file is part of RcppArmadillo. | ||
## | ||
## RcppArmadillo is free software: you can redistribute it and/or modify it | ||
## under the terms of the GNU General Public License as published by | ||
## the Free Software Foundation, either version 2 of the License, or | ||
## (at your option) any later version. | ||
## | ||
## RcppArmadillo is distributed in the hope that it will be useful, but | ||
## WITHOUT ANY WARRANTY; without even the implied warranty of | ||
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
## GNU General Public License for more details. | ||
## | ||
## You should have received a copy of the GNU General Public License | ||
## along with RcppArmadillo. If not, see <http://www.gnu.org/licenses/>. | ||
|
||
.pkgenv <- new.env(parent=emptyenv()) | ||
|
||
.onLoad <- function(libname, pkgname) { | ||
.pkgenv[["omp_threads"]] <- armadillo_get_number_of_omp_threads() | ||
} | ||
|
||
##' Throttle (or Reset) (Rcpp)Armadillo to Two Cores | ||
##' | ||
##' Helper functions to throttle use of cores by RcppArmadillo-internal | ||
##' code on systems with OpenMP. On package load, the initial value is | ||
##' saved and used to reset the value. | ||
##' @param n Integer value of desired cores, default is two | ||
armadillo_throttle_cores <- function(n = 2) { | ||
armadillo_set_number_of_omp_threads(n) | ||
} | ||
|
||
##' @rdname armadillo_throttle_cores | ||
armadillo_reset_cores <- function() { | ||
n <- .pkgenv[["omp_threads"]] | ||
armadillo_set_number_of_omp_threads(n) | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
|
||
// RcppArmadillo.cpp: Rcpp/Armadillo glue | ||
// | ||
// Copyright (C) 2010 - 2020 Dirk Eddelbuettel, Romain Francois and Douglas Bates | ||
// Copyright (C) 2010 - 2023 Dirk Eddelbuettel, Romain Francois and Douglas Bates | ||
// | ||
// This file is part of RcppArmadillo. | ||
// | ||
|
@@ -90,3 +90,26 @@ void armadillo_set_seed(unsigned int val) { | |
//Rcpp::Rcout << "Setting value " << val << std::endl; | ||
arma::arma_rng::set_seed(val); // set the seed to given value | ||
} | ||
|
||
//' Report (or Set) Maximum Number of OpenMP Threads | ||
//' | ||
//' @param n Number of threads to be set | ||
//' @return For the getter, and on a system with OpenMP, the maximum | ||
//' number of threads that OpenMP may be using and on systems without it, | ||
//' one. The setter does not return a value. | ||
// [[Rcpp::export]] | ||
int armadillo_get_number_of_omp_threads() { | ||
#ifdef _OPENMP | ||
return omp_get_max_threads(); | ||
#else | ||
return 1; | ||
#endif | ||
} | ||
|
||
//' @rdname armadillo_get_number_of_omp_threads | ||
// [[Rcpp::export]] | ||
void armadillo_set_number_of_omp_threads(int n) { | ||
#ifdef _OPENMP | ||
omp_set_num_threads(n); | ||
#endif | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
conradsnicta
Contributor
|
||
} |
@eddelbuettel If OpenMP is not enabled, the compiler may warn (for example, under
-Wall
) that parametern
is unused.Suggest to change the function to: