Skip to content

Commit

Permalink
xecto-impl: initialize in parallel context
Browse files Browse the repository at this point in the history
  • Loading branch information
pkhuong committed Dec 18, 2011
1 parent 24821cb commit 966198b
Showing 1 changed file with 56 additions and 10 deletions.
66 changes: 56 additions & 10 deletions xecto-impl.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,15 @@
(defun make-xecto (dimensions &key initial-element)
(multiple-value-bind (size shape)
(size-and-shape dimensions)
(let ((xecto (%make-xecto shape (vector-future:make size '() #()))))
(let ((xecto (%make-xecto shape
(vector-future:make size
'()
(if initial-element
(vector (lambda (data)
(fill (vector-future:data data)
(float initial-element 1d0))))
#())))))
(set-finalizer xecto)
(when initial-element
(future:wait (xecto-data xecto) :done)
(fill (vector-future:data (xecto-data xecto)) (float initial-element 1d0)))
xecto)))

(defun wait (xecto &rest condition)
Expand All @@ -104,11 +108,53 @@
(set-finalizer new)))

#||
(defparameter *x* (make-xecto '(2048 2048) :initial-element 1))
(defparameter *y* (transpose (make-xecto '(2048 2048) :initial-element 1) 0 1))
(gc :full t)
(time (let ((x (map-xecto #'+ *x* *y*))
(y (scan-xecto #'+ *y*)))
(wait (reduce-xecto #'+ (map-xecto #'+ x y)) :done)))
(setf *print-circle* t *print-length* 20)
(defvar xx)
(defvar yy)
(sb-thread:join-thread
(sb-thread:make-thread
(lambda ()
(parallel-future:with-context (11)
(let ()
#+nil ((xx (make-xecto '(16384 16384) :initial-element 1))
(yy (transpose (make-xecto '(16384 16384) :initial-element 5) 0 1)))
(setf xx (make-xecto '(16384 16384) :initial-element 1)
yy (transpose (make-xecto '(16384 16384) :initial-element 5) 0 1))
(time (let ((x (map-xecto #'+ xx yy))
(y (scan-xecto #'+ xx)))
(wait (reduce-xecto #'+ (reduce-xecto #'+ (map-xecto #'+ x y)))
:done)))
(setf *print-length* 20 xx nil yy nil))
parallel-future:*context*))))
Evaluation took:
104.652 seconds of real time
104.462529 seconds of total run time (101.230327 user, 3.232202 system)
[ Run times consist of 0.248 seconds GC time, and 104.215 seconds non-GC time. ]
99.82% CPU
Evaluation took:
49.085 seconds of real time
97.618102 seconds of total run time (94.157885 user, 3.460217 system)
[ Run times consist of 0.256 seconds GC time, and 97.363 seconds non-GC time. ]
198.88% CPU
Evaluation took:
26.356 seconds of real time
103.402463 seconds of total run time (100.010251 user, 3.392212 system)
[ Run times consist of 0.404 seconds GC time, and 102.999 seconds non-GC time. ]
392.33% CPU
Evaluation took:
14.404 seconds of real time
108.718794 seconds of total run time (105.314582 user, 3.404212 system)
[ Run times consist of 0.612 seconds GC time, and 108.107 seconds non-GC time. ]
754.78% CPU
Evaluation took:
11.439 seconds of real time
110.318895 seconds of total run time (106.422651 user, 3.896244 system)
[ Run times consist of 0.896 seconds GC time, and 109.423 seconds non-GC time. ]
964.41% CPU
||#

0 comments on commit 966198b

Please sign in to comment.