diff --git a/Parallel/Parallel.ml b/Parallel/Parallel.ml index f27b66d..d6db9e6 100644 --- a/Parallel/Parallel.ml +++ b/Parallel/Parallel.ml @@ -15,12 +15,41 @@ let rank = assert (result >= 0); result + let master = rank = 0 + let barrier () = Mpi.barrier Mpi.comm_world +let broadcast x = + Mpi.broadcast x 0 Mpi.comm_world + + +let broadcast_int x = + Mpi.broadcast_int x 0 Mpi.comm_world + + +let broadcast_int_array x = + Mpi.broadcast_int_array x 0 Mpi.comm_world + + +let broadcast_float x = + Mpi.broadcast_float x 0 Mpi.comm_world + + +let broadcast_float_array x = + Mpi.broadcast_float_array x 0 Mpi.comm_world + + +let broadcast_vec x = + let a = Lacaml.D.Vec.to_array x in + let a = broadcast_float_array a in + Lacaml.D.Vec.of_array a + + + module Vec = struct type t = diff --git a/Parallel/Parallel.mli b/Parallel/Parallel.mli index a535afa..1e48db2 100644 --- a/Parallel/Parallel.mli +++ b/Parallel/Parallel.mli @@ -12,6 +12,25 @@ val master : bool val barrier : unit -> unit (** Wait for all processes to reach this point. *) +val broadcast : 'a -> 'a +(** Broadcasts data to all processes. *) + +val broadcast_int : int -> int +(** Broadcasts an [int] to all processes. *) + +val broadcast_float : float -> float +(** Broadcasts a [float] to all processes. *) + +val broadcast_int_array : int array -> int array +(** Broadcasts an [int array] to all processes. *) + +val broadcast_float_array : float array -> float array +(** Broadcasts a [float array] to all processes. *) + +val broadcast_vec : Lacaml.D.vec -> Lacaml.D.vec +(** Broadcasts a Lacaml vector to all processes. *) + + (** {5 Vector operations} *) module Vec : sig diff --git a/run_parallel.ml b/run_parallel.ml index fbe904f..afb24cc 100644 --- a/run_parallel.ml +++ b/run_parallel.ml @@ -9,7 +9,7 @@ let v = Parallel.Vec.init 47 (fun i -> float_of_int i) in let b = Array.init 41 (fun i -> float_of_int (3*i+1)) |> Lacaml.D.Vec.of_array in let v1 = Parallel.Vec.of_vec a in let v2 = Parallel.Vec.of_vec b in - let d1 = Parallel.dot v1 v2 in + let d1 = Parallel.dot v1 v2 |> Parallel.broadcast_float in let d2 = Lacaml.D.dot a b in (* let w = Parallel.Vec.to_vec v in