walk   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/examples/contrib/mpi/random-walk.xtm

Implementation

(bind-func walk
  (lambda (walker:Walker* region:DomainRegion* domain_size outgoing_walkers)
    (let ((location (tref walker 0))
          (steps_remaining (tref walker 1))
          (region_start (tref region 0))
          (region_size (tref region 1)))
      (if (< (+ location steps_remaining)
             (+ region_start region_size))
          ;; walk ends in this domain
          (begin (tfill! walker (+ location steps_remaining) 0) void)
          (begin
            (tfill! walker
                    (if (> (+ location steps_remaining) domain_size)
                        0 ;; off the end of the world! need to wrap
                        (+ region_start region_size)) ;; beginning of next region
                    (% (+ location steps_remaining) region_size))
            (add_walker outgoing_walkers walker))))))


Back to Index

Similar Entries