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

Fixes for OpenMP limit options and detection #78

Merged
merged 2 commits into from
Feb 16, 2025

Conversation

aitap
Copy link
Contributor

@aitap aitap commented Feb 13, 2025

Fixes: #77.

Use omp_get_max_threads and omp_get_thread_limit to let the OpenMP runtime parse the OMP_NUM_THREADS and OMP_THREAD_LIMIT environment variables. Only set the rsparse_omp_threads option if it is not already set.

omp_get_max_threads() will consult the default number of threads for the
current nested parallelism layer, which is set either by the runtime or
from the OMP_NUM_THREADS environment variable.

omp_get_thread_limit() will consult the separate limit on the total
number of threads, set by the OMP_THREAD_LIMIT environment variable.
Instead of resetting it unconditionally to the automatically detected
number of threads, let the user pre-set the option to their desired
value (overriding everything).

Additionally, let detect_number_omp_threads() rely on the OpenMP runtime
to parse the OMP_NUM_THREADS and OMP_THREAD_LIMIT environment variables
instead of parsing them manually. In particular, a valid OMP_NUM_THREADS
could contain multiple integers representing different levels of nested
parallelism.
@dselivanov dselivanov merged commit 147d400 into dselivanov:master Feb 16, 2025
2 of 3 checks passed
@dselivanov
Copy link
Owner

Thanks for the issue and for the solution!

@dselivanov
Copy link
Owner

On CRAN now

@aitap
Copy link
Contributor Author

aitap commented Feb 17, 2025

Thank you too!

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.

OpenMP problems in .onLoad
2 participants