10
1
mirror of https://gitlab.com/scemama/QCaml.git synced 2024-12-22 04:13:33 +01:00

Added SharedMemory

This commit is contained in:
Anthony Scemama 2019-04-01 15:21:22 +02:00
parent 4a6f23dcdd
commit dce6e3fb66

View File

@ -0,0 +1,23 @@
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 _ -> ());
if Parallel.Node.master then
begin
let fd = Unix.openfile filename [Unix.O_RDWR] 0o600 in
let result =
Unix.map_file fd data_type Bigarray.fortran_layout true size_array
in
Bigarray.Genarray.fill result 0.;
Parallel.Node.barrier ();
result
end
else
begin
Parallel.Node.barrier ();
let fd = Unix.openfile filename [Unix.O_RDONLY] 0o600 in
Unix.map_file fd data_type Bigarray.fortran_layout false size_array
end