mirror of
https://github.com/c-cube/moonpool.git
synced 2025-12-09 04:35:33 -05:00
remove Fork_join.map_reduce_commutative
A bit too specialized, and not hard to do with `for_`. Let's see if it shows to be really useful.
This commit is contained in:
parent
9ce94fd242
commit
d995992917
2 changed files with 0 additions and 51 deletions
|
|
@ -207,24 +207,4 @@ let map_list ?chunk_size f (l : _ list) : _ list =
|
||||||
| None -> assert false
|
| None -> assert false
|
||||||
| Some x -> x)
|
| Some x -> x)
|
||||||
|
|
||||||
type 'a commutative_monoid = {
|
|
||||||
neutral: unit -> 'a; (** Neutral element *)
|
|
||||||
combine: 'a -> 'a -> 'a; (** Combine two items. *)
|
|
||||||
}
|
|
||||||
|
|
||||||
let map_reduce_commutative ?chunk_size ~gen ~map
|
|
||||||
~(reduce : 'b commutative_monoid) n : 'b =
|
|
||||||
let res = Lock.create (reduce.neutral ()) in
|
|
||||||
|
|
||||||
for_ ?chunk_size n (fun low high ->
|
|
||||||
let local_acc = ref (reduce.neutral ()) in
|
|
||||||
for i = low to high do
|
|
||||||
let x = gen i in
|
|
||||||
let y = map x in
|
|
||||||
local_acc := reduce.combine !local_acc y
|
|
||||||
done;
|
|
||||||
|
|
||||||
Lock.update res (fun res -> reduce.combine res !local_acc));
|
|
||||||
Lock.get res
|
|
||||||
|
|
||||||
[@@@endif]
|
[@@@endif]
|
||||||
|
|
|
||||||
|
|
@ -106,35 +106,4 @@ val map_list : ?chunk_size:int -> ('a -> 'b) -> 'a list -> 'b list
|
||||||
@since NEXT_RELEASE
|
@since NEXT_RELEASE
|
||||||
{b NOTE} this is only available on OCaml 5. *)
|
{b NOTE} this is only available on OCaml 5. *)
|
||||||
|
|
||||||
type 'a commutative_monoid = {
|
|
||||||
neutral: unit -> 'a; (** Neutral element *)
|
|
||||||
combine: 'a -> 'a -> 'a; (** Combine two items. *)
|
|
||||||
}
|
|
||||||
(** A commutative monoid: order of operations does not matter.
|
|
||||||
@since NEXT_RELEASE *)
|
|
||||||
|
|
||||||
val map_reduce_commutative :
|
|
||||||
?chunk_size:int ->
|
|
||||||
gen:(int -> 'a) ->
|
|
||||||
map:('a -> 'b) ->
|
|
||||||
reduce:'b commutative_monoid ->
|
|
||||||
int ->
|
|
||||||
'b
|
|
||||||
(** [map_reduce_commutative ~gen ~map ~reduce n] produces items of type ['a]
|
|
||||||
using [gen 0], [gen 1], …, [gen (n-1)]. Items are then mapped using [map]
|
|
||||||
in background tasks (each task processes up to [chunk_size] items at a time).
|
|
||||||
|
|
||||||
Then, items of type ['b] obtained by mapping are reduced together using the
|
|
||||||
definition of the commutative monoid [reduce]. The order in which they
|
|
||||||
are reduced is not specified.
|
|
||||||
|
|
||||||
@param chunk_size controls granularity of the mapping process
|
|
||||||
@param gen generates items to process based on an index
|
|
||||||
@param map takes an item and processes it, independently of other items
|
|
||||||
@param reduce is used to aggregate results of mapping.
|
|
||||||
|
|
||||||
@since NEXT_RELEASE
|
|
||||||
{b NOTE} this is only available on OCaml 5.
|
|
||||||
*)
|
|
||||||
|
|
||||||
[@@@endif]
|
[@@@endif]
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue