10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-11-19 04:22:21 +01:00

Fixed SharedMemory

This commit is contained in:
Anthony Scemama 2019-04-01 16:05:43 +02:00
parent dce6e3fb66
commit 5bd2edde7b
2 changed files with 6 additions and 4 deletions

View File

@ -84,7 +84,7 @@ module Node = struct
let broadcast x = broadcast_generic Mpi.broadcast x let broadcast x = broadcast_generic Mpi.broadcast x
let barrier () = (* Mpi.barrier comm *) () let barrier () = Mpi.barrier comm
end end

View File

@ -2,22 +2,24 @@ let create ?(temp_dir="/dev/shm") data_type size_array =
let filename = let filename =
Parallel.Node.broadcast (lazy (Filename.temp_file ~temp_dir "4idx." ".tmp")) Parallel.Node.broadcast (lazy (Filename.temp_file ~temp_dir "4idx." ".tmp"))
in in
at_exit (fun () -> try Sys.remove filename with _ -> ()); Printf.printf "File:%s\n%!" filename;
if Parallel.Node.master then if Parallel.Node.master then
begin begin
let fd = Unix.openfile filename [Unix.O_RDWR] 0o600 in let fd = Unix.openfile filename Unix.[O_RDWR ; O_CREAT] 0o777 in
let result = let result =
Unix.map_file fd data_type Bigarray.fortran_layout true size_array Unix.map_file fd data_type Bigarray.fortran_layout true size_array
in in
Bigarray.Genarray.fill result 0.; Bigarray.Genarray.fill result 0.;
Parallel.Node.barrier (); Parallel.Node.barrier ();
at_exit (fun () -> Unix.close fd ; try Sys.remove filename with _ -> ());
result result
end end
else else
begin begin
Parallel.Node.barrier (); Parallel.Node.barrier ();
let fd = Unix.openfile filename [Unix.O_RDONLY] 0o600 in let fd = Unix.openfile filename [Unix.O_RDONLY] 0o777 in
at_exit (fun () -> Unix.close fd ; try Sys.remove filename with _ -> ());
Unix.map_file fd data_type Bigarray.fortran_layout false size_array Unix.map_file fd data_type Bigarray.fortran_layout false size_array
end end