Make the parallel operations more continuous
Instead of batching the list items, change the batch size to a parallelism limit and run up to that many fibers. When the processing of one list item finishes, another will then start immediately after, rather than when the whole batch is finished. These changes also make the fibers-map and fibers-for-each operations work with vectors as well as lists.
This commit is contained in:
parent
2f39c58d6c
commit
dc2fe732ea
2 changed files with 107 additions and 55 deletions
|
@ -3,6 +3,7 @@
|
|||
(unit-test)
|
||||
(knots parallelism))
|
||||
|
||||
;; Test fibers-map
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(assert-equal
|
||||
|
@ -12,4 +13,34 @@
|
|||
(* 2 i))
|
||||
(iota 34))))))
|
||||
|
||||
;; Test fibers-batch-map with a large batch size
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(assert-equal
|
||||
1122
|
||||
(apply + (fibers-batch-map
|
||||
(lambda (i)
|
||||
(* 2 i))
|
||||
100
|
||||
(iota 34))))))
|
||||
|
||||
;; Test fibers-map with vectors
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(assert-equal
|
||||
1122
|
||||
(apply + (vector->list
|
||||
(fibers-map
|
||||
(lambda (i)
|
||||
(* 2 i))
|
||||
(list->vector (iota 34))))))))
|
||||
|
||||
;; Test fibers-for-each
|
||||
(run-fibers-for-tests
|
||||
(lambda ()
|
||||
(fibers-for-each
|
||||
(lambda (i)
|
||||
(* 2 i))
|
||||
(iota 34))))
|
||||
|
||||
(display "parallelism test finished successfully\n")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue