Rdsm: Distributed (Quasi-)Threads Programming in R , Gaithersburg, - - PowerPoint PPT Presentation

rdsm distributed quasi threads programming in r
SMART_READER_LITE
LIVE PREVIEW

Rdsm: Distributed (Quasi-)Threads Programming in R , Gaithersburg, - - PowerPoint PPT Presentation

Rdsm: Distributed (Quasi-)Threads Programming in R , Gaithersburg, MD July 21, 2010 Norm Matloff Department of Computer Science University of California at Davis Davis, CA 95616 USA matloff@cs.ucdavis.edu Parallel R Many excellent packages


slide-1
SLIDE 1

Rdsm: Distributed (Quasi-)Threads Programming in R , Gaithersburg, MD July 21, 2010

Norm Matloff Department of Computer Science University of California at Davis Davis, CA 95616 USA matloff@cs.ucdavis.edu

slide-2
SLIDE 2

Parallel R

Many excellent packages are available.

slide-3
SLIDE 3

Parallel R

Many excellent packages are available. But most use message-passing paradigm

  • r variants, e.g. Rmpi, snow.
slide-4
SLIDE 4

Parallel R

Many excellent packages are available. But most use message-passing paradigm

  • r variants, e.g. Rmpi, snow.

True shared-memory choices very limited.

slide-5
SLIDE 5

Parallel R

Many excellent packages are available. But most use message-passing paradigm

  • r variants, e.g. Rmpi, snow.

True shared-memory choices very limited.

bigmemory attached C (OpenMP, CUDA)

slide-6
SLIDE 6

¡Arriba sharing!

slide-7
SLIDE 7

¡Arriba sharing!

Many in the parallel processing community consider shared-memory paradigm to be clearer, more concise, e.g. Chandra (2001), Hess (2002).

slide-8
SLIDE 8

¡Arriba sharing!

Many in the parallel processing community consider shared-memory paradigm to be clearer, more concise, e.g. Chandra (2001), Hess (2002). Conversion from sequential code easier than in message-passing case.

slide-9
SLIDE 9

Why Threads?

My definition here: Concurrent processes, communicating through shared memory.

slide-10
SLIDE 10

Why Threads?

My definition here: Concurrent processes, communicating through shared memory. Enable parallel computation.

slide-11
SLIDE 11

Why Threads?

My definition here: Concurrent processes, communicating through shared memory. Enable parallel computation.

Standard approach for speedup on shared-memory machines.

slide-12
SLIDE 12

Why Threads?

My definition here: Concurrent processes, communicating through shared memory. Enable parallel computation.

Standard approach for speedup on shared-memory machines.

Enable parallel I/O!

slide-13
SLIDE 13

Why Threads?

My definition here: Concurrent processes, communicating through shared memory. Enable parallel computation.

Standard approach for speedup on shared-memory machines.

Enable parallel I/O!

Perhaps less well-known, more commonly used.

slide-14
SLIDE 14

Why Threads?

My definition here: Concurrent processes, communicating through shared memory. Enable parallel computation.

Standard approach for speedup on shared-memory machines.

Enable parallel I/O!

Perhaps less well-known, more commonly used. E.g. Web servers.

slide-15
SLIDE 15

Rdsm: History and Motivation

slide-16
SLIDE 16

Rdsm: History and Motivation

Goals:

slide-17
SLIDE 17

Rdsm: History and Motivation

Goals:

Shared-memory vehicle for R, providing threads-like environment.

slide-18
SLIDE 18

Rdsm: History and Motivation

Goals:

Shared-memory vehicle for R, providing threads-like environment. Distributed computing capability, e.g. for collaborative tools.

slide-19
SLIDE 19

Rdsm: History and Motivation

Goals:

Shared-memory vehicle for R, providing threads-like environment. Distributed computing capability, e.g. for collaborative tools.

Easy to build on my previous product, PerlDSM (Matloff, 2002).

slide-20
SLIDE 20

What Is Rdsm?

slide-21
SLIDE 21

What Is Rdsm?

Provides R programmers with a threads-like programming environment:

slide-22
SLIDE 22

What Is Rdsm?

Provides R programmers with a threads-like programming environment:

Multiple R processes.

slide-23
SLIDE 23

What Is Rdsm?

Provides R programmers with a threads-like programming environment:

Multiple R processes. Read/write shared variables, accessed through ordinary R syntax.

slide-24
SLIDE 24

What Is Rdsm?

Provides R programmers with a threads-like programming environment:

Multiple R processes. Read/write shared variables, accessed through ordinary R syntax. Locks, barriers, wait/signal, etc.

slide-25
SLIDE 25

What Is Rdsm?

Provides R programmers with a threads-like programming environment:

Multiple R processes. Read/write shared variables, accessed through ordinary R syntax. Locks, barriers, wait/signal, etc.

Platforms: Processes can be on the same mulicore machine or on distributed, geographically disperse machines.

slide-26
SLIDE 26

Applications of Rdsm

slide-27
SLIDE 27

Applications of Rdsm

Performance programming, in “embarrassingly parallel” (EP) settings.

slide-28
SLIDE 28

Applications of Rdsm

Performance programming, in “embarrassingly parallel” (EP) settings. EP is possibly the limit for any parallel R, but there are lots of EP apps.

slide-29
SLIDE 29

Applications of Rdsm

Performance programming, in “embarrassingly parallel” (EP) settings. EP is possibly the limit for any parallel R, but there are lots of EP apps. Nothing to be embarrassed about. :-)

slide-30
SLIDE 30

Applications of Rdsm

Performance programming, in “embarrassingly parallel” (EP) settings. EP is possibly the limit for any parallel R, but there are lots of EP apps. Nothing to be embarrassed about. :-) Parallel I/O applications, e.g. parallel collection of Web data and its concurrent statistical analysis.

slide-31
SLIDE 31

Applications of Rdsm

Performance programming, in “embarrassingly parallel” (EP) settings. EP is possibly the limit for any parallel R, but there are lots of EP apps. Nothing to be embarrassed about. :-) Parallel I/O applications, e.g. parallel collection of Web data and its concurrent statistical analysis. Collaborative tools.

slide-32
SLIDE 32

Applications of Rdsm

Performance programming, in “embarrassingly parallel” (EP) settings. EP is possibly the limit for any parallel R, but there are lots of EP apps. Nothing to be embarrassed about. :-) Parallel I/O applications, e.g. parallel collection of Web data and its concurrent statistical analysis. Collaborative tools. Even games!

slide-33
SLIDE 33

What Does Rdsm Code Look Like?

slide-34
SLIDE 34

What Does Rdsm Code Look Like?

Answer: Except for initialization, it looks just like—and IS—ordinary R code.

slide-35
SLIDE 35

What Does Rdsm Code Look Like?

Answer: Except for initialization, it looks just like—and IS—ordinary R code. For example, to replace the 5th column of a shared matrix m by a vector of all 1s: m[,5] <- 1 # use recycling

slide-36
SLIDE 36

What Does Rdsm Code Look Like?

Answer: Except for initialization, it looks just like—and IS—ordinary R code. For example, to replace the 5th column of a shared matrix m by a vector of all 1s: m[,5] <- 1 # use recycling This is ordinary, garden-variety R code.

slide-37
SLIDE 37

What Does Rdsm Code Look Like?

Answer: Except for initialization, it looks just like—and IS—ordinary R code. For example, to replace the 5th column of a shared matrix m by a vector of all 1s: m[,5] <- 1 # use recycling This is ordinary, garden-variety R code. And it IS shared: If process 3 executes the above and then process 8 does x <- m[2,5] then x will be 1 at process 8.

slide-38
SLIDE 38

What Does Rdsm Code Look Like? (cont’d.)

The only difference is in creating the variable:

slide-39
SLIDE 39

What Does Rdsm Code Look Like? (cont’d.)

The only difference is in creating the variable: # create shared 6x6 matrix newdsm("m","dsmm","double",size=c(6,6)) Note the special ”dsmm” class for shared matrices.

slide-40
SLIDE 40

What Does Rdsm Code Look Like? (cont’d.)

The only difference is in creating the variable: # create shared 6x6 matrix newdsm("m","dsmm","double",size=c(6,6)) Note the special ”dsmm” class for shared matrices. (Also have classes for shared vectors and lists.)

slide-41
SLIDE 41

What Does Rdsm Code Look Like? (cont’d.)

The only difference is in creating the variable: # create shared 6x6 matrix newdsm("m","dsmm","double",size=c(6,6)) Note the special ”dsmm” class for shared matrices. (Also have classes for shared vectors and lists.) Otherwise, it’s ordinary R syntax, with threads.

slide-42
SLIDE 42

Embarrassingly Parallel Example: Find Best k in k-NN Regression

Rdsm provides the familiar threads shared-memory environment. # have SHARED vars minmse , mink best found so f a r # each process executes the f o l l o w i n g rng <− f i n d r a n g e () # range

  • f k

f o r t h i s process f o r ( k in rng$mystart : rng$myend ) { mse <− crossvalmse ( x , y , k ) lock (” minlock ”) i f ( mse < minmse ) { minmse <− mse mink <− k } unlock (” minlock ”) }

slide-43
SLIDE 43

Parallel I/O Example: Web Speed Monitor

Goal: Continually measure Web speed while concurrently allowing stat analysis on the collected data.

slide-44
SLIDE 44

Parallel I/O Example: Web Speed Monitor

Goal: Continually measure Web speed while concurrently allowing stat analysis on the collected data. Rdsm solution:

slide-45
SLIDE 45

Web Speed Monitor (cont’d.)

What’s in the picture:

slide-46
SLIDE 46

Web Speed Monitor (cont’d.)

What’s in the picture: multiple Rdsm threads, 4 here

slide-47
SLIDE 47

Web Speed Monitor (cont’d.)

What’s in the picture: multiple Rdsm threads, 4 here 3 of the threads gather data, by continually probing the Web

slide-48
SLIDE 48

Web Speed Monitor (cont’d.)

What’s in the picture: multiple Rdsm threads, 4 here 3 of the threads gather data, by continually probing the Web those 3 threads write access times to the shared vector accesstimes

slide-49
SLIDE 49

Web Speed Monitor (cont’d.)

What’s in the picture: multiple Rdsm threads, 4 here 3 of the threads gather data, by continually probing the Web those 3 threads write access times to the shared vector accesstimes in 4th thread, human gives R commands, reading the shared vector accesstimes

slide-50
SLIDE 50

Web Speed Monitor (cont’d.)

What’s in the picture: multiple Rdsm threads, 4 here 3 of the threads gather data, by continually probing the Web those 3 threads write access times to the shared vector accesstimes in 4th thread, human gives R commands, reading the shared vector accesstimes the human applies R’s myriad statistical operations to the data at his/her whim—concurrently with the data collection

slide-51
SLIDE 51

Example of Collaborative Structures: Online Auction

slide-52
SLIDE 52

Example of Collaborative Structures: Online Auction

asynchronous—anyone can bid at any time, no turns

slide-53
SLIDE 53

Example of Collaborative Structures: Online Auction

asynchronous—anyone can bid at any time, no turns shared variables:

slide-54
SLIDE 54

Example of Collaborative Structures: Online Auction

asynchronous—anyone can bid at any time, no turns shared variables:

latestbid

slide-55
SLIDE 55

Example of Collaborative Structures: Online Auction

asynchronous—anyone can bid at any time, no turns shared variables:

latestbid nbidders, number who haven’t dropped out of the bidding yet

slide-56
SLIDE 56

Example of Collaborative Structures: Online Auction

asynchronous—anyone can bid at any time, no turns shared variables:

latestbid nbidders, number who haven’t dropped out of the bidding yet

if n participants, then 2n Rdsm threads

slide-57
SLIDE 57

Example of Collaborative Structures: Online Auction

asynchronous—anyone can bid at any time, no turns shared variables:

latestbid nbidders, number who haven’t dropped out of the bidding yet

if n participants, then 2n Rdsm threads for a participant, one thread watches latestbid, the other submits bids

slide-58
SLIDE 58

Auction (cont’d.)

slide-59
SLIDE 59

Auction (cont’d.)

Built-in Rdsm functions used:

slide-60
SLIDE 60

Auction (cont’d.)

Built-in Rdsm functions used: wait(), signal(): Watcher threads call wait(), bidder threads call signal().

slide-61
SLIDE 61

Auction (cont’d.)

Built-in Rdsm functions used: wait(), signal(): Watcher threads call wait(), bidder threads call signal(). lock(), unlock(): Usual need for lock, but with check for need to cancel bid.

slide-62
SLIDE 62

Auction (cont’d.)

Built-in Rdsm functions used: wait(), signal(): Watcher threads call wait(), bidder threads call signal(). lock(), unlock(): Usual need for lock, but with check for need to cancel bid. fa(): Fetch-and-add, to atomically decrement nbidders when someone drops out.

slide-63
SLIDE 63

R...As a GAME Platform????

slide-64
SLIDE 64

R...As a GAME Platform????

Well, just for fun...

slide-65
SLIDE 65

R...As a GAME Platform????

Well, just for fun... Project for my parallel programming students: Use Rdsm to implement the card game, Pit.

slide-66
SLIDE 66

R...As a GAME Platform????

Well, just for fun... Project for my parallel programming students: Use Rdsm to implement the card game, Pit. Asynchronous—no turns! Like Auction.R.

slide-67
SLIDE 67

R...As a GAME Platform????

Well, just for fun... Project for my parallel programming students: Use Rdsm to implement the card game, Pit. Asynchronous—no turns! Like Auction.R. Transaction coding tricky; when is a trade “official”?

slide-68
SLIDE 68

How Rdsm Works

slide-69
SLIDE 69

How Rdsm Works

Same scheme as in PerlDSM (Matloff, 2002):

slide-70
SLIDE 70

How Rdsm Works

Same scheme as in PerlDSM (Matloff, 2002): R processes run on clients.

slide-71
SLIDE 71

How Rdsm Works

Same scheme as in PerlDSM (Matloff, 2002): R processes run on clients. Physical storage of shared variables at server.

slide-72
SLIDE 72

How Rdsm Works

Same scheme as in PerlDSM (Matloff, 2002): R processes run on clients. Physical storage of shared variables at server. Rdsm shared-variable classes:

slide-73
SLIDE 73

How Rdsm Works

Same scheme as in PerlDSM (Matloff, 2002): R processes run on clients. Physical storage of shared variables at server. Rdsm shared-variable classes:

dsmv: shared vector dsmm: shared matrix dsml: shared list

slide-74
SLIDE 74

How Rdsm Works

Same scheme as in PerlDSM (Matloff, 2002): R processes run on clients. Physical storage of shared variables at server. Rdsm shared-variable classes:

dsmv: shared vector dsmm: shared matrix dsml: shared list

Redefine indexing functions, e.g. ”[.dsmv”, ”[<-.dsmv”.

slide-75
SLIDE 75

How Rdsm Works

Same scheme as in PerlDSM (Matloff, 2002): R processes run on clients. Physical storage of shared variables at server. Rdsm shared-variable classes:

dsmv: shared vector dsmm: shared matrix dsml: shared list

Redefine indexing functions, e.g. ”[.dsmv”, ”[<-.dsmv”. New indexing functions communicate with server.

slide-76
SLIDE 76

How Rdsm Works

Same scheme as in PerlDSM (Matloff, 2002): R processes run on clients. Physical storage of shared variables at server. Rdsm shared-variable classes:

dsmv: shared vector dsmm: shared matrix dsml: shared list

Redefine indexing functions, e.g. ”[.dsmv”, ”[<-.dsmv”. New indexing functions communicate with server. But all is transparent to programmer.

slide-77
SLIDE 77

Rdsm Internals, cont’d.

slide-78
SLIDE 78

Rdsm Internals, cont’d.

E.g. client 3 writes to m[2,12], then client 8 reads it:

slide-79
SLIDE 79

Rdsm Internals, cont’d.

E.g. client 3 writes to m[2,12], then client 8 reads it:

slide-80
SLIDE 80

Comparison to bigmemory

Rdsm has functions for threads infrastructure1 Rdsm is usable across fully independent machines2 bigmemory may be faster on embarrassingly parallel apps

1I’ve written an incomplete set for bigmemory. 2but could try bigmemory with NFS files