mirror of
https://gitlab.com/scemama/QCaml.git
synced 2024-07-11 22:03:37 +02:00
Added SharedMemory
This commit is contained in:
parent
db70b22629
commit
4a6f23dcdd
|
@ -83,6 +83,8 @@ module Node = struct
|
||||||
| None -> assert false
|
| None -> assert false
|
||||||
|
|
||||||
let broadcast x = broadcast_generic Mpi.broadcast x
|
let broadcast x = broadcast_generic Mpi.broadcast x
|
||||||
|
|
||||||
|
let barrier () = (* Mpi.barrier comm *) ()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,7 @@ val broadcast_float_array : float array -> float array
|
||||||
val broadcast_vec : Lacaml.D.vec -> Lacaml.D.vec
|
val broadcast_vec : Lacaml.D.vec -> Lacaml.D.vec
|
||||||
(** Broadcasts a Lacaml vector to all processes. *)
|
(** Broadcasts a Lacaml vector to all processes. *)
|
||||||
|
|
||||||
|
|
||||||
(** {5 Intra-node operations} *)
|
(** {5 Intra-node operations} *)
|
||||||
module Node : sig
|
module Node : sig
|
||||||
val name : string
|
val name : string
|
||||||
|
@ -46,10 +47,14 @@ module Node : sig
|
||||||
|
|
||||||
val broadcast : 'a lazy_t -> 'a
|
val broadcast : 'a lazy_t -> 'a
|
||||||
(** Broadcasts data to all the processes of the current node. *)
|
(** Broadcasts data to all the processes of the current node. *)
|
||||||
|
|
||||||
|
val barrier : unit -> unit
|
||||||
|
(** Wait for all processes among the node to reach this point. *)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
(*
|
(*
|
||||||
(** {5 Intra-node operations} *)
|
(** {5 Inter-node operations} *)
|
||||||
module InterNode : sig
|
module InterNode : sig
|
||||||
|
|
||||||
val comm : Mpi.communicator
|
val comm : Mpi.communicator
|
||||||
|
|
|
@ -14,7 +14,6 @@ type storage_t =
|
||||||
type t =
|
type t =
|
||||||
{
|
{
|
||||||
size : int ;
|
size : int ;
|
||||||
filename : string ;
|
|
||||||
four_index : storage_t ;
|
four_index : storage_t ;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -128,41 +127,18 @@ let set ~r1 ~r2 ~value =
|
||||||
let increment ~r1 ~r2 =
|
let increment ~r1 ~r2 =
|
||||||
increment_four_index ~r1 ~r2
|
increment_four_index ~r1 ~r2
|
||||||
|
|
||||||
let create ~size ?temp_dir sparsity =
|
let create ~size ?(temp_dir="/dev/shm") sparsity =
|
||||||
assert (size < max_index);
|
assert (size < max_index);
|
||||||
let filename = Parallel.broadcast (lazy (Filename.temp_file ?temp_dir "4idx." ".tmp")) in
|
|
||||||
at_exit (fun () -> try Sys.remove filename with _ -> ());
|
|
||||||
let four_index =
|
let four_index =
|
||||||
match sparsity with
|
match sparsity with
|
||||||
| `Dense ->
|
| `Dense -> let result =
|
||||||
let result =
|
SharedMemory.create Float64 [| size*size ; size*size |]
|
||||||
if Parallel.master then
|
|> Bigarray.array2_of_genarray
|
||||||
begin
|
in Dense result
|
||||||
Printf.printf "filename: %s\n%!" filename;
|
| `Sparse -> let result = Hashtbl.create (size*size+13) in
|
||||||
let fd = Unix.openfile filename [Unix.O_RDWR] 0o600 in
|
|
||||||
let result =
|
|
||||||
Unix.map_file fd Float64 Bigarray.fortran_layout true
|
|
||||||
[| size*size ; size*size |]
|
|
||||||
|> Bigarray.array2_of_genarray
|
|
||||||
in Bigarray.Array2.fill result 0.;
|
|
||||||
Parallel.barrier ();
|
|
||||||
result
|
|
||||||
end
|
|
||||||
else
|
|
||||||
begin
|
|
||||||
Parallel.barrier ();
|
|
||||||
let fd = Unix.openfile filename [Unix.O_RDONLY] 0o600 in
|
|
||||||
Unix.map_file fd Float64 Bigarray.fortran_layout false
|
|
||||||
[| size*size ; size*size |]
|
|
||||||
|> Bigarray.array2_of_genarray
|
|
||||||
end
|
|
||||||
in
|
|
||||||
Dense result
|
|
||||||
| `Sparse ->
|
|
||||||
let result = Hashtbl.create (size*size+13) in
|
|
||||||
Sparse result
|
Sparse result
|
||||||
in
|
in
|
||||||
{ size ; filename ; four_index }
|
{ size ; four_index }
|
||||||
|
|
||||||
|
|
||||||
let size t = t.size
|
let size t = t.size
|
||||||
|
|
Loading…
Reference in New Issue
Block a user