10
1
mirror of https://gitlab.com/scemama/qmcchem.git synced 2024-11-07 06:33:38 +01:00

Binary output

This commit is contained in:
Anthony Scemama 2022-01-11 22:12:02 +01:00
parent ca7f0f0171
commit 6798019161
5 changed files with 109 additions and 49 deletions

View File

@ -41,6 +41,7 @@ export LD_LIBRARY_PATH="\${QMCCHEM_PATH}/lib:\${LD_LIBRARY_PATH}"
export LIBRARY_PATH="\${QMCCHEM_PATH}/lib:\${LIBRARY_PATH}" export LIBRARY_PATH="\${QMCCHEM_PATH}/lib:\${LIBRARY_PATH}"
export QMCCHEM_MPIRUN="mpirun" export QMCCHEM_MPIRUN="mpirun"
export QMCCHEM_MPIRUN_FLAGS="" export QMCCHEM_MPIRUN_FLAGS=""
#export QMCCHEM_IO="B"
export C_INCLUDE_PATH="\${QMCCHEM_PATH}/include:\${C_INCLUDE_PATH}" export C_INCLUDE_PATH="\${QMCCHEM_PATH}/include:\${C_INCLUDE_PATH}"
#export QMCCHEM_NIC=ib0 #export QMCCHEM_NIC=ib0
source \${QMCCHEM_PATH}/irpf90/bin/irpman source \${QMCCHEM_PATH}/irpf90/bin/irpman

View File

@ -51,6 +51,26 @@ let of_string s =
let to_short_string b =
Printf.sprintf "%s # %s %d %d"
(Property.to_string b.property)
(Compute_node.to_string b.compute_node)
b.pid
(Block_id.to_int b.block_id)
let to_string b =
Printf.sprintf "%s %s # %s %s %s %d"
(Sample.to_string b.value )
(Weight.to_float b.weight |> string_of_float)
(Property.to_string b.property)
(Compute_node.to_string b.compute_node)
(string_of_int b.pid)
(Block_id.to_int b.block_id)
let zero = let zero =
bytes_of_int 0 bytes_of_int 0
@ -83,6 +103,9 @@ let read_bytes b =
Then, read the next m bytes and return a tuple containing the decoded data and the rest. Then, read the next m bytes and return a tuple containing the decoded data and the rest.
*) *)
let l = Bytes.length b in let l = Bytes.length b in
if l < 8 then
failwith "Zero-sized bytes"
else
let m = let m =
Bytes.get_int64_le b 0 Bytes.get_int64_le b 0
|> Int64.to_int |> Int64.to_int
@ -96,9 +119,6 @@ let read_bytes b =
let of_bytes b = let of_bytes b =
let b, _rest =
read_bytes b
in
let rec loop accu s = let rec loop accu s =
match read_bytes s with match read_bytes s with
| data, None -> List.rev (data :: accu) | data, None -> List.rev (data :: accu)
@ -106,7 +126,8 @@ let of_bytes b =
in in
let result = let result =
match loop [] b with match loop [] b with
| value :: weight :: property :: compute_node :: pid :: block_id :: [] -> | property :: value :: weight :: pid :: block_id :: compute_node :: [] ->
Some
{ property = Property.of_bytes property; { property = Property.of_bytes property;
value = Sample.of_bytes value; value = Sample.of_bytes value;
weight = Weight.of_bytes weight; weight = Weight.of_bytes weight;
@ -114,24 +135,17 @@ let of_bytes b =
block_id = Block_id.of_bytes block_id; block_id = Block_id.of_bytes block_id;
compute_node = Compute_node.of_bytes compute_node; compute_node = Compute_node.of_bytes compute_node;
} }
| _ -> assert false | _ -> None
in in
result result
let to_string b = let of_string_or_bytes s =
if Qmcchem_config.binary_io then if Qmcchem_config.binary_io then
to_bytes b Bytes.of_string s
|> Bytes.to_string |> of_bytes
else else
Printf.sprintf "%s %s # %s %s %s %d" of_string s
(Sample.to_string b.value )
(Weight.to_float b.weight |> string_of_float)
(Property.to_string b.property)
(Compute_node.to_string b.compute_node)
(string_of_int b.pid)
(Block_id.to_int b.block_id)
let dir_name = lazy( let dir_name = lazy(
let ezfio_filename = let ezfio_filename =
@ -191,6 +205,38 @@ let update_raw_data ?(locked=true) () =
| Some x -> transform (x::new_list) tail | Some x -> transform (x::new_list) tail
in in
if Qmcchem_config.binary_io then
begin
let result =
let rec aux buf accu =
(* Read one block *)
let item, rest =
read_bytes buf
in
match of_bytes item with
| None -> []
| Some item ->
match rest with
| None -> List.rev (item::accu)
| Some rest -> (aux [@tailcall]) rest (item::accu)
in
List.concat_map (fun filename ->
let ic = open_in filename in
let length = in_channel_length ic in
let result =
if length > 0 then
let buf = Bytes.create length in
really_input ic buf 0 length;
aux buf []
else []
in
close_in ic;
result ) files
in
result
end
else
begin
let result = let result =
let rec aux ic accu = let rec aux ic accu =
let l = let l =
@ -211,6 +257,15 @@ let update_raw_data ?(locked=true) () =
|> transform [] |> transform []
in in
result result
end
let to_string_or_bytes b =
if Qmcchem_config.binary_io then
to_bytes b
|> Bytes.to_string
else
to_string b
let raw_data ?(locked=true) () = let raw_data ?(locked=true) () =

View File

@ -115,5 +115,8 @@ let ip_address = lazy (
let binary_io = false let binary_io =
try
Sys.getenv "QMCCHEM_IO" = "B"
with Not_found -> false

View File

@ -757,7 +757,7 @@ let run ?(daemon=true) ezfio_filename =
match wall with match wall with
| Some wall -> | Some wall ->
begin begin
output_string !block_channel (Block.to_string wall); output_string !block_channel (Block.to_string_or_bytes wall);
if not Qmcchem_config.binary_io then if not Qmcchem_config.binary_io then
output_char !block_channel '\n'; output_char !block_channel '\n';
end end
@ -767,10 +767,10 @@ let run ?(daemon=true) ezfio_filename =
begin begin
if (status = Status.Running) then if (status = Status.Running) then
touch_worker b.Block.compute_node b.Block.pid ; touch_worker b.Block.compute_node b.Block.pid ;
output_string !block_channel (Block.to_string b); output_string !block_channel (Block.to_string_or_bytes b);
if not Qmcchem_config.binary_io then if not Qmcchem_config.binary_io then
output_char !block_channel '\n'; output_char !block_channel '\n';
recv_log (Block.to_string b) recv_log (Block.to_short_string b)
end end
| Message.Test | Message.Test
| Message.GetWalkers _ | Message.GetWalkers _

View File

@ -740,7 +740,8 @@ let compress_files () =
*) *)
in in
List.iter (fun x -> List.iter (fun x ->
output_string block_channel (Block.to_string x); output_string block_channel (Block.to_string_or_bytes x);
if not Qmcchem_config.binary_io then
output_char block_channel '\n'; output_char block_channel '\n';
) l.data ) l.data
) properties ; ) properties ;