Presentation is loading. Please wait.

Presentation is loading. Please wait.

Parallel Programming with R ENDER AHMET YURT 121402101.

Similar presentations


Presentation on theme: "Parallel Programming with R ENDER AHMET YURT 121402101."— Presentation transcript:

1 Parallel Programming with R ENDER AHMET YURT 121402101

2  R is a programming language.  For statistical computing.  Open source.  Command Line or GUI.  Linear, non-linear modeling, classical statistical tests, times series, clustering, classification.  Developing R packages.  Try R http://tryr.codeschool.com/ WHAT IS R?

3 > 5+5 [1] 10 > x <- c(1,2,3,4,5,6) > x*2 [1] 2 4 6 8 10 12 > y <- x > mean(y) [1] 3.5 SOME R

4  R is single-thread.  CPU leverage without extra packages.  Plenty of them,  RMPI (R Message-Passing Interface)  NWS (Network Spaces)  SNOW (Simple Network of Workstations)  SPRINT (Simple Parallel R Interface)  FOREACH  MULTICORE  PARALLEL R & PARALLEL PROGRAMMING

5  MPI Interface.  MPI is developed by C or C++.  RMPI uses low level MPI functions.  Provides non-level C or C++ users. RMPI

6 # Load the R MPI package if it is not already loaded. if (!is.loaded("mpi_initialize")) { library("Rmpi") } # Spawn as many slaves as possible mpi.spawn.Rslaves() # In case R exits unexpectedly, have it automatically clean up # resources taken up by Rmpi (slaves, memory, etc...).Last <- function(){ if (is.loaded("mpi_initialize")){ if (mpi.comm.size(1) > 0){ print("Please use mpi.close.Rslaves() to close slaves.") mpi.close.Rslaves() } print("Please use mpi.quit() to quit R").Call("mpi_finalize") } # Tell all slaves to return a message identifying themselves mpi.remote.exec(paste("I am",mpi.comm.rank(),"of",mpi.comm.size())) # Tell all slaves to close down, and exit the program mpi.close.Rslaves() mpi.quit() SOME RMPI

7  Simple Network of Workstations.  High level interfaces for workstations to do parallel computing.  Based Master-Slave model  Uses three based interface to create a virtual connection  Socket  PVM (Parallel Virtual Machine)  MPI (Message Passing Interface) SNOW

8 > library(snow) > library(rlecuyer) # Now set up some sample data. Here I take 100 random draws, with replacement, from the integers in \([0,5]\). > x <- sample(0:5, 100, replace = TRUE) > mean(x) [1] 2.64 SOME SNOW

9 # Define a simple function to calculate a single bootstrapped mean from a given vector: > bs.mean <- function(v) { + s <- sample(v, length(v), replace = TRUE) + mean(s) + } SOME SNOW (2)

10 # Now it’s time to set up the cluster. Here I set up a SOCK-type connection, which can be used to set up multiple R instances on the local machine and/or to set up R instances on remote machines through ssh connections. snow offers other connection options that may be more convenient or necessary depending on your environment (for instance, MPI was needed on the OSC cluster). > cl <- makeCluster(c("localhost", "localhost"), type = "SOCK") SOME SNOW (3)

11  One machine multiple cores.  Faster than others.  Not work on MS Windows MULTICORE

12  mclapply - parallelized version of lapply.  lapply return a list same as its argument  A little example for lapply. > x <- list(a = 1:10, beta = exp(-3:3), logic = c(TRUE,FALSE,FALSE,TRUE)) # compute the list mean for each list element >lapply(x,mean) RUNNNN!!!!  EXAMPLE TIME!!! MULTICORE (2)

13  Based on multicore and snow.  Solve Single Program – Multiple Data Problem.  Single Machines Multicore  Several Machines Snow  MPI supports RMPI package  EXAMPLE TIME!!! PARALLEL

14 THANK YOU


Download ppt "Parallel Programming with R ENDER AHMET YURT 121402101."

Similar presentations


Ads by Google