diff --git a/Parallel_mpi/Parallel.ml b/Parallel_mpi/Parallel.ml index 5641272..bf81735 100644 --- a/Parallel_mpi/Parallel.ml +++ b/Parallel_mpi/Parallel.ml @@ -83,6 +83,8 @@ module Node = struct | None -> assert false let broadcast x = broadcast_generic Mpi.broadcast x + + let barrier () = (* Mpi.barrier comm *) () end diff --git a/Parallel_mpi/Parallel.mli b/Parallel_mpi/Parallel.mli index 19d1f23..9a74928 100644 --- a/Parallel_mpi/Parallel.mli +++ b/Parallel_mpi/Parallel.mli @@ -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 diff --git a/Utils/FourIdxStorage.ml b/Utils/FourIdxStorage.ml index b1e45a2..078ffca 100644 --- a/Utils/FourIdxStorage.ml +++ b/Utils/FourIdxStorage.ml @@ -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 |] - |> 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 + | `Dense -> let result = + SharedMemory.create Float64 [| size*size ; size*size |] + |> Bigarray.array2_of_genarray + 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