Skip to content

Commit

Permalink
some CRAN related fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
markvanderloo committed Dec 16, 2016
1 parent e3cabaa commit 4a493a5
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 17 deletions.
4 changes: 2 additions & 2 deletions pkg/DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,14 @@ Description: Implements an approximate string matching version of R's native
implementation of soundex is provided as well. Distances can be computed between
character vectors while taking proper care of encoding or between integer
vectors representing generic sequences.
Version: 0.9.4.2
Version: 0.9.4.4
Depends:
R (>= 2.15.3)
Imports:
parallel
URL: https://github.com/markvanderloo/stringdist
BugReports: https://github.com/markvanderloo/stringdist/issues
Date: 2016-09-09
Date: 2016-12-16
Suggests:
testthat
RoxygenNote: 5.0.1
5 changes: 5 additions & 0 deletions pkg/NEWS
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
version 0.9.4.4
- updated default nr of threads to comply to CRAN policy (thanks to Kurt Hornik).
The default nr of cores now equals OMP_NUM_THREADS if set. See
?'stringdist-parallelization' for the full policy.

version 0.9.4.2
- bugfix in stringdistmatrix(a): value of p, for jw-distance was ignored
(thanks to Max Fritsche)
Expand Down
2 changes: 1 addition & 1 deletion pkg/R/doc_metrics.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
#'
#' @section A short description of string metrics supported by \pkg{stringdist}:
#'
#' See \href{http://journal.r-project.org/archive/2014-1/loo.pdf}{Van der Loo
#' See \href{https://journal.r-project.org/archive/2014-1/loo.pdf}{Van der Loo
#' (2014)} for an extensive description and references. The review papers of
#' Navarro (2001) and Boytsov (2011) provide excellent technical overviews of
#' respectively online and offline string matching algorithms.
Expand Down
11 changes: 7 additions & 4 deletions pkg/R/doc_parallel.R
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,13 @@
#' By default, the number of threads to use is taken from \code{options('sd_num_thread')}.
#' When the package is loaded, the value for this option is determined as follows:
#' \itemize{
#' \item{The number of available cores is determined with \code{parallel::detectCores()}}
#' \item{If available, the environment variable \code{OMP_THREAD_LIMIT} is determined}
#' \item{The number of threads is set to the lesser of \code{OMP_THREAD_LIMIT} and the number of detected cores.}
#' \item{If the number of threads larger then or equal to \eqn{4}, and \code{OMP_THREAD_LIMIT} is not set, it is set to \code{'sd_num_thread'-1}}.
#' \item{If the environment variable \code{OMP_NUM_THREADS} is set, this value is taken.}
#' \item{Otherwise, the number of available cores is determined with \code{parallel::detectCores()}
#' If this fails, the number of threads is set to 1 (with a message). If the nr of detected
#' cores exceeds three, the number of used cores is set to \eqn{n-1}.}
#' \item{If available, the environment variable \code{OMP_THREAD_LIMIT} is
#' determined and The number of threads is set to the lesser of
#' \code{OMP_THREAD_LIMIT} and the number of detected cores.}
#' }
#'
#' The latter step makes sure that on machines with \eqn{n>3} cores, \eqn{n-1}
Expand Down
2 changes: 1 addition & 1 deletion pkg/R/stringdist.R
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
#' \item{The code for soundex conversion and string similarity was kindly contributed by Jan van der Laan.}
#' }
#' @section Citation:
#' If you would like to cite this package, please cite the \href{http://journal.r-project.org/archive/2014-1/loo.pdf}{R Journal Paper}:
#' If you would like to cite this package, please cite the \href{https://journal.r-project.org/archive/2014-1/loo.pdf}{R Journal Paper}:
#' \itemize{
#' \item{M.P.J. van der Loo (2014). The \code{stringdist} package for approximate string matching.
#' R Journal 6(1) pp 111-122}
Expand Down
25 changes: 16 additions & 9 deletions pkg/R/utils.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,25 @@ mymsg <- message
.onLoad <- function(libname, pkgname){
RECYCLEWARNING <<- gettext(tryCatch( (1:2)+(1:3),warning=function(w) w$message ))

nthread = parallel::detectCores()

if ( is.na(nthread) || !is.numeric(nthread) ){
nthread <- 1L
mymsg("Could not detect number of cores, defaulting to 1.")

omp_num_threads <- as.numeric(Sys.getenv("OMP_NUM_THREADS"))
if (!is.na(omp_num_threads) && omp_num_threads > 0){
nthread <- omp_num_threads
} else {
nthread <- parallel::detectCores()
if ( is.na(nthread) || !is.numeric(nthread) ){
nthread <- 1L
mymsg("Could not detect number of cores, defaulting to 1.")
} else {
# nthread=nr of detected cores. Leave one core free.
if (nthread >= 4) nthread <- nthread - 1
}
}

omp_thread_limit = as.numeric(Sys.getenv("OMP_THREAD_LIMIT"))
## if OMP_THREAD_LIMIT is set, maximize on that limit.
omp_thread_limit <- as.numeric(Sys.getenv("OMP_THREAD_LIMIT"))
if ( is.na(omp_thread_limit) ) omp_thread_limit <- nthread

nthread = min(omp_thread_limit,nthread)
if (nthread >= 4) nthread <- nthread - 1
nthread <- min(omp_thread_limit,nthread)

options(sd_num_thread=nthread)
}
Expand Down

0 comments on commit 4a493a5

Please sign in to comment.