Performance issues for parallel execution
See granularity for an important construct that limits the spawning of parallel computations, which can be important when a computation is too short-lived to warrant a separate thread.
There are times in which parallelism provides no speedup because of garbage collection in the underlying Lisp implementation. The following example illustrates this phenomenon. If you change the granularity declaration so that the depth bound is 3, 4, or larger instead of 2, you may still find no speedup. In all cases you may find that parallelism results in a significantly greater time spent in garbage collection.
(include-book "finite-set-theory/osets/sets" :dir :system) (defun set::pmergesort-exec (x depth) (declare (xargs :mode :program)) (cond ((endp x) nil) ((endp (cdr x)) (set::insert (car x) nil)) (t (mv-let (part1 part2) (set::split-list x nil nil) (pargs (declare (granularity (< depth 2))) (set::union (set::pmergesort-exec part1 (1+ depth)) (set::pmergesort-exec part2 (1+ depth)))))))) (defconst *x* (reverse (fromto 1 400000))) (time$ (length (set::pmergesort-exec *x* 0))) (set-parallel-execution nil) (time$ (length (set::pmergesort-exec *x* 0)))