Skip to content

Add natcpp_threads() thread policy; default jaccard threads to NULL - #5

Merged
jefferis merged 1 commit into
masterfrom
natcpp_threads
Sep 17, 2026
Merged

jefferis merged 1 commit into
masterfrom
natcpp_threads

Conversation

@jefferis

Copy link
Copy Markdown
Collaborator

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 the OMP_THREAD_LIMIT env var → else a conservative 2. Needs no dependency on parallel.

  • c_weighted_jaccard_sparse() and c_weighted_jaccard_dense() now default threads = NULL and resolve through the helper instead of a hard-coded 4. Pass threads = 0 for all cores, or an integer to override.
  • The dense C++ export is renamed to an internal 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).
  • Version bump 0.3.10.3.1.9000; NEWS bullet; helper tests.

Two decisions worth noting

  1. No new dependency. parallel was considered (for detectCores()) but is unnecessary under this policy — and the conservative fallback is the socially-correct default for a library.
  2. Behavioural change: when Ncpus is unset (most local sessions) the effective default drops from 4 to 2. That's the intended "good citizen" behaviour; power users pass threads = 0 (all cores) or set options(Ncpus=).

Test plan

  • test-utils.R: helper honours explicit values (incl. 0), and the NcpusOMP_THREAD_LIMIT2 fallback chain.
  • test-weighted-jaccard.R: unchanged, still green.
  • Local 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

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.
@jefferis
jefferis merged commit aa220fa into master Sep 17, 2026
9 checks passed
@jefferis
jefferis deleted the natcpp_threads branch September 17, 2026 22:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant