ocaml-multicore / domainslib

Parallel Programming over Domains
ISC License
172 stars 30 forks source link

Question About Inconsistent Behavior in Parallel BFS Implementation Using Domainslib Task Pool #122

Closed tjazerzen closed 10 months ago

tjazerzen commented 10 months ago

Description:

Context:

Code Overview:

module BfsAlgorithms : Bfs = struct
  (* ... other methods ... *)

  let parallel_map (f : 'a -> 'b) (task_pool : T.pool) (arr : 'a array) : 'b array =
    let len = Array.length arr in
    let res = Array.make len (f arr.(0)) in
    T.parallel_for task_pool ~start:0 ~finish:(len - 1) ~body:(fun i -> res.(i) <- f arr.(i));
    res

  let parallel (graph : UnweightedGraph.t) (start_node : Node.t) ~(task_pool: T.pool) : NodeSet.t list =
    (* implementation details *)
    (* uses parallel_map *)
end

(* ... other code ... *)

Issue: Inconsistent Execution Behavior

Expected Behavior:

Both scenarios should exhibit the same behavior, as the only difference is the direct invocation of BfsAlgorithms.parallel in Scenario 2.

I was wondering if there is any known issue or subtlety with how Domainslib handles task pools and closures that could explain this discrepancy?

I'm new to parallel OCaml, so this could be fault on my side.

If any more context is needed, the full implementation may be found at https://github.com/tjazerzen/parallelisation-of-graph-algorithms-in-functional-programming-languages/blob/master/playground/graph/bfs.ml.

Best, Tjaz

tjazerzen commented 10 months ago

realized my problem, which doesn't have to do anything with parallelism. Closing...