anchor.diff:  
   
   ;;;
  -;;; Performance measurement functions
  +;;; Performance displayment functions
   ;;;
   
   (defvar *flops-per-interaction* 20)
   
  -(defun compute-perf-stats (num-bodies elapsed-time fps-count iterations)
  -  (let ((milliseconds (/ elapsed-time fps-count)))
  -    (let* ((ifps (/ 1.0 (/ milliseconds 1000.0)))
  -           (interactions-per-second (/ (* num-bodies num-bodies iterations)
  -                                       (/ milliseconds 1000)
  -                                       1.0e9))
  -           (gflops (* interactions-per-second *flops-per-interaction*)))
  -      (values ifps interactions-per-second gflops))))
  +(defun compute-perf-stats (num-bodies fps iterations)
  +  (let* ((interactions-per-second (/ (* num-bodies num-bodies iterations)
  +                                     (/ 1.0 fps)
  +                                     1.0e9))
  +         (gflops                  (* interactions-per-second *flops-per-interaction*)))
  +    (values interactions-per-second gflops)))
   
   (let ((fps-count 0)
         (fps-limit 5)
         (template "CUDA N-Body (~A bodies): ~,1F fps | ~,1F BIPS | ~,1F GFLOP/s | single precision~%"))
  -  (defun display-frame-rate (num-bodies)
  +  (defun display-frame-rate (num-bodies fps)
       (incf fps-count)
       (when (>= fps-count fps-limit)
  -      (multiple-value-bind (ifps interactions-per-second gflops)
  -          (compute-perf-stats num-bodies (get-elapsed-time) fps-count 1)
  -        (glut:set-window-title
  -          (format nil template num-bodies ifps interactions-per-second gflops))
  -        (setf fps-count 0)
  -        (setf fps-limit (max ifps 1.0))))))
  -
  -
  -;;;
  -;;; Timing functions
  +      (multiple-value-bind (interactions-per-second gflops)
  +          (compute-perf-stats num-bodies fps 1)
  +        (format t template num-bodies fps interactions-per-second gflops)
  +        (glut:set-window-title (format nil template num-bodies fps interactions-per-second gflops)))
  +      (setf fps-count 0
  +            fps-limit (max fps 1.0)))))
  +
  +
  +;;;
  +;;; Frame rate counter
  +;;;
  +
  +(let ((fps-count 0)
  +      (fps-limit 5)
  +      (fps       0))
  +  
  +  (defun frame-rate-counter-init ()
  +    (create-timer-events)
  +    (start-timer))
  +  
  +  (defun frame-rate-counter-release ()
  +    (destroy-timer-events))
  +  
  +  (defun frame-rate-counter-get-frame-rate ()
  +    fps)
  +  
  +  (defun frame-rate-counter-measure ()
  +    (incf fps-count)
  +    (when (>= fps-count fps-limit)
  +      (let ((milliseconds (/ (get-elapsed-time) fps-count)))
  +        (setf fps       (/ 1.0 (/ milliseconds 1000.0))
  +              fps-count 0
  +              fps-limit (max fps 1.0))))))
  +
  +
  +;;;
  +;;; Timer functions
   ;;;
   
   (let ((start-event (cffi:null-pointer))
  
positive.code: 
    (defun get-elapsed-time ()
      (let (milliseconds)
        (cffi:with-foreign-object (pmilliseconds :float)
          (stop-and-synchronize-timer)
          (cu-event-elapsed-time pmilliseconds
                                 (cffi:mem-ref start-event 'cu-event)
                                 (cffi:mem-ref stop-event 'cu-event))
          (start-timer)
          (setf milliseconds (cffi:mem-ref pmilliseconds :float)))
        milliseconds)))
  
  (defmacro with-cuda-timer (&body body)
  
negative.code:     (gl:tex-image-2d :texture-2d 0 :rgba8 resolution resolution 0
                       :rgba :unsigned-byte m-texture-data))
    
    (defun init-memory-blocks ()
      (setf m-new-pos (cl-cuda::alloc-memory-block 'float4 m-num-bodies)
            m-old-pos (cl-cuda::alloc-memory-block 'float4 m-num-bodies)
            m-vel     (cl-cuda::alloc-memory-block 'float4 m-num-bodies)))
    
    (defun nbody-release ()
      (frame-rate-counter-release)
      (release-memory-blocks)
      (release-cuda-context)
      (destroy-texture)
      (release-shaders))
    
    (defun release-shaders ()
      (values))
    
    (defun destroy-texture ()
      (cffi:foreign-free m-texture-data))
    
    (defun release-memory-blocks ()
      (cl-cuda::free-memory-block m-vel)
      (cl-cuda::free-memory-block m-old-pos)
      (cl-cuda::free-memory-block m-new-pos))
    
    (defun nbody-reset ()
      (randomize-bodies m-old-pos m-vel
                        m-cluster-scale m-velocity-scale m-num-bodies))
    
    (defun nbody-update-simulation ()
      (integrate-nbody-system m-new-pos m-old-pos m-vel
                              m-delta-time m-damping m-num-bodies m-p)
      (rotatef m-new-pos m-old-pos))
    
    (defun nbody-display (mode)
      (memcpy-device-to-host m-new-pos)
      (ecase mode
        (:particle-points
          (gl:color 1.0 1.0 1.0)
          (gl:point-size m-point-size)
          (draw-points))
        (:particle-sprites
          ;; enable features
          (gl:enable :point-sprite)
          (gl:tex-env :point-sprite :coord-replace :true)
          (gl:enable :vertex-program-point-size-nv)
          (gl:point-size m-sprite-size)
          (gl:blend-func :src-alpha :one)
          (gl:enable :blend)
          (gl:depth-mask :false)
          ;; use shader program
          (gl:use-program m-program)
          (gl:uniformi (gl:get-uniform-location m-program "splatTexture") 0)
          ;; bind texture
          (gl:active-texture :texture0-arb)
          (gl:bind-texture :texture-2d m-texture)
          ;; set color
          (gl:color 1.0 1.0 1.0)
          (gl:secondary-color (aref m-base-color 0) (aref m-base-color 1) (aref m-base-color 2))
          ;; draw points
          (draw-points)
          ;; dont use shader program
          (gl:use-program 0)
          ;; disable features
          (gl:disable :point-sprite-arb)
          (gl:disable :blend)
          (gl:depth-mask :true)))
      (frame-rate-counter-measure))
    
    (defun draw-points ()
      (gl:begin :points)
      (dotimes (i m-num-bodies)
        (let ((p (mem-aref m-new-pos i)))
          (gl:vertex (float4-x p) (float4-y p) (float4-z p))))
      (gl:end)))
  
  
  ;;;
  ;;; Functions for texture creation
  ;;;
  
  (defun eval-hermite (pa pb va vb u)
    (let ((u2 (* u u))
          (u3 (* u u u)))
      (let ((b0 (+ (- (* 2 u3) (* 3 u2)) 1))
            (b1 (+ (* -2 u3) (* 3 u2)))
            (b2 (+ (- u3 (* 2 u2)) u))
            (b3 (- u3 u)))
        (+ (* b0 pa) (* b1 pb) (* b2 va) (* b3 vb)))))
  
  (defun create-gaussian-map (b n)
    (let ((incr (/ 2.0 n))
          (j 0))
      (do ((y 0 (1+ y))
           (yy -1.0 (+ yy incr)))
          ((= y n))
        (do ((x 0 (1+ x))
             (xx -1.0 (+ xx incr)))
            ((= x n))
          (let* ((dist (min (sqrt (+ (* xx xx) (* yy yy))) 1.0))
                 (hermite (eval-hermite 1.0 0 0 0 dist))
                 (value (truncate (* hermite 255))))
            (setf (cffi:mem-aref b :unsigned-char j)       value
                  (cffi:mem-aref b :unsigned-char (+ j 1)) value
                  (cffi:mem-aref b :unsigned-char (+ j 2)) value
                  (cffi:mem-aref b :unsigned-char (+ j 3)) value)
            (incf j 4))))))
  
  
  ;;;
  ;;; Functions for initialize body position
  ;;;
  
  (defun divided-point (inner outer k)
  