1 2 3 Places Example (require racket/place - - PowerPoint PPT Presentation

1 2 3 places example
SMART_READER_LITE
LIVE PREVIEW

1 2 3 Places Example (require racket/place - - PowerPoint PPT Presentation

1 2 3 Places Example (require racket/place racket/place/distributed) (provide hello-world) (define (hello-world ch) (printf/f "hello-world received: a\n" (place-channel-get ch)) (place-channel-put ch "Hello World\n")


slide-1
SLIDE 1

1

slide-2
SLIDE 2

2

slide-3
SLIDE 3

3

slide-4
SLIDE 4

Places Example

(require racket/place racket/place/distributed) (provide hello-world) (define (hello-world ch) (printf/f "hello-world received: ∼a\n" (place-channel-get ch)) (place-channel-put ch "Hello World\n") (printf/f "hello-world sent: Hello World\n")) (module+ main (define p (dynamic-place (quote-module-path "..") ’hello-world)) (place-channel-put p "Hello") (printf/f "main received: ∼a\n" (place-channel-get p)) (place-wait p))

4

slide-5
SLIDE 5

Places Example

(require racket/place racket/place/distributed) (provide hello-world) (define (hello-world ch) (printf/f "hello-world received: ∼a\n" (place-channel-get ch)) (place-channel-put ch "Hello World\n") (printf/f "hello-world sent: Hello World\n")) (module+ main (define p (dynamic-place (quote-module-path "..") ’hello-world)) (place-channel-put p "Hello") (printf/f "main received: ∼a\n" (place-channel-get p)) (place-wait p))

5

slide-6
SLIDE 6

Places Example

(require racket/place racket/place/distributed) (provide hello-world) (define (hello-world ch) (printf/f "hello-world received: ∼a\n" (place-channel-get ch)) (place-channel-put ch "Hello World\n") (printf/f "hello-world sent: Hello World\n")) (module+ main (define p (dynamic-place (quote-module-path "..") ’hello-world)) (place-channel-put p "Hello") (printf/f "main received: ∼a\n" (place-channel-get p)) (place-wait p))

6

slide-7
SLIDE 7

Places Example

(require racket/place racket/place/distributed) (provide hello-world) (define (hello-world ch) (printf/f "hello-world received: ∼a\n" (place-channel-get ch)) (place-channel-put ch "Hello World\n") (printf/f "hello-world sent: Hello World\n")) (module+ main (define p (dynamic-place (quote-module-path "..") ’hello-world)) (place-channel-put p "Hello") (printf/f "main received: ∼a\n" (place-channel-get p)) (place-wait p))

7

slide-8
SLIDE 8

8

slide-9
SLIDE 9

9

slide-10
SLIDE 10

10

slide-11
SLIDE 11

11

slide-12
SLIDE 12

Pile of Functions FFI

12

slide-13
SLIDE 13

Pile of Functions FFI

13

slide-14
SLIDE 14

Pile of Functions FFI

14

slide-15
SLIDE 15

Pile of Functions FFI

15

slide-16
SLIDE 16

Distributed Places Example

Places

(require racket/place racket/place/distributed) (provide hello-world) (define (hello-world ch) (printf/f "hello-world received: ∼a\n" (place-channel-get ch)) (place-channel-put ch "Hello World\n") (printf/f "hello-world sent: Hello World\n")) (module+ main (define p (dynamic-place (quote-module-path "..") ’hello-world)) (place-channel-put p "Hello") (printf/f "main received: ∼a\n" (place-channel-get p)) (place-wait p))

Distributed Places

(require racket/place racket/place/distributed) (provide hello-world) (define (hello-world ch) (printf/f "hello-world received: ∼a\n" (place-channel-get ch)) (place-channel-put ch "Hello World\n") (printf/f "hello-world sent: Hello World\n")) (module+ main (define n (create-place-node "host2" #:listen-port 6344)) (define p (dynamic-place #:at n (quote-module-path "..") ’hello-world)) (place-channel-put p "Hello") (printf/f "main received: ∼a\n" (place-channel-get p)) (place-wait p))

16

slide-17
SLIDE 17

Distributed Places API

17

slide-18
SLIDE 18

create-place-node

(create-place-node hostname [#:listen-port port #:racket-path racket-path #:ssh-bin-path ssh-path #:distributed-launch-path launcher-path #:use-current-ports use-current-ports]) → (is-a?/c remote-node%) hostname : string? port : port-no? = DEFAULT-ROUTER-PORT racket-path : string-path? = (racket-path) ssh-path : string-path? = (ssh-bin-path) launcher-path : string-path? = (path->string distributed-launch-path) use-current-ports : boolean? = #t

18

slide-19
SLIDE 19

dynamic-place

(dynamic-place module-path start-name [#:at node #:named named]) → place? module-path : (or/c module-path? path?) start-name : symbol? node : (or/c #f remote-node%) = #f named : (or/c #f string?) = #f

19

slide-20
SLIDE 20

Implementing Distributed Places

20

slide-21
SLIDE 21

Implementing Distributed Places

Spawn Remote Processes

21

slide-22
SLIDE 22

Implementing Distributed Places

Spawn Remote Processes Send Place Messages Across TCP Sockets

22

slide-23
SLIDE 23

Implementing Distributed Places

Spawn Remote Processes Send Place Messages Across TCP Sockets Integrate with Racket Concurrency Primitives

(sync place-channel-1 socket place-descriptor)

23

slide-24
SLIDE 24

Higher-level Distributed Frameworks

24

slide-25
SLIDE 25

RPC Server

Definition - tuple.rkt

(require racket/match racket/place/define-remote-server) (define-named-remote-server tuple-server (define-state h (make-hash)) (define-rpc (set k v) (hash-set! h k v) v) (define-rpc (get k) (hash-ref h k #f)) (define-cast (hello) (printf "Hello from define-cast\n") (flush-output)))

Use

(require racket/place/distributed racket/place "tuple.rkt") (module+ main (define c (connect-to-named-place remote-node 'tuple-server)) (tuple-server-hello c) (displayln (tuple-server-set c "user0" 100)) (displayln (tuple-server-get c "user0") (tuple-server-hello)))

25

slide-26
SLIDE 26

MPI

(require racket/place/distributed racket/place/distributed/rmpi) (provide prod-id-place) (define (prod-id-place ch) (define-values (comm args tc) (rmpi-init ch)) (define sum (rmpi-allreduce comm * (+ 1 (rmpi-id comm)))) (printf/f "~a - ~a\n" (rmpi-id comm) sum) (sleep 3) (rmpi-finish comm tc)) (module+ main (define args null) (time (rmpi-launch (rmpi-build-default-config #:mpi-module (quote-module-path "..") #:mpi-func 'prod-id-place #:mpi-args args) (list (list "localhost" 6341 'kmeans0 0) (list "localhost" 6342 'kmeans1 1) (list "localhost" 6343 'kmeans2 2) (list "localhost" 6344 'kmeans3 3) (list "localhost" 6345 'kmeans4 4) (list "localhost" 6346 'kmeans5 5) (list "localhost" 6347 'kmeans6 6) (list "localhost" 6348 'kmeans7 7)))))

26

slide-27
SLIDE 27

Map Reduce

(define/provide (mapper kvs) (for/first ([kv kvs]) (match kv [(cons k v) (with-input-from-file v (lambda () (let loop ([result null]) (define l (read-line)) (if (eof-object? l) result (loop (cons (cons l 1) result))))))]))) (define/provide (reducer kvs) (for/list ([kv kvs]) (match kv [(cons k v) (cons k (list (for/fold ([sum 0]) ([x v]) (+ sum x))))]))) (define/provide (outputer kvs) (displayln (for/fold ([sum 0]) ([kv kvs]) (printf "∼a - ∼a\n" (car kv) (cadr kv)) (+ sum (cadr kv))))) (define config (list (list "host2" 6430) (list "host3" 6430))) (define tasks (list (list (cons 0 "/tmp/w0")) (list (cons 1 "/tmp/w1")) ...)) (define workers (make-map-reduce-workers config)) (map-reduce workers config tasks (list (quote-module-path "..") 'mapper) (list (quote-module-path "..") 'reducer) #:outputer (list (quote-module-path "..") 'outputer))

27

slide-28
SLIDE 28
  • Language extension enables concise

implementation and use

  • Reuses dynamic-place syntax and place channels
  • Foundation for building higher-level parallel and

distributed frameworks

  • Roadmap for dynamic language implementers to

follow

28