SlideShare uma empresa Scribd logo
1 de 19
Baixar para ler offline
Parallel MCMC
         Random Number Generators
                        Summary




Parallel Bayesian computation in R ≥ 2.14
     using the packages foreach and parallel


            Matt Moores             Cathy Hargrave

           Bayesian Research & Applications Group
     Queensland University of Technology, Brisbane, Australia
                 CRICOS provider no. 00213J


            Thursday September 27, 2012




                    BRAG Sept. 27    Parallel MCMC in R
Parallel MCMC
               Random Number Generators
                              Summary


Outline



  1   Parallel MCMC
        Introduction
        R packages


  2   Random Number Generators
        RNG and parallel MCMC
        RNGs available in R




                          BRAG Sept. 27   Parallel MCMC in R
Parallel MCMC
                                             Introduction
                  Random Number Generators
                                             R packages
                                 Summary


Motivation




  Why parallel?
      large datasets
      many MCMC iterations
      multiple CPU cores now commonplace
          eg. Intel Core i5 and i7
          even mobile phones have multicore CPUs



                             BRAG Sept. 27   Parallel MCMC in R
Parallel MCMC
                                           Introduction
                Random Number Generators
                                           R packages
                               Summary


Parallel MCMC



  2 kinds of parallelism:
       concurrent MCMC chains
           always applicable
           straightforward to implement
      concurrent updates within an iteration
           only useful for a very large parameter space
           ideally in a compiled language (eg. Rcpp with OpenMP)
  also implicit parallelism, eg. with Intel Math Kernel Library




                           BRAG Sept. 27   Parallel MCMC in R
Parallel MCMC
                                      Introduction
           Random Number Generators
                                      R packages
                          Summary


Concurrent Chains




                      BRAG Sept. 27   Parallel MCMC in R
Parallel MCMC
                                          Introduction
               Random Number Generators
                                          R packages
                              Summary


Simple Network Of Workstations


  R package snow by Luke Tierney, et al.
      spawns multiple copies of R
      provides several options for inter-process communication
          TCP sockets
               available on any platform, including Microsoft Windows
          Message Passing Interface (via the package Rmpi)
          Parallel Virtual Machine (via the package rpvm)
          NetWorkSpaces (via the package nws)
      can either run on a local machine or a cluster (eg. Lyra)




                          BRAG Sept. 27   Parallel MCMC in R
Parallel MCMC
                                            Introduction
                 Random Number Generators
                                            R packages
                                Summary


multicore



  R package by Simon Urbanek
      implemented using the POSIX fork system call
            available on Linux and Mac OS X
            clones the R instance (functions + data)
            takes advantage of copy-on-write
            will fork as many processes as there are available CPU
            cores, unless told otherwise




                            BRAG Sept. 27   Parallel MCMC in R
Parallel MCMC
                                           Introduction
                Random Number Generators
                                           R packages
                               Summary


parallel




  R package parallel included in the core R distribution
      available in versions ≥ 2.14.0
      incorporates subsets of snow, multicore, and rlecuyer
      sensible default behaviour




                           BRAG Sept. 27   Parallel MCMC in R
Parallel MCMC
                                            Introduction
                 Random Number Generators
                                            R packages
                                Summary


foreach

  "syntactic sugar"
 §
  l i b r a r y ( foreach )
  library ( parallel )
  library ( doParallel )

  # w i l l a u t o m a t i c a l l y use a SOCK c l u s t e r on Windows
  # ( o t h e r w i s e uses m u l t i c o r e )
  r e g i s t e r D o P a r a l l e l ( cores = d e t e c t C o r e s ( ) )

  f o r e a c h ( i =1: getDoParWorkers ( ) ) %dopar% {
      # t h i s code w i l l be executed c o n c u r r e n t l y
       ...
  }

                            BRAG Sept. 27   Parallel MCMC in R
Parallel MCMC
                                           Introduction
                Random Number Generators
                                           R packages
                               Summary


foreach with SNOW
 §
  l i b r a r y ( foreach )
  library ( parallel )
  library ( doParallel )

  # setup l o c a l SOCK c l u s t e r f o r 4 CPU cores
  c l ← makePSOCKcluster ( 4 )
  registerDoParallel ( cl )

  f o r e a c h ( i =1: getDoParWorkers ( ) ) %dopar% {
      # t h i s code w i l l be executed c o n c u r r e n t l y
       ...
  }
  stopCluster ( cl )

                           BRAG Sept. 27   Parallel MCMC in R
Parallel MCMC
                                           Introduction
                Random Number Generators
                                           R packages
                               Summary


foreach with multicore
 §
  l i b r a r y ( foreach )
  library ( parallel )
  library ( doParallel )

  # f o r k one c h i l d process f o r each CPU core
  c l ← makeForkCluster ( d e t e c t C o r e s ( ) )
  registerDoParallel ( cl )

  f o r e a c h ( i =1: getDoParWorkers ( ) ) %dopar% {
      # t h i s code w i l l be executed c o n c u r r e n t l y
       ...
  }


                           BRAG Sept. 27   Parallel MCMC in R
Parallel MCMC
                                              Introduction
                   Random Number Generators
                                              R packages
                                  Summary


foreach with CODA


  If your Gibbs sampler returns an mcmc object, these can be
  conbined into an mcmc.list:
 §
  l i b r a r y ( coda )

  samples . l i s t ← f o r e a c h ( i =1: getDoParWorkers ( ) ,
                                   . combine=mcmc . l i s t ,
                                   . m u l t i c o m b i n e =T ) %dopar% {
    # t h i s code w i l l be executed c o n c u r r e n t l y
    ...
  }



                              BRAG Sept. 27   Parallel MCMC in R
Parallel MCMC
                                              Introduction
                  Random Number Generators
                                              R packages
                                 Summary


foreach with other libraries


  You need to declare any libraries that are used inside the child
  process. For example:
 §
  l i b r a r y ( mvtnorm )
  l i b r a r y ( coda )

  f o r e a c h ( i =1: getDoParWorkers ( ) ,
                  . packages=c ( "mvtnorm" , "coda" ) ) %dopar% {
      # t h i s code uses mcmc ( . . . ) and rmvnorm ( . . . )
       ...
  }



                              BRAG Sept. 27   Parallel MCMC in R
Parallel MCMC
                                           RNG and parallel MCMC
                Random Number Generators
                                           RNGs available in R
                               Summary


Random Number Generators for parallel MCMC


  The chains of our Gibbs sampler run independently, but:
      if the same RNG is seeded with the same value, all of the
      chains will generate the same random numbers in the
      same sequence - they will be identical!
      we either need to use:
          different seeds, or
          different random number generators
      for each chain (preferably both)
      it is also advisable to choose (or generate) different initial
      values in each chain of our Gibbs sampler



                           BRAG Sept. 27   Parallel MCMC in R
Parallel MCMC
                                             RNG and parallel MCMC
                  Random Number Generators
                                             RNGs available in R
                                 Summary


Mersenne Twister



   The default RNG in R
        pseudo-random sequence with 32bit precision
        periodicity of 219937 − 1
        takes 0.4 seconds to generate 107 random numbers
        on an Intel Core i5 running R 2.15.1 and Windows 7
   open-source implementation available at:
   http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html




Matsumoto & Nishimura (1998) TOMACS 8: 3–30.

                             BRAG Sept. 27   Parallel MCMC in R
Parallel MCMC
                                           RNG and parallel MCMC
                Random Number Generators
                                           RNGs available in R
                               Summary


Other RNGs in the base package



      Wichmann-Hill (1982) Applied Statistics 31, 188–190.
      Marsaglia-Multicarry
      (Usenet newsgroup sci.stat.math, 1997)
      Super-Duper
      (Reeds, J., Hubert, S. and Abrahams, M., 1982–4)
  For JAGS with up to 4 concurrent chains:
 §
  r n g I n i t s ← p a r a l l e l . seeds ( "base::BaseRNG" , 4 )




                           BRAG Sept. 27   Parallel MCMC in R
Parallel MCMC
                                               RNG and parallel MCMC
                    Random Number Generators
                                               RNGs available in R
                                   Summary


L’Ecuyer

         Available via R libraries rlecuyer or parallel
         Multiple independent streams of random numbers
         Periodicity ≈ 2191
         (each stream is a subsequence of length 2127 )
         0.6 seconds to generate 107 random numbers via runif
    To initialize each child process in a SNOW cluster with an
    independent stream:
   §
    c l ← makeCluster ( 4 )
    clusterSetRNGStream ( c l )
    registerDoParallel ( cl )
L’Ecuyer, et al. (2002) Operations Research, 50(6): 1073–1075.

                               BRAG Sept. 27   Parallel MCMC in R
Parallel MCMC
             Random Number Generators
                            Summary


Summary


    Most MCMC algorithms are "embarrasingly parallel"
        chains run independently
        (as long as the RNG is set up correctly)
    The R packages foreach and doParallel make parallelism
    easy, on any computing platform


    Related topics (not covered in this presentation):
        Running R on a supercomputer (eg. lyra.qut.edu.au)
        Cloud computing with Apache Hadoop
        GPU programming in R (nVidia CUDA)




                        BRAG Sept. 27   Parallel MCMC in R
Appendix   For Further Reading



For Further Reading

     Norman Matloff
     The Art of R Programming.
     No Starch Press, 2011.
     M. Schmidberger, M. Morgan, D. Eddelbuettel, H. Yu, L. Tierney & U.
     Mansmann
     State of the Art in Parallel Computing with R.
     Journal of Statistical Software, 31(1), 2009.
     P. L’Ecuyer, R. Simard, E.J. Chen & W.D. Kelton
     An Object-Oriented Random-Number Package with Many Long Streams
     and Substreams.
     Operations Research, 50(6): 1073–1075, 2002.
     M. Matsumoto & T. Nishimura
     Mersenne Twister: A 623-Dimensionally Equidistributed Uniform
     Pseudo-Random Number Generator.
     ACM Transactions on Modeling and Computer Simulation, 8: 3–30,
     1998.

                         BRAG Sept. 27   Parallel MCMC in R

Mais conteúdo relacionado

Mais procurados

OSDC 2015: Roland Kammerer | DRBD9: Managing High-Available Storage in Many-N...
OSDC 2015: Roland Kammerer | DRBD9: Managing High-Available Storage in Many-N...OSDC 2015: Roland Kammerer | DRBD9: Managing High-Available Storage in Many-N...
OSDC 2015: Roland Kammerer | DRBD9: Managing High-Available Storage in Many-N...
NETWAYS
 
Two-level Just-in-Time Compilation with One Interpreter and One Engine
Two-level Just-in-Time Compilation with One Interpreter and One EngineTwo-level Just-in-Time Compilation with One Interpreter and One Engine
Two-level Just-in-Time Compilation with One Interpreter and One Engine
Yusuke Izawa
 
Claire protorpc
Claire protorpcClaire protorpc
Claire protorpc
Fan Robbin
 
Stack Hybridization: A Mechanism for Bridging Two Compilation Strategies in a...
Stack Hybridization: A Mechanism for Bridging Two Compilation Strategies in a...Stack Hybridization: A Mechanism for Bridging Two Compilation Strategies in a...
Stack Hybridization: A Mechanism for Bridging Two Compilation Strategies in a...
Yusuke Izawa
 

Mais procurados (19)

BPF - All your packets belong to me
BPF - All your packets belong to meBPF - All your packets belong to me
BPF - All your packets belong to me
 
A Follow-up Cg Runtime Tutorial for Readers of The Cg Tutorial
A Follow-up Cg Runtime Tutorial for Readers of The Cg TutorialA Follow-up Cg Runtime Tutorial for Readers of The Cg Tutorial
A Follow-up Cg Runtime Tutorial for Readers of The Cg Tutorial
 
Challenges in GPU compilers
Challenges in GPU compilersChallenges in GPU compilers
Challenges in GPU compilers
 
OSDC 2015: Roland Kammerer | DRBD9: Managing High-Available Storage in Many-N...
OSDC 2015: Roland Kammerer | DRBD9: Managing High-Available Storage in Many-N...OSDC 2015: Roland Kammerer | DRBD9: Managing High-Available Storage in Many-N...
OSDC 2015: Roland Kammerer | DRBD9: Managing High-Available Storage in Many-N...
 
Code GPU with CUDA - Memory Subsystem
Code GPU with CUDA - Memory SubsystemCode GPU with CUDA - Memory Subsystem
Code GPU with CUDA - Memory Subsystem
 
Nug2004 yhe
Nug2004 yheNug2004 yhe
Nug2004 yhe
 
Pragmatic Optimization in Modern Programming - Mastering Compiler Optimizations
Pragmatic Optimization in Modern Programming - Mastering Compiler OptimizationsPragmatic Optimization in Modern Programming - Mastering Compiler Optimizations
Pragmatic Optimization in Modern Programming - Mastering Compiler Optimizations
 
Code GPU with CUDA - Device code optimization principle
Code GPU with CUDA - Device code optimization principleCode GPU with CUDA - Device code optimization principle
Code GPU with CUDA - Device code optimization principle
 
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the CompilerPragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
 
High Speed Decoding of Non-Binary Irregular LDPC Codes Using GPUs (Paper)
High Speed Decoding of Non-Binary Irregular LDPC Codes Using GPUs (Paper)High Speed Decoding of Non-Binary Irregular LDPC Codes Using GPUs (Paper)
High Speed Decoding of Non-Binary Irregular LDPC Codes Using GPUs (Paper)
 
20 -miscellaneous
20  -miscellaneous20  -miscellaneous
20 -miscellaneous
 
Two-level Just-in-Time Compilation with One Interpreter and One Engine
Two-level Just-in-Time Compilation with One Interpreter and One EngineTwo-level Just-in-Time Compilation with One Interpreter and One Engine
Two-level Just-in-Time Compilation with One Interpreter and One Engine
 
A Framework for Efficient Rapid Prototyping by Virtually Enlarging FPGA Resou...
A Framework for Efficient Rapid Prototyping by Virtually Enlarging FPGA Resou...A Framework for Efficient Rapid Prototyping by Virtually Enlarging FPGA Resou...
A Framework for Efficient Rapid Prototyping by Virtually Enlarging FPGA Resou...
 
Arm tools and roadmap for SVE compiler support
Arm tools and roadmap for SVE compiler supportArm tools and roadmap for SVE compiler support
Arm tools and roadmap for SVE compiler support
 
Modular Pick and Place Simulator using ROS Framework
Modular Pick and Place Simulator using ROS FrameworkModular Pick and Place Simulator using ROS Framework
Modular Pick and Place Simulator using ROS Framework
 
Veriloggen.Stream: データフローからハードウェアを作る(2018年3月3日 高位合成友の会 第5回 @東京工業大学)
Veriloggen.Stream: データフローからハードウェアを作る(2018年3月3日 高位合成友の会 第5回 @東京工業大学)Veriloggen.Stream: データフローからハードウェアを作る(2018年3月3日 高位合成友の会 第5回 @東京工業大学)
Veriloggen.Stream: データフローからハードウェアを作る(2018年3月3日 高位合成友の会 第5回 @東京工業大学)
 
Claire protorpc
Claire protorpcClaire protorpc
Claire protorpc
 
Stack Hybridization: A Mechanism for Bridging Two Compilation Strategies in a...
Stack Hybridization: A Mechanism for Bridging Two Compilation Strategies in a...Stack Hybridization: A Mechanism for Bridging Two Compilation Strategies in a...
Stack Hybridization: A Mechanism for Bridging Two Compilation Strategies in a...
 
Debugging Applications with GNU Debugger
Debugging Applications with GNU DebuggerDebugging Applications with GNU Debugger
Debugging Applications with GNU Debugger
 

Semelhante a Parallel R

R & CDK: A Sturdy Platform in the Oceans of Chemical Data}
R & CDK: A Sturdy Platform in the Oceans of Chemical Data}R & CDK: A Sturdy Platform in the Oceans of Chemical Data}
R & CDK: A Sturdy Platform in the Oceans of Chemical Data}
Rajarshi Guha
 
Through the firewall with miniCRAN
Through the firewall with miniCRANThrough the firewall with miniCRAN
Through the firewall with miniCRAN
Revolution Analytics
 
Crossing Abstraction Barriers When Debugging In Dynamic Languages
Crossing Abstraction Barriers When Debugging In Dynamic LanguagesCrossing Abstraction Barriers When Debugging In Dynamic Languages
Crossing Abstraction Barriers When Debugging In Dynamic Languages
Bastian Kruck
 
Research Inventy : International Journal of Engineering and Science is publis...
Research Inventy : International Journal of Engineering and Science is publis...Research Inventy : International Journal of Engineering and Science is publis...
Research Inventy : International Journal of Engineering and Science is publis...
researchinventy
 

Semelhante a Parallel R (20)

R workshop xx -- Parallel Computing with R
R workshop xx -- Parallel Computing with R R workshop xx -- Parallel Computing with R
R workshop xx -- Parallel Computing with R
 
R & CDK: A Sturdy Platform in the Oceans of Chemical Data}
R & CDK: A Sturdy Platform in the Oceans of Chemical Data}R & CDK: A Sturdy Platform in the Oceans of Chemical Data}
R & CDK: A Sturdy Platform in the Oceans of Chemical Data}
 
main
mainmain
main
 
Through the firewall with miniCRAN
Through the firewall with miniCRANThrough the firewall with miniCRAN
Through the firewall with miniCRAN
 
Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?Declare Your Language: What is a Compiler?
Declare Your Language: What is a Compiler?
 
Using R on High Performance Computers
Using R on High Performance ComputersUsing R on High Performance Computers
Using R on High Performance Computers
 
Wilmott Nyc Jul2012 Nag Talk John Holden
Wilmott Nyc Jul2012 Nag Talk John HoldenWilmott Nyc Jul2012 Nag Talk John Holden
Wilmott Nyc Jul2012 Nag Talk John Holden
 
Crossing Abstraction Barriers When Debugging In Dynamic Languages
Crossing Abstraction Barriers When Debugging In Dynamic LanguagesCrossing Abstraction Barriers When Debugging In Dynamic Languages
Crossing Abstraction Barriers When Debugging In Dynamic Languages
 
OpenCL programming using Python syntax
OpenCL programming using Python syntax OpenCL programming using Python syntax
OpenCL programming using Python syntax
 
Rcpp
RcppRcpp
Rcpp
 
Porting a Streaming Pipeline from Scala to Rust
Porting a Streaming Pipeline from Scala to RustPorting a Streaming Pipeline from Scala to Rust
Porting a Streaming Pipeline from Scala to Rust
 
XConf 2022 - Code As Data: How data insights on legacy codebases can fill the...
XConf 2022 - Code As Data: How data insights on legacy codebases can fill the...XConf 2022 - Code As Data: How data insights on legacy codebases can fill the...
XConf 2022 - Code As Data: How data insights on legacy codebases can fill the...
 
"Massive Parallel Decoding of Low-Density Parity-Check Codes Using Graphic Ca...
"Massive Parallel Decoding of Low-Density Parity-Check Codes Using Graphic Ca..."Massive Parallel Decoding of Low-Density Parity-Check Codes Using Graphic Ca...
"Massive Parallel Decoding of Low-Density Parity-Check Codes Using Graphic Ca...
 
Gpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cudaGpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cuda
 
L Fu - Dao: a novel programming language for bioinformatics
L Fu - Dao: a novel programming language for bioinformaticsL Fu - Dao: a novel programming language for bioinformatics
L Fu - Dao: a novel programming language for bioinformatics
 
NVIDIA HPC ソフトウエア斜め読み
NVIDIA HPC ソフトウエア斜め読みNVIDIA HPC ソフトウエア斜め読み
NVIDIA HPC ソフトウエア斜め読み
 
Partial Compilers
Partial CompilersPartial Compilers
Partial Compilers
 
Research Inventy : International Journal of Engineering and Science is publis...
Research Inventy : International Journal of Engineering and Science is publis...Research Inventy : International Journal of Engineering and Science is publis...
Research Inventy : International Journal of Engineering and Science is publis...
 
Workshop de Ruby on Rails
Workshop de Ruby on RailsWorkshop de Ruby on Rails
Workshop de Ruby on Rails
 
SF Big Analytics 2019112: Uncovering performance regressions in the TCP SACK...
 SF Big Analytics 2019112: Uncovering performance regressions in the TCP SACK... SF Big Analytics 2019112: Uncovering performance regressions in the TCP SACK...
SF Big Analytics 2019112: Uncovering performance regressions in the TCP SACK...
 

Mais de Matt Moores

R package bayesImageS: Scalable Inference for Intractable Likelihoods
R package bayesImageS: Scalable Inference for Intractable LikelihoodsR package bayesImageS: Scalable Inference for Intractable Likelihoods
R package bayesImageS: Scalable Inference for Intractable Likelihoods
Matt Moores
 
Final PhD Seminar
Final PhD SeminarFinal PhD Seminar
Final PhD Seminar
Matt Moores
 

Mais de Matt Moores (16)

Bayesian Inference and Uncertainty Quantification for Inverse Problems
Bayesian Inference and Uncertainty Quantification for Inverse ProblemsBayesian Inference and Uncertainty Quantification for Inverse Problems
Bayesian Inference and Uncertainty Quantification for Inverse Problems
 
bayesImageS: an R package for Bayesian image analysis
bayesImageS: an R package for Bayesian image analysisbayesImageS: an R package for Bayesian image analysis
bayesImageS: an R package for Bayesian image analysis
 
Exploratory Analysis of Multivariate Data
Exploratory Analysis of Multivariate DataExploratory Analysis of Multivariate Data
Exploratory Analysis of Multivariate Data
 
R package bayesImageS: Scalable Inference for Intractable Likelihoods
R package bayesImageS: Scalable Inference for Intractable LikelihoodsR package bayesImageS: Scalable Inference for Intractable Likelihoods
R package bayesImageS: Scalable Inference for Intractable Likelihoods
 
bayesImageS: Bayesian computation for medical Image Segmentation using a hidd...
bayesImageS: Bayesian computation for medical Image Segmentation using a hidd...bayesImageS: Bayesian computation for medical Image Segmentation using a hidd...
bayesImageS: Bayesian computation for medical Image Segmentation using a hidd...
 
Approximate Bayesian computation for the Ising/Potts model
Approximate Bayesian computation for the Ising/Potts modelApproximate Bayesian computation for the Ising/Potts model
Approximate Bayesian computation for the Ising/Potts model
 
Importing satellite imagery into R from NASA and the U.S. Geological Survey
Importing satellite imagery into R from NASA and the U.S. Geological SurveyImporting satellite imagery into R from NASA and the U.S. Geological Survey
Importing satellite imagery into R from NASA and the U.S. Geological Survey
 
Accelerating Pseudo-Marginal MCMC using Gaussian Processes
Accelerating Pseudo-Marginal MCMC using Gaussian ProcessesAccelerating Pseudo-Marginal MCMC using Gaussian Processes
Accelerating Pseudo-Marginal MCMC using Gaussian Processes
 
R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...
R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...
R package 'bayesImageS': a case study in Bayesian computation using Rcpp and ...
 
Bayesian modelling and computation for Raman spectroscopy
Bayesian modelling and computation for Raman spectroscopyBayesian modelling and computation for Raman spectroscopy
Bayesian modelling and computation for Raman spectroscopy
 
Final PhD Seminar
Final PhD SeminarFinal PhD Seminar
Final PhD Seminar
 
Precomputation for SMC-ABC with undirected graphical models
Precomputation for SMC-ABC with undirected graphical modelsPrecomputation for SMC-ABC with undirected graphical models
Precomputation for SMC-ABC with undirected graphical models
 
Intro to ABC
Intro to ABCIntro to ABC
Intro to ABC
 
Pre-computation for ABC in image analysis
Pre-computation for ABC in image analysisPre-computation for ABC in image analysis
Pre-computation for ABC in image analysis
 
Variational Bayes
Variational BayesVariational Bayes
Variational Bayes
 
Informative Priors for Segmentation of Medical Images
Informative Priors for Segmentation of Medical ImagesInformative Priors for Segmentation of Medical Images
Informative Priors for Segmentation of Medical Images
 

Último

+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 

Parallel R

  • 1. Parallel MCMC Random Number Generators Summary Parallel Bayesian computation in R ≥ 2.14 using the packages foreach and parallel Matt Moores Cathy Hargrave Bayesian Research & Applications Group Queensland University of Technology, Brisbane, Australia CRICOS provider no. 00213J Thursday September 27, 2012 BRAG Sept. 27 Parallel MCMC in R
  • 2. Parallel MCMC Random Number Generators Summary Outline 1 Parallel MCMC Introduction R packages 2 Random Number Generators RNG and parallel MCMC RNGs available in R BRAG Sept. 27 Parallel MCMC in R
  • 3. Parallel MCMC Introduction Random Number Generators R packages Summary Motivation Why parallel? large datasets many MCMC iterations multiple CPU cores now commonplace eg. Intel Core i5 and i7 even mobile phones have multicore CPUs BRAG Sept. 27 Parallel MCMC in R
  • 4. Parallel MCMC Introduction Random Number Generators R packages Summary Parallel MCMC 2 kinds of parallelism: concurrent MCMC chains always applicable straightforward to implement concurrent updates within an iteration only useful for a very large parameter space ideally in a compiled language (eg. Rcpp with OpenMP) also implicit parallelism, eg. with Intel Math Kernel Library BRAG Sept. 27 Parallel MCMC in R
  • 5. Parallel MCMC Introduction Random Number Generators R packages Summary Concurrent Chains BRAG Sept. 27 Parallel MCMC in R
  • 6. Parallel MCMC Introduction Random Number Generators R packages Summary Simple Network Of Workstations R package snow by Luke Tierney, et al. spawns multiple copies of R provides several options for inter-process communication TCP sockets available on any platform, including Microsoft Windows Message Passing Interface (via the package Rmpi) Parallel Virtual Machine (via the package rpvm) NetWorkSpaces (via the package nws) can either run on a local machine or a cluster (eg. Lyra) BRAG Sept. 27 Parallel MCMC in R
  • 7. Parallel MCMC Introduction Random Number Generators R packages Summary multicore R package by Simon Urbanek implemented using the POSIX fork system call available on Linux and Mac OS X clones the R instance (functions + data) takes advantage of copy-on-write will fork as many processes as there are available CPU cores, unless told otherwise BRAG Sept. 27 Parallel MCMC in R
  • 8. Parallel MCMC Introduction Random Number Generators R packages Summary parallel R package parallel included in the core R distribution available in versions ≥ 2.14.0 incorporates subsets of snow, multicore, and rlecuyer sensible default behaviour BRAG Sept. 27 Parallel MCMC in R
  • 9. Parallel MCMC Introduction Random Number Generators R packages Summary foreach "syntactic sugar" § l i b r a r y ( foreach ) library ( parallel ) library ( doParallel ) # w i l l a u t o m a t i c a l l y use a SOCK c l u s t e r on Windows # ( o t h e r w i s e uses m u l t i c o r e ) r e g i s t e r D o P a r a l l e l ( cores = d e t e c t C o r e s ( ) ) f o r e a c h ( i =1: getDoParWorkers ( ) ) %dopar% { # t h i s code w i l l be executed c o n c u r r e n t l y ... } BRAG Sept. 27 Parallel MCMC in R
  • 10. Parallel MCMC Introduction Random Number Generators R packages Summary foreach with SNOW § l i b r a r y ( foreach ) library ( parallel ) library ( doParallel ) # setup l o c a l SOCK c l u s t e r f o r 4 CPU cores c l ← makePSOCKcluster ( 4 ) registerDoParallel ( cl ) f o r e a c h ( i =1: getDoParWorkers ( ) ) %dopar% { # t h i s code w i l l be executed c o n c u r r e n t l y ... } stopCluster ( cl ) BRAG Sept. 27 Parallel MCMC in R
  • 11. Parallel MCMC Introduction Random Number Generators R packages Summary foreach with multicore § l i b r a r y ( foreach ) library ( parallel ) library ( doParallel ) # f o r k one c h i l d process f o r each CPU core c l ← makeForkCluster ( d e t e c t C o r e s ( ) ) registerDoParallel ( cl ) f o r e a c h ( i =1: getDoParWorkers ( ) ) %dopar% { # t h i s code w i l l be executed c o n c u r r e n t l y ... } BRAG Sept. 27 Parallel MCMC in R
  • 12. Parallel MCMC Introduction Random Number Generators R packages Summary foreach with CODA If your Gibbs sampler returns an mcmc object, these can be conbined into an mcmc.list: § l i b r a r y ( coda ) samples . l i s t ← f o r e a c h ( i =1: getDoParWorkers ( ) , . combine=mcmc . l i s t , . m u l t i c o m b i n e =T ) %dopar% { # t h i s code w i l l be executed c o n c u r r e n t l y ... } BRAG Sept. 27 Parallel MCMC in R
  • 13. Parallel MCMC Introduction Random Number Generators R packages Summary foreach with other libraries You need to declare any libraries that are used inside the child process. For example: § l i b r a r y ( mvtnorm ) l i b r a r y ( coda ) f o r e a c h ( i =1: getDoParWorkers ( ) , . packages=c ( "mvtnorm" , "coda" ) ) %dopar% { # t h i s code uses mcmc ( . . . ) and rmvnorm ( . . . ) ... } BRAG Sept. 27 Parallel MCMC in R
  • 14. Parallel MCMC RNG and parallel MCMC Random Number Generators RNGs available in R Summary Random Number Generators for parallel MCMC The chains of our Gibbs sampler run independently, but: if the same RNG is seeded with the same value, all of the chains will generate the same random numbers in the same sequence - they will be identical! we either need to use: different seeds, or different random number generators for each chain (preferably both) it is also advisable to choose (or generate) different initial values in each chain of our Gibbs sampler BRAG Sept. 27 Parallel MCMC in R
  • 15. Parallel MCMC RNG and parallel MCMC Random Number Generators RNGs available in R Summary Mersenne Twister The default RNG in R pseudo-random sequence with 32bit precision periodicity of 219937 − 1 takes 0.4 seconds to generate 107 random numbers on an Intel Core i5 running R 2.15.1 and Windows 7 open-source implementation available at: http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/emt.html Matsumoto & Nishimura (1998) TOMACS 8: 3–30. BRAG Sept. 27 Parallel MCMC in R
  • 16. Parallel MCMC RNG and parallel MCMC Random Number Generators RNGs available in R Summary Other RNGs in the base package Wichmann-Hill (1982) Applied Statistics 31, 188–190. Marsaglia-Multicarry (Usenet newsgroup sci.stat.math, 1997) Super-Duper (Reeds, J., Hubert, S. and Abrahams, M., 1982–4) For JAGS with up to 4 concurrent chains: § r n g I n i t s ← p a r a l l e l . seeds ( "base::BaseRNG" , 4 ) BRAG Sept. 27 Parallel MCMC in R
  • 17. Parallel MCMC RNG and parallel MCMC Random Number Generators RNGs available in R Summary L’Ecuyer Available via R libraries rlecuyer or parallel Multiple independent streams of random numbers Periodicity ≈ 2191 (each stream is a subsequence of length 2127 ) 0.6 seconds to generate 107 random numbers via runif To initialize each child process in a SNOW cluster with an independent stream: § c l ← makeCluster ( 4 ) clusterSetRNGStream ( c l ) registerDoParallel ( cl ) L’Ecuyer, et al. (2002) Operations Research, 50(6): 1073–1075. BRAG Sept. 27 Parallel MCMC in R
  • 18. Parallel MCMC Random Number Generators Summary Summary Most MCMC algorithms are "embarrasingly parallel" chains run independently (as long as the RNG is set up correctly) The R packages foreach and doParallel make parallelism easy, on any computing platform Related topics (not covered in this presentation): Running R on a supercomputer (eg. lyra.qut.edu.au) Cloud computing with Apache Hadoop GPU programming in R (nVidia CUDA) BRAG Sept. 27 Parallel MCMC in R
  • 19. Appendix For Further Reading For Further Reading Norman Matloff The Art of R Programming. No Starch Press, 2011. M. Schmidberger, M. Morgan, D. Eddelbuettel, H. Yu, L. Tierney & U. Mansmann State of the Art in Parallel Computing with R. Journal of Statistical Software, 31(1), 2009. P. L’Ecuyer, R. Simard, E.J. Chen & W.D. Kelton An Object-Oriented Random-Number Package with Many Long Streams and Substreams. Operations Research, 50(6): 1073–1075, 2002. M. Matsumoto & T. Nishimura Mersenne Twister: A 623-Dimensionally Equidistributed Uniform Pseudo-Random Number Generator. ACM Transactions on Modeling and Computer Simulation, 8: 3–30, 1998. BRAG Sept. 27 Parallel MCMC in R