Skip to content

Commit

Permalink
Merge pull request #2099 from quanteda/fix-thread-options
Browse files Browse the repository at this point in the history
Fixes warning that occurs on Debian devel
  • Loading branch information
kbenoit committed Mar 25, 2021
2 parents 9e506ff + 77fefd5 commit 75432cf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 23 deletions.
17 changes: 5 additions & 12 deletions R/quanteda_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
#' \item{`verbose`}{logical; if `TRUE` then use this as the default
#' for all functions with a `verbose` argument}
#' \item{`threads`}{integer; specifies the number of threads to use in
#' parallelized functions; defaults to `RcppParallel::defaultNumThreads()`
#' unless `OMP_THREAD_LIMIT` is set; the number of threads can be changed
#' only once in a session}
#' parallelized functions; defaults to `RcppParallel::defaultNumThreads()`;
#' the number of threads can be changed only once in a session}
#' \item{`print_dfm_max_ndoc`}{integer; specifies the number of documents
#' to display when using the defaults for printing a dfm}
#' \item{`print_dfm_max_nfeat`}{integer; specifies the number of
Expand Down Expand Up @@ -129,13 +128,8 @@ set_option_value <- function(key, value) {
warning("Setting threads instead to maximum available ", thread["max"], call. = FALSE)
value <- thread["max"]
}
if (is.na(thread["tbb"])) {
if (value != thread["max"])
RcppParallel::setThreadOptions(value)
} else {
if (value != thread["tbb"])
warning("Number of threads can be changed only once in a session", call. = FALSE)
}
if (value != thread["max"])
RcppParallel::setThreadOptions(value)
}

# assign the key-value
Expand All @@ -146,8 +140,7 @@ set_option_value <- function(key, value) {

# returns thread settings
get_threads <- function() {
c("omp" = as.integer(Sys.getenv("OMP_THREAD_LIMIT")),
"tbb" = as.integer(Sys.getenv("RCPP_PARALLEL_NUM_THREADS")),
c("tbb" = as.integer(Sys.getenv("RCPP_PARALLEL_NUM_THREADS")),
"max" = RcppParallel::defaultNumThreads())
}

Expand Down
4 changes: 1 addition & 3 deletions cran-comments.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
# Resubmission notes

- We submitted this a second time after commenting out a single test that failed on Debian (R Under development (unstable) (2021-03-21 r80102)), apparently due to a reported issue with RcppParallel. We've skipped that test now.

- We avoided the "Found the following (possibly) invalid URLs" warning from https://www.hashtags.org/featured/what-characters-can-a-hashtag-include/ by removing it as a hyperlink.
- We submitted this after fixing an issue with a warning when threads were set, which caused a warning on Debian (R Under development (unstable) (2021-03-21 r80102)). It was determined that this warning was unnecessary so we removed it.

# Submission notes

Expand Down
5 changes: 2 additions & 3 deletions man/quanteda_options.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 5 additions & 5 deletions tests/testthat/test-quanteda_options.R
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ test_that("quanteda_options reset works correctly", {
})

test_that("quanteda_options works with threads", {
skip_on_cran()
# skip_on_cran()
if (RcppParallel::defaultNumThreads() == 2) {
quanteda_options(threads = 1)
} else {
Expand All @@ -78,10 +78,10 @@ test_that("quanteda_options works with threads", {
as.numeric(Sys.getenv('RCPP_PARALLEL_NUM_THREADS')),
quanteda_options("threads")
)
expect_warning(
quanteda_options(threads = 4),
"Number of threads can be changed only once"
)
# expect_warning(
# quanteda_options(threads = 4),
# "Number of threads can be changed only once"
# )
expect_error(quanteda_options(threads = 0),
"^Number of threads must be greater or equal to 1")
expect_warning(quanteda_options(threads = 100),
Expand Down

0 comments on commit 75432cf

Please sign in to comment.