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

26 lines
914 B
OCaml
Raw Normal View History

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