make make stop start -j1 sleep make test make test make stop make Ente

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
;; % make
;; make stop start -j1 ; sleep 1; make test; make test; make stop
;; make[1]: Entering directory `/home/worklez/tmp/term_5/lisp/14'
;; pkill -9 lisp.run; :
;; sh -c 'for port in {5..7} ; do clisp parallel.cl -server 4444$port & done'
;; make[1]: Leaving directory `/home/worklez/tmp/term_5/lisp/14'
;; make[1]: Entering directory `/home/worklez/tmp/term_5/lisp/14'
;; clisp parallel.cl -client
;; Real time: 6.023586 sec.
;; Run time: 0.0 sec.
;; Space: 19560 Bytes
;; Real time: 15.004132 sec.
;; Run time: 0.0 sec.
;; Space: 0 Bytes
;; ((PARALLEL . 6) (SEQUENCE . 6))
;; make[1]: Leaving directory `/home/worklez/tmp/term_5/lisp/14'
;; make[1]: Entering directory `/home/worklez/tmp/term_5/lisp/14'
;; clisp parallel.cl -client
;; Real time: 6.023839 sec.
;; Run time: 0.0 sec.
;; Space: 19560 Bytes
;; Real time: 15.004166 sec.
;; Run time: 0.0 sec.
;; Space: 0 Bytes
;; ((PARALLEL . 6) (SEQUENCE . 6))
;; make[1]: Leaving directory `/home/worklez/tmp/term_5/lisp/14'
;; make[1]: Entering directory `/home/worklez/tmp/term_5/lisp/14'
;; pkill -9 lisp.run; :
;; make[1]: Leaving directory `/home/worklez/tmp/term_5/lisp/14'
(defun slow (x) (sleep 5) x)
(defun parallel (servers expr)
(let
( (sockets (mapcar #'(lambda (server) (socket-connect (cadr server) (car server))) servers))
(args-number (length (cdr expr))) )
(defun distribute (exprs socks arg)
(cond
( (null exprs) nil )
( (null socks) (distribute exprs sockets arg) )
( T (princ (cons arg (car exprs)) (car socks)) (distribute (cdr exprs) (cdr socks) (+ 1 arg)) )))
(defun collect-results (socks results result-count)
(cond
( (eq args-number result-count) (mapcar #'cdr results) )
( (null socks) (sleep 1) (collect-results sockets results result-count) )
( (eq :input (socket-status (cons (car socks) :input) 0))
(collect-results
(cdr sockets)
(merge 'list (list (read (car socks))) results #'(lambda (a b) (< (car a) (car b))))
(+ 1 result-count)) )
( T (collect-results (cdr socks) results result-count) )))
(distribute (cdr expr) sockets 0)
(eval (cons (car expr) (collect-results sockets nil 0)))))
;; (defun run-server (port)
;; (let ( (serv (socket-server port)) )
;; (let ( (f (socket-accept serv)))
;; (let ( (in (read f)) )
;; ;; (princ (car in))
;; (princ (cons (car in) (eval (cdr in))) f)))))
(defun run-server (port)
(let ( (bound (socket-server port)) )
(loop
(let ( (client (socket-accept bound)) )
(defun serve (exprs)
;; (princ (list port ":" exprs))
(cond
( (eq :input (socket-status (cons client :input) 0))
(serve (cons (read client) exprs)) )
( (eq :eof (socket-status (cons client :input) 0)) nil )
( (null exprs) (sleep 1) (serve exprs) )
( T (princ (cons (caar exprs) (eval (cdar exprs))) client)
(serve (cdr exprs)) )))
(serve nil)))))
(setq server-list '(
("127.0.0.1" 44445)
("127.0.0.1" 44446)
("127.0.0.1" 44447)))
(let
( (whoami (car ext:*args*)) )
(cond
( (equal "-client" whoami)
(princ (list
(cons 'parallel (time (parallel server-list '(+ (slow 1) (slow 2) (slow 3)))))
(cons 'sequence (time (+ (slow 1) (slow 2) (slow 3))))
))
)
( (equal "-server" whoami) (run-server (parse-integer (cadr ext:*args*))))
( T (princ "Usage: -client | -server port"))))