tebdol

Simulation of ultracold atoms in optical lattices
git clone https://miroslavurbanek.com/git/tebdol.git
Log | Files | Refs | README

mpi.lisp (772B)


      1 ;; pass ranks from one process to another and calculate their sum
      2 
      3 (load "conf.lisp")
      4 (require :tebdol)
      5 
      6 (use-package '(:sb-sys :mpi))
      7 
      8 (defun mpi-pass (out prev next)
      9   (without-gcing
     10     (let ((request (mpi-issend-object out next))
     11 	  (in (mpi-receive-object prev)))
     12       (mpi-wait request)
     13       in)))
     14 
     15 (mpi-init)
     16 
     17 (let* ((rank (mpi-comm-rank *mpi-comm-world*))
     18        (size (mpi-comm-size *mpi-comm-world*))
     19        (prev (mod (1- rank) size))
     20        (next (mod (1+ rank) size)))
     21   (if (zerop rank)
     22       (format t "There ~:[are ~a processes~;is ~a process~] running.~%" (eq size 1) size))
     23   (format t
     24 	  "Sum of ranks in process ~a is ~a.~%"
     25 	  rank
     26 	  (loop
     27 	     repeat size
     28 	     for value = rank then (mpi-pass value prev next)
     29 	     sum value)))
     30 
     31 (mpi-finalize)