mirror of
https://gitlab.com/scemama/QCaml.git
synced 2024-11-06 22:23:42 +01:00
Prepared inter-node
This commit is contained in:
parent
0897beabd5
commit
db70b22629
@ -59,7 +59,7 @@ module Node = struct
|
||||
|
||||
let name = Unix.gethostname ()
|
||||
|
||||
let comm_node =
|
||||
let comm =
|
||||
Mpi.allgather (name, rank) Mpi.comm_world
|
||||
|> Array.to_list
|
||||
|> List.filter (fun (n, r) -> name = n)
|
||||
@ -69,10 +69,20 @@ module Node = struct
|
||||
|> Mpi.(comm_create comm_world)
|
||||
|
||||
let rank =
|
||||
Mpi.comm_rank comm_node
|
||||
Mpi.comm_rank comm
|
||||
|
||||
let master = rank = 0
|
||||
|
||||
let broadcast_generic broadcast x =
|
||||
let x =
|
||||
if master then Some (Lazy.force x)
|
||||
else None
|
||||
in
|
||||
match broadcast x 0 comm with
|
||||
| Some x -> x
|
||||
| None -> assert false
|
||||
|
||||
let broadcast x = broadcast_generic Mpi.broadcast x
|
||||
end
|
||||
|
||||
|
||||
|
@ -30,6 +30,41 @@ val broadcast_float_array : float array -> float array
|
||||
val broadcast_vec : Lacaml.D.vec -> Lacaml.D.vec
|
||||
(** Broadcasts a Lacaml vector to all processes. *)
|
||||
|
||||
(** {5 Intra-node operations} *)
|
||||
module Node : sig
|
||||
val name : string
|
||||
(** Name of the current host *)
|
||||
|
||||
val comm : Mpi.communicator
|
||||
(** MPI Communicator on the current node *)
|
||||
|
||||
val rank : Mpi.rank
|
||||
(** Rank of the current process in the node *)
|
||||
|
||||
val master : bool
|
||||
(** If true, master process of the node *)
|
||||
|
||||
val broadcast : 'a lazy_t -> 'a
|
||||
(** Broadcasts data to all the processes of the current node. *)
|
||||
end
|
||||
|
||||
(*
|
||||
(** {5 Intra-node operations} *)
|
||||
module InterNode : sig
|
||||
|
||||
val comm : Mpi.communicator
|
||||
(** MPI Communicator among the master processes of the each node *)
|
||||
|
||||
val rank : Mpi.rank
|
||||
(** Rank of the current process in the inter-node communicator *)
|
||||
|
||||
val master : bool
|
||||
(** If true, master process of the inter-node communicator *)
|
||||
|
||||
val broadcast : 'a lazy_t -> 'a
|
||||
(** Broadcasts data to all the processes of the inter-node communicator. *)
|
||||
end
|
||||
*)
|
||||
|
||||
(** {5 Vector operations} *)
|
||||
module Vec : sig
|
||||
|
@ -21,7 +21,7 @@ let v = Parallel.Vec.init 47 (fun i -> float_of_int i) in
|
||||
print_newline ()
|
||||
|
||||
|
||||
let () =
|
||||
let pouet2 () =
|
||||
let f (a,b) = (Parallel.rank, a+b) in
|
||||
let input = Stream.of_list
|
||||
[ (1,2) ; (3,4) ; (5,6) ; (7,8) ; (9,10)
|
||||
@ -34,3 +34,11 @@ let () =
|
||||
in
|
||||
Stream.iter (fun (x,y) -> Printf.printf "%d %d\n%!" x y) stream
|
||||
|
||||
|
||||
open Printf
|
||||
let () =
|
||||
printf "%d : %s\n" Parallel.rank Parallel.Node.name;
|
||||
let value = Parallel.broadcast (lazy Parallel.rank) in
|
||||
printf "%d : %d\n" Parallel.rank value;
|
||||
let value = Parallel.Node.broadcast (lazy Parallel.rank) in
|
||||
printf "%d : %d\n" Parallel.rank value
|
||||
|
Loading…
Reference in New Issue
Block a user