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

Threading speedup #131

Open
muschellij2 opened this issue Jan 13, 2021 · 1 comment
Open

Threading speedup #131

muschellij2 opened this issue Jan 13, 2021 · 1 comment

Comments

@muschellij2
Copy link
Collaborator

Describe the bug
Question

  1. Should multi-threading help decrease rigid-body registration?
  2. Do you have comparable timings as blow

To Reproduce
Steps to reproduce the behavior

library(ANTsRCore)
#> 
#> Attaching package: 'ANTsRCore'
#> The following objects are masked from 'package:stats':
#> 
#>     sd, var
#> The following objects are masked from 'package:base':
#> 
#>     all, any, apply, max, min, prod, range, sum
library(kirby21.t1)
library(kirby21.flair)
kirby21.t1::download_t1_data(id = 113)
#> [1] TRUE
t1 = kirby21.t1::get_t1_filenames(id = 113, visit = 1)
kirby21.flair::download_flair_data(id = 113)
#> [1] TRUE
flair = kirby21.flair::get_flair_filenames(id = 113, visit = 1)
fi <- antsImageRead(t1)
fi
#> antsImage
#>   Pixel Type          : float 
#>   Components Per Pixel: 1 
#>   Dimensions          : 170x256x256 
#>   Voxel Spacing       : 1.20000004768372x1x1 
#>   Origin              : 202.8 0 0 
#>   Direction           : -1 0 0 0 1 0 0 0 1 
#>   Filename           : /Users/johnmuschelli/Library/R/4.0/library/kirby21.t1/visit_1/113/113-01-T1.nii.gz
mi <- antsImageRead(flair)
mi
#> antsImage
#>   Pixel Type          : float 
#>   Components Per Pixel: 1 
#>   Dimensions          : 327x576x576 
#>   Voxel Spacing       : 0.550000011920929x0.416666656732559x0.416666656732559 
#>   Origin              : 179.3 239.5833 0 
#>   Direction           : -1 0 0 0 -1 0 0 0 1 
#>   Filename           : /Users/johnmuschelli/Library/R/4.0/library/kirby21.flair/visit_1/113/113-01-FLAIR.nii.gz
Sys.setenv(ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS = 8)
speed2 = system.time({
  rig <- antsRegistration(fixed=fi, moving = mi,
                          typeofTransform = 'Rigid', verbose = TRUE)
})
print(speed2)
#>    user  system elapsed 
#> 108.832   3.215  18.748
Sys.setenv(ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS = 1)
speed1 = system.time({
  rig <- antsRegistration(fixed=fi, moving = mi,
                          typeofTransform = 'Rigid', verbose = TRUE)
})
print(speed1)
#>    user  system elapsed 
#> 117.935   1.233  19.433

Created on 2021-01-13 by the reprex package (v0.3.0.9001)

Session info

sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.2 (2020-06-22)
#>  os       macOS Catalina 10.15.7      
#>  system   x86_64, darwin17.0          
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       America/New_York            
#>  date     2021-01-13                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package       * version    date       lib
#>  ANTsRCore     * 0.7.4.6    2020-07-07 [2]
#>  assertthat      0.2.1      2019-03-21 [2]
#>  backports       1.2.0      2020-11-02 [1]
#>  cli             2.2.0      2020-11-20 [1]
#>  crayon          1.3.4      2017-09-16 [2]
#>  digest          0.6.27     2020-10-24 [1]
#>  ellipsis        0.3.1      2020-05-15 [2]
#>  evaluate        0.14       2019-05-28 [2]
#>  fansi           0.4.1      2020-01-08 [2]
#>  fs              1.5.0      2020-07-31 [2]
#>  git2r           0.28.0     2021-01-11 [1]
#>  glue            1.4.2      2020-08-27 [1]
#>  highr           0.8        2019-03-20 [2]
#>  htmltools       0.5.0      2020-06-16 [2]
#>  ITKR            0.5.3.2.0  2020-06-01 [2]
#>  kirby21.base    1.7.4      2020-10-01 [1]
#>  kirby21.flair * 1.7.0      2021-01-13 [1]
#>  kirby21.t1    * 1.7.3.2    2021-01-09 [1]
#>  knitr           1.30       2020-09-22 [1]
#>  lattice         0.20-41    2020-04-02 [2]
#>  lifecycle       0.2.0      2020-03-06 [2]
#>  magrittr        2.0.1      2020-11-17 [1]
#>  Matrix          1.2-18     2019-11-27 [2]
#>  pillar          1.4.7      2020-11-20 [1]
#>  pkgconfig       2.0.3      2019-09-22 [2]
#>  purrr           0.3.4      2020-04-17 [2]
#>  Rcpp            1.0.5      2020-07-06 [1]
#>  RcppEigen       0.3.3.7.0  2019-11-16 [2]
#>  reprex          0.3.0.9001 2020-09-30 [1]
#>  rlang           0.4.9.9000 2020-12-11 [1]
#>  rmarkdown       2.5        2020-10-21 [1]
#>  rstudioapi      0.13       2020-11-12 [1]
#>  sessioninfo     1.1.1      2018-11-05 [2]
#>  stringi         1.5.3      2020-09-09 [1]
#>  stringr         1.4.0      2019-02-10 [2]
#>  styler          1.3.2      2020-02-23 [2]
#>  tibble          3.0.4      2020-10-12 [1]
#>  vctrs           0.3.5      2020-11-17 [1]
#>  withr           2.3.0      2020-09-22 [1]
#>  xfun            0.19       2020-10-30 [1]
#>  yaml            2.2.1      2020-02-01 [2]
#>  source                                    
#>  Github (muschellij2/ANTsRCore@61c37a1)    
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.2)                            
#>  Github (ropensci/git2r@4e342ca)           
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.0)                            
#>  Github (stnava/ITKR@9bdd5f8)              
#>  local                                     
#>  Github (muschellij2/kirby21.flair@461077a)
#>  local                                     
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.0)                            
#>  Github (tidyverse/reprex@d3fc4b8)         
#>  Github (r-lib/rlang@1939a71)              
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.0)                            
#> 
#> [1] /Users/johnmuschelli/Library/R/4.0/library
#> [2] /Library/Frameworks/R.framework/Versions/4.0/Resources/library
library(ANTsRCore)
#> 
#> Attaching package: 'ANTsRCore'
#> The following objects are masked from 'package:stats':
#> 
#>     sd, var
#> The following objects are masked from 'package:base':
#> 
#>     all, any, apply, max, min, prod, range, sum
library(kirby21.t1)
library(kirby21.flair)
kirby21.t1::download_t1_data(id = 113)
#> [1] TRUE
t1 = kirby21.t1::get_t1_filenames(id = 113, visit = 1)
kirby21.flair::download_flair_data(id = 113)
#> [1] TRUE
flair = kirby21.flair::get_flair_filenames(id = 113, visit = 1)
fi <- antsImageRead(t1)
fi
#> antsImage
#>   Pixel Type          : float 
#>   Components Per Pixel: 1 
#>   Dimensions          : 170x256x256 
#>   Voxel Spacing       : 1.20000004768372x1x1 
#>   Origin              : 202.8 0 0 
#>   Direction           : -1 0 0 0 1 0 0 0 1 
#>   Filename           : /Users/johnmuschelli/Library/R/4.0/library/kirby21.t1/visit_1/113/113-01-T1.nii.gz
mi <- antsImageRead(flair)
mi
#> antsImage
#>   Pixel Type          : float 
#>   Components Per Pixel: 1 
#>   Dimensions          : 327x576x576 
#>   Voxel Spacing       : 0.550000011920929x0.416666656732559x0.416666656732559 
#>   Origin              : 179.3 239.5833 0 
#>   Direction           : -1 0 0 0 -1 0 0 0 1 
#>   Filename           : /Users/johnmuschelli/Library/R/4.0/library/kirby21.flair/visit_1/113/113-01-FLAIR.nii.gz
Sys.setenv(ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS = 8)
speed2 = system.time({
  rig <- antsRegistration(fixed=fi, moving = mi,
                          typeofTransform = 'SyN', verbose = TRUE)
})
print(speed2)
#>    user  system elapsed 
#> 271.658   8.046  56.734
Sys.setenv(ITK_GLOBAL_DEFAULT_NUMBER_OF_THREADS = 1)
speed1 = system.time({
  rig <- antsRegistration(fixed=fi, moving = mi,
                          typeofTransform = 'SyN', verbose = TRUE)
})
print(speed1)
#>    user  system elapsed 
#> 306.933   3.898  59.187

Created on 2021-01-13 by the reprex package (v0.3.0.9001)

Session info

sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 4.0.2 (2020-06-22)
#>  os       macOS Catalina 10.15.7      
#>  system   x86_64, darwin17.0          
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       America/New_York            
#>  date     2021-01-13                  
#> 
#> ─ Packages ───────────────────────────────────────────────────────────────────
#>  package       * version    date       lib
#>  ANTsRCore     * 0.7.4.6    2020-07-07 [2]
#>  assertthat      0.2.1      2019-03-21 [2]
#>  backports       1.2.0      2020-11-02 [1]
#>  cli             2.2.0      2020-11-20 [1]
#>  crayon          1.3.4      2017-09-16 [2]
#>  digest          0.6.27     2020-10-24 [1]
#>  ellipsis        0.3.1      2020-05-15 [2]
#>  evaluate        0.14       2019-05-28 [2]
#>  fansi           0.4.1      2020-01-08 [2]
#>  fs              1.5.0      2020-07-31 [2]
#>  git2r           0.28.0     2021-01-11 [1]
#>  glue            1.4.2      2020-08-27 [1]
#>  highr           0.8        2019-03-20 [2]
#>  htmltools       0.5.0      2020-06-16 [2]
#>  ITKR            0.5.3.2.0  2020-06-01 [2]
#>  kirby21.base    1.7.4      2020-10-01 [1]
#>  kirby21.flair * 1.7.0      2021-01-13 [1]
#>  kirby21.t1    * 1.7.3.2    2021-01-09 [1]
#>  knitr           1.30       2020-09-22 [1]
#>  lattice         0.20-41    2020-04-02 [2]
#>  lifecycle       0.2.0      2020-03-06 [2]
#>  magrittr        2.0.1      2020-11-17 [1]
#>  Matrix          1.2-18     2019-11-27 [2]
#>  pillar          1.4.7      2020-11-20 [1]
#>  pkgconfig       2.0.3      2019-09-22 [2]
#>  purrr           0.3.4      2020-04-17 [2]
#>  Rcpp            1.0.5      2020-07-06 [1]
#>  RcppEigen       0.3.3.7.0  2019-11-16 [2]
#>  reprex          0.3.0.9001 2020-09-30 [1]
#>  rlang           0.4.9.9000 2020-12-11 [1]
#>  rmarkdown       2.5        2020-10-21 [1]
#>  rstudioapi      0.13       2020-11-12 [1]
#>  sessioninfo     1.1.1      2018-11-05 [2]
#>  stringi         1.5.3      2020-09-09 [1]
#>  stringr         1.4.0      2019-02-10 [2]
#>  styler          1.3.2      2020-02-23 [2]
#>  tibble          3.0.4      2020-10-12 [1]
#>  vctrs           0.3.5      2020-11-17 [1]
#>  withr           2.3.0      2020-09-22 [1]
#>  xfun            0.19       2020-10-30 [1]
#>  yaml            2.2.1      2020-02-01 [2]
#>  source                                    
#>  Github (muschellij2/ANTsRCore@61c37a1)    
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.2)                            
#>  Github (ropensci/git2r@4e342ca)           
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.0)                            
#>  Github (stnava/ITKR@9bdd5f8)              
#>  local                                     
#>  Github (muschellij2/kirby21.flair@461077a)
#>  local                                     
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.0)                            
#>  Github (tidyverse/reprex@d3fc4b8)         
#>  Github (r-lib/rlang@1939a71)              
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.0)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.2)                            
#>  CRAN (R 4.0.0)                            
#> 
#> [1] /Users/johnmuschelli/Library/R/4.0/library
#> [2] /Library/Frameworks/R.framework/Versions/4.0/Resources/library
@muschellij2
Copy link
Collaborator Author

Related to ANTsX/ANTs#1017

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

No branches or pull requests

1 participant