-
Notifications
You must be signed in to change notification settings - Fork 978
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a linter for calls to omp_set_num_threads
- Loading branch information
1 parent
2dac309
commit 40d4fc5
Showing
3 changed files
with
15 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
# Ensure no calls to omp_set_num_threads() [to avoid affecting other packages and base R] | ||
# Only comments referring to it should be in openmp-utils.c | ||
omp_set_num_threads_linter = function(c_file) { | ||
processed_lines = system2("gcc", c("-fpreprocessed", "-E", "-xc", "-"), stdin=c_file, stdout=TRUE, stderr=FALSE) | ||
idx = grep("omp_set_num_threads", processed_lines, fixed = TRUE) | ||
if (!length(idx)) return() | ||
stop(sprintf( | ||
"In %s, found 'omp_set_num_threads() usage, which could affect other packages and base R:\n%s", | ||
c_file, paste0(" ", format(idx), ":", processed_lines[idx], collapse = "\n") | ||
)) | ||
} |
This file contains 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
This file contains 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