Add natcpp_threads() thread policy; default jaccard threads to NULL - #5
Merged
Merged
Conversation
Introduce an internal natcpp_threads() helper implementing a package-wide
default thread count: an explicit value wins, else getOption("Ncpus"), else
the OMP_THREAD_LIMIT env var, else a conservative 2 (following Eddelbuettel's
advice in Rdatatable/data.table#5658). Needs no dependency on parallel.
c_weighted_jaccard_sparse() and c_weighted_jaccard_dense() now default
threads=NULL and route through the helper instead of a hard-coded 4; pass
threads=0 for all cores. The dense C++ export is renamed to an internal
weighted_jaccard_dense_impl() behind a documented hand wrapper so the R-level
default and its docs live in one place.
Bump to 0.3.1.9000; add tests for the helper.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Introduces an internal
natcpp_threads()helper implementing a package-wide default thread-count policy, and routes the two weighted-Jaccard functions through it.Policy (following Eddelbuettel's advice in Rdatatable/data.table#5658): an explicit user value wins → else
getOption("Ncpus")(which CRAN sets) → else theOMP_THREAD_LIMITenv var → else a conservative 2. Needs no dependency onparallel.c_weighted_jaccard_sparse()andc_weighted_jaccard_dense()now defaultthreads = NULLand resolve through the helper instead of a hard-coded4. Passthreads = 0for all cores, or an integer to override.weighted_jaccard_dense_impl()behind a documented hand R wrapper, so the R-level default and docs live in one place (mirroring the existing sparse wrapper).0.3.1→0.3.1.9000; NEWS bullet; helper tests.Two decisions worth noting
parallelwas considered (fordetectCores()) but is unnecessary under this policy — and the conservative fallback is the socially-correct default for a library.Ncpusis unset (most local sessions) the effective default drops from4to2. That's the intended "good citizen" behaviour; power users passthreads = 0(all cores) or setoptions(Ncpus=).Test plan
test-utils.R: helper honours explicit values (incl.0), and theNcpus→OMP_THREAD_LIMIT→2fallback chain.test-weighted-jaccard.R: unchanged, still green.R CMD check: 0 errors / 0 warnings / 1 pre-existing NOTE (top-level files).Co-Authored-By: Claude Opus 4.8 noreply@anthropic.com
🤖 Generated with Claude Code