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 barrier () = (* Mpi.barrier comm *) ()
let barrier () = Mpi.barrier comm
end

View File

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