Skip to content

Commit

Permalink
new omp_set_nested_linter for C (#6347)
Browse files Browse the repository at this point in the history
* Add a linter for calls to omp_set_num_threads

* simplify, comment

* refactor

* new omp_set_nested_linter

* #define in myomp.h is not needed since macro is not used
  • Loading branch information
MichaelChirico authored Aug 21, 2024
1 parent 26c2c08 commit caacbbd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
11 changes: 11 additions & 0 deletions .ci/linters/c/omp_set_nested_linter.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Ensure no calls to omp_set_nested() as
# i) it's hard to fully honor OMP_THREAD_LIMIT as required by CRAN, and
# ii) a simpler non-nested approach is always preferable if possible, as has been the case so far
omp_set_nested_linter = function(c_obj) {
idx = grep("omp_set_nested", c_obj$lines, fixed=TRUE)
if (!length(idx)) return()
stop(sprintf(
"In %s, found omp_set_nested() usage, please reconsider:\n%s",
c_obj$path, paste0(" ", format(idx), ":", c_obj$lines[idx], collapse = "\n")
))
}
5 changes: 0 additions & 5 deletions .dev/CRAN_Release.cmd
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,6 @@ grep -RI --exclude-dir=".git" --exclude="*.md" --exclude="*~" --color='auto' -P
# Unicode is now ok. This unicode in tests.Rraw is passing on CRAN.
grep -RI --exclude-dir=".git" --exclude="*.md" --exclude="*~" --color='auto' -n "[\]u[0-9]" ./


# Ensure no calls to omp_set_nested() as i) it's hard to fully honor OMP_THREAD_LIMIT as required by CRAN, and
# ii) a simpler non-nested approach is always preferable if possible, as has been the case so far
grep omp_set_nested ./src/*.c

# Ensure no calls to omp_get_max_threads() also since access should be via getDTthreads()
grep --exclude="./src/openmp-utils.c" omp_get_max_threads ./src/*

Expand Down
1 change: 0 additions & 1 deletion src/myomp.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
#define omp_get_max_threads() 1
#define omp_get_thread_limit() 1
#define omp_get_num_procs() 1
#define omp_set_nested(a) // empty statement to remove the call
#define omp_get_wtime() 0
#define MY_OPENMP 0
#endif
Expand Down

0 comments on commit caacbbd

Please sign in to comment.