ANTsX / ANTsR

R interface to the ANTs biomedical image processing library
https://antsx.github.io/ANTsR
Apache License 2.0
127 stars 35 forks source link

ITK_GLOBAL_NUMBER_OF_THREADS is ignored #390

Closed muratmaga closed 5 months ago

muratmaga commented 5 months ago

I am trying to do measure performance scaling for a project and this code executes pretty much the same amount of time regardless of what I set the ITK_GLOBAL_NUMBER_OF_THREADS to. I tried setting in R with Sys.setenv and also in shell prior to starting R. Both had no effect


fi <- antsImageRead(getANTsRData("r16") ) %>% resampleImage(., c(1024, 1024), useVoxels = TRUE)
mi <- antsImageRead(getANTsRData("r64") ) %>% resampleImage(., c(1024, 1024), useVoxels = TRUE)

f=function(X) {
  antsRegistration(fi, mi, "SyNOnly",  
                   synMetric="CC", 
                   synSampling=4, synits="0x0x0x1000", 
                   smoothingsigmas="3x2x1x0" 
                   shrinkfactors="4x3x2x1")
}

cores=c(64, 32, 16, 8, 4)

time=NULL
for (i in cores){
Sys.setenv(ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=i)
tt=Sys.time()
f(i)
time=rbind(time, cbind(i, Sys.time()-tt))
}

This is not a big deal for me, as I typically prefer to use the full number of cores. I wanted to let people now.

dorianps commented 5 months ago

I think setting it in the console should work fine. See this old thread for some tests I ran long time ago.

https://github.com/dorianps/LESYMAP/issues/15

On Tue, Jan 23, 2024, 7:54 PM muratmaga @.***> wrote:

I am trying to do measure performance scaling for a project and this code executes pretty much the same amount of time regardless of what I set the ITK_GLOBAL_NUMBER_OF_THREADS to. I tried setting in R with Sys.setenv and also in shell prior to starting R. Both had no effect

fi <- antsImageRead(getANTsRData("r16") ) %>% resampleImage(., c(1024, 1024), useVoxels = TRUE)mi <- antsImageRead(getANTsRData("r64") ) %>% resampleImage(., c(1024, 1024), useVoxels = TRUE) f=function(X) { antsRegistration(fi, mi, "SyNOnly", synMetric="CC", synSampling=4, synits="0x0x0x1000", smoothingsigmas="3x2x1x0" shrinkfactors="4x3x2x1") } cores=c(64, 32, 16, 8, 4) time=NULLfor (i in cores){ Sys.setenv(ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS=i)tt=Sys.time() f(i)time=rbind(time, cbind(i, Sys.time()-tt)) }

This is not a big deal for me, as I typically prefer to use the full number of cores. I wanted to let people now.

— Reply to this email directly, view it on GitHub https://github.com/ANTsX/ANTsR/issues/390, or unsubscribe https://github.com/notifications/unsubscribe-auth/ACFJU7MYJ4OIAHXTJR5XCODYQBLSTAVCNFSM6AAAAABCH5BZNKVHI2DSMVQWIX3LMV43ASLTON2WKOZSGA4TOMRRHE4DKMY . You are receiving this because you are subscribed to this thread.Message ID: @.***>

muratmaga commented 5 months ago

Thanks. I retried with the using the terminal window in the Rstudio, and yes setting the variable prior to starting R works.