Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

detectThreadsPerCore(): infer how many threads per cores the machine's CPU provides #47

Open
2 tasks
HenrikBengtsson opened this issue Apr 4, 2021 · 0 comments
Labels
enhancement New feature or request help wanted Extra attention is needed

Comments

@HenrikBengtsson
Copy link
Collaborator

Wish

For example, for a machine with:

$ lscpu | grep -iF "core"
Thread(s) per core:  2
Core(s) per socket:  4
Model name:          Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz

we should get:

> detectThreadsPerCore()
[1] 2

Action

  • Figure out how to do this reliably on all operating systems and Unix distributions.
  • If it cannot be inferred, return default, which could default to either 1L ("always works") or NA_integer_ ("unknown"). Alternatively, there could be a mustWork argument or similar.

Background

This will be useful when limiting multi-threading in nested parallelization. For example, in future we try to force single-processing by setting various environment variables and R options in parallel workers, e.g. MC_CORES=1. Currently, we do not limit the number of parallel threads.

The simplest approach would be to force a single thread, but it would be more efficient on modern systems if we'd limit it to detectThreadsPerCore() threads, e.g.

RhpcBLASctl::blas_set_num_threads(threads = detectThreadsPerCore())
RcppParallel::setThreadOptions(numThreads = detectThreadsPerCore())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

1 participant