concurrency.combinators: adding parallel-product-map, docs for stack effects.
parent
278d210064
commit
eb801f1072
|
@ -7,7 +7,7 @@ HELP: parallel-map
|
||||||
{ $errors "Throws an error if one of the iterations throws an error." } ;
|
{ $errors "Throws an error if one of the iterations throws an error." } ;
|
||||||
|
|
||||||
HELP: 2parallel-map
|
HELP: 2parallel-map
|
||||||
{ $values { "seq1" sequence } { "seq2" sequence } { "quot" { $quotation "( elt -- newelt )" } } { "newseq" sequence } }
|
{ $values { "seq1" sequence } { "seq2" sequence } { "quot" { $quotation "( elt1 elt2 -- newelt )" } } { "newseq" sequence } }
|
||||||
{ $description "Spawns a new thread for applying " { $snippet "quot" } " to pairwise elements of " { $snippet "seq1" } " and " { $snippet "seq2" } ", collecting the results at the end." }
|
{ $description "Spawns a new thread for applying " { $snippet "quot" } " to pairwise elements of " { $snippet "seq1" } " and " { $snippet "seq2" } ", collecting the results at the end." }
|
||||||
{ $errors "Throws an error if one of the iterations throws an error." } ;
|
{ $errors "Throws an error if one of the iterations throws an error." } ;
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ HELP: parallel-each
|
||||||
{ $errors "Throws an error if one of the iterations throws an error." } ;
|
{ $errors "Throws an error if one of the iterations throws an error." } ;
|
||||||
|
|
||||||
HELP: 2parallel-each
|
HELP: 2parallel-each
|
||||||
{ $values { "seq1" sequence } { "seq2" sequence } { "quot" { $quotation "( elt -- )" } } }
|
{ $values { "seq1" sequence } { "seq2" sequence } { "quot" { $quotation "( elt1 elt2 -- )" } } }
|
||||||
{ $description "Spawns a new thread for applying " { $snippet "quot" } " to pairwise elements of " { $snippet "seq1" } " and " { $snippet "seq2" } ", blocking until all quotations complete." }
|
{ $description "Spawns a new thread for applying " { $snippet "quot" } " to pairwise elements of " { $snippet "seq1" } " and " { $snippet "seq2" } ", blocking until all quotations complete." }
|
||||||
{ $errors "Throws an error if one of the iterations throws an error." } ;
|
{ $errors "Throws an error if one of the iterations throws an error." } ;
|
||||||
|
|
||||||
|
@ -34,6 +34,7 @@ $nl
|
||||||
parallel-each
|
parallel-each
|
||||||
2parallel-each
|
2parallel-each
|
||||||
parallel-map
|
parallel-map
|
||||||
|
parallel-product-map
|
||||||
2parallel-map
|
2parallel-map
|
||||||
parallel-filter
|
parallel-filter
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2008 Slava Pestov.
|
! Copyright (C) 2008 Slava Pestov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: concurrency.futures concurrency.count-downs sequences
|
USING: combinators concurrency.count-downs concurrency.futures
|
||||||
kernel macros fry combinators generalizations ;
|
fry generalizations kernel macros sequences sequences.product ;
|
||||||
IN: concurrency.combinators
|
IN: concurrency.combinators
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
@ -11,17 +11,17 @@ IN: concurrency.combinators
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: parallel-each ( seq quot -- )
|
: parallel-each ( seq quot: ( elt -- ) -- )
|
||||||
over length [
|
over length [
|
||||||
'[ _ curry _ spawn-stage ] each
|
'[ _ curry _ spawn-stage ] each
|
||||||
] (parallel-each) ; inline
|
] (parallel-each) ; inline
|
||||||
|
|
||||||
: 2parallel-each ( seq1 seq2 quot -- )
|
: 2parallel-each ( seq1 seq2 quot: ( elt1 elt2 -- ) -- )
|
||||||
2over min-length [
|
2over min-length [
|
||||||
'[ _ 2curry _ spawn-stage ] 2each
|
'[ _ 2curry _ spawn-stage ] 2each
|
||||||
] (parallel-each) ; inline
|
] (parallel-each) ; inline
|
||||||
|
|
||||||
: parallel-filter ( seq quot -- newseq )
|
: parallel-filter ( seq quot: ( elt -- ? ) -- newseq )
|
||||||
over [ selector [ parallel-each ] dip ] dip like ; inline
|
over [ selector [ parallel-each ] dip ] dip like ; inline
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
@ -33,10 +33,13 @@ PRIVATE>
|
||||||
|
|
||||||
PRIVATE>
|
PRIVATE>
|
||||||
|
|
||||||
: parallel-map ( seq quot -- newseq )
|
: parallel-map ( seq quot: ( elt -- newelt ) -- newseq )
|
||||||
[future] map future-values ; inline
|
[future] map future-values ; inline
|
||||||
|
|
||||||
: 2parallel-map ( seq1 seq2 quot -- newseq )
|
: parallel-product-map ( seq quot: ( elt -- newelt ) -- newseq )
|
||||||
|
[ <product-sequence> ] dip parallel-map ;
|
||||||
|
|
||||||
|
: 2parallel-map ( seq1 seq2 quot: ( elt1 elt2 -- newelt ) -- newseq )
|
||||||
'[ _ 2curry future ] 2map future-values ;
|
'[ _ 2curry future ] 2map future-values ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
Loading…
Reference in New Issue