quantixed / TrackMateR

Analysis of TrackMate XML outputs in R
https://quantixed.github.io/TrackMateR/
Other
12 stars 1 forks source link

WISH: parallel::detectCores() -> parallelly::availableCores() #10

Closed HenrikBengtsson closed 1 year ago

HenrikBengtsson commented 1 year ago

readTrackMateXML() parallelizes on all hardware CPU cores by default:

https://github.com/quantixed/TrackMateR/blob/d6b981f00c4024d61ffae183b47aaf5a78fb8d2d/R/readTrackMateXML.r#L54

Using parallel::detectCores() is problematic for many reasons. I explain why in my 'Please Avoid detectCores() in your R Packages' 2022-12-05 blog post. The simplest fix is to address most of the problems is to replace it with parallelly::availableCores().

FWIW, availableCores() is also agile to _R_CHECK_LIMIT_CORES_, so you can replace all of:

https://github.com/quantixed/TrackMateR/blob/d6b981f00c4024d61ffae183b47aaf5a78fb8d2d/R/readTrackMateXML.r#L48-L55

with

numCores <- parallelly::availableCores()
quantixed commented 1 year ago

You convinced me. Now added.