mirror of
https://gitlab.com/scemama/QCaml.git
synced 2025-01-03 01:55:40 +01:00
Added SharedMemory
This commit is contained in:
parent
db70b22629
commit
4a6f23dcdd
@ -83,6 +83,8 @@ module Node = struct
|
||||
| None -> assert false
|
||||
|
||||
let broadcast x = broadcast_generic Mpi.broadcast x
|
||||
|
||||
let barrier () = (* Mpi.barrier comm *) ()
|
||||
end
|
||||
|
||||
|
||||
|
@ -30,6 +30,7 @@ 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
|
||||
@ -46,10 +47,14 @@ module Node : sig
|
||||
|
||||
val broadcast : 'a lazy_t -> 'a
|
||||
(** 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
|
||||
|
||||
|
||||
(*
|
||||
(** {5 Intra-node operations} *)
|
||||
(** {5 Inter-node operations} *)
|
||||
module InterNode : sig
|
||||
|
||||
val comm : Mpi.communicator
|
||||
|
@ -14,7 +14,6 @@ type storage_t =
|
||||
type t =
|
||||
{
|
||||
size : int ;
|
||||
filename : string ;
|
||||
four_index : storage_t ;
|
||||
}
|
||||
|
||||
@ -128,41 +127,18 @@ let set ~r1 ~r2 ~value =
|
||||
let increment ~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);
|
||||
let filename = Parallel.broadcast (lazy (Filename.temp_file ?temp_dir "4idx." ".tmp")) in
|
||||
at_exit (fun () -> try Sys.remove filename with _ -> ());
|
||||
let four_index =
|
||||
match sparsity with
|
||||
| `Dense ->
|
||||
let result =
|
||||
if Parallel.master then
|
||||
begin
|
||||
Printf.printf "filename: %s\n%!" filename;
|
||||
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 |]
|
||||
| `Dense -> let result =
|
||||
SharedMemory.create Float64 [| 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
|
||||
in Dense result
|
||||
| `Sparse -> let result = Hashtbl.create (size*size+13) in
|
||||
Sparse result
|
||||
in
|
||||
{ size ; filename ; four_index }
|
||||
{ size ; four_index }
|
||||
|
||||
|
||||
let size t = t.size
|
||||
|
Loading…
Reference in New Issue
Block a user