From d995992917b8275023b002622d5b39c79b2dd057 Mon Sep 17 00:00:00 2001 From: Simon Cruanes Date: Mon, 10 Jul 2023 23:19:02 -0400 Subject: [PATCH] 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. --- src/fork_join.ml | 20 -------------------- src/fork_join.mli | 31 ------------------------------- 2 files changed, 51 deletions(-) diff --git a/src/fork_join.ml b/src/fork_join.ml index a01036ed..ccf9a753 100644 --- a/src/fork_join.ml +++ b/src/fork_join.ml @@ -207,24 +207,4 @@ let map_list ?chunk_size f (l : _ list) : _ list = | None -> assert false | 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] diff --git a/src/fork_join.mli b/src/fork_join.mli index fd164902..a1adb83a 100644 --- a/src/fork_join.mli +++ b/src/fork_join.mli @@ -106,35 +106,4 @@ val map_list : ?chunk_size:int -> ('a -> 'b) -> 'a list -> 'b list @since NEXT_RELEASE {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]