Working on binary I/O

This commit is contained in:
Anthony Scemama 2022-01-11 14:47:04 +01:00
parent dfbbf8b329
commit ca7f0f0171
5 changed files with 29 additions and 17 deletions

View File

@ -120,13 +120,17 @@ let of_bytes b =
let to_string b = let to_string b =
Printf.sprintf "%s %s # %s %s %s %d" if Qmcchem_config.binary_io then
(Sample.to_string b.value ) to_bytes b
(Weight.to_float b.weight |> string_of_float) |> Bytes.to_string
(Property.to_string b.property) else
(Compute_node.to_string b.compute_node) Printf.sprintf "%s %s # %s %s %s %d"
(string_of_int b.pid) (Sample.to_string b.value )
(Block_id.to_int b.block_id) (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(

View File

@ -8,10 +8,10 @@ let root = lazy (
(* PATH environment variable as a list of strings *) (* PATH environment variable as a list of strings *)
let path = lazy ( let path = lazy (
let p = let p =
try Sys.getenv "PATH" with try Sys.getenv "PATH" with
| Not_found -> failwith "PATH environment variable is not set" | Not_found -> failwith "PATH environment variable is not set"
in in
String.split_on_char ':' p String.split_on_char ':' p
) )
@ -23,8 +23,8 @@ let full_path exe =
| [] -> None | [] -> None
| head :: tail -> | head :: tail ->
begin begin
let fp = let fp =
Filename.concat head exe Filename.concat head exe
in in
if Sys.file_exists fp then if Sys.file_exists fp then
Some fp Some fp
@ -82,8 +82,8 @@ let hostname = lazy (
) )
external get_ipv4_address_for_interface : string -> string = external get_ipv4_address_for_interface : string -> string =
"get_ipv4_address_for_interface" "get_ipv4_address_for_interface"
let ip_address = lazy ( let ip_address = lazy (
@ -106,7 +106,7 @@ let ip_address = lazy (
end end
| Some interface -> | Some interface ->
let result = get_ipv4_address_for_interface interface in let result = get_ipv4_address_for_interface interface in
if String.sub result 0 5 = "error" then if String.sub result 0 5 = "error" then
Printf.sprintf "Unable to use network interface %s" interface Printf.sprintf "Unable to use network interface %s" interface
|> failwith |> failwith
else else
@ -115,3 +115,5 @@ let ip_address = lazy (
let binary_io = false

View File

@ -758,7 +758,8 @@ let run ?(daemon=true) ezfio_filename =
| Some wall -> | Some wall ->
begin begin
output_string !block_channel (Block.to_string wall); output_string !block_channel (Block.to_string wall);
output_char !block_channel '\n'; if not Qmcchem_config.binary_io then
output_char !block_channel '\n';
end end
| _ -> () | _ -> ()
end end
@ -767,7 +768,8 @@ let run ?(daemon=true) ezfio_filename =
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 b);
output_char !block_channel '\n'; if not Qmcchem_config.binary_io then
output_char !block_channel '\n';
recv_log (Block.to_string b) recv_log (Block.to_string b)
end end
| Message.Test | Message.Test

View File

@ -344,7 +344,7 @@ let create_ezfio_handler () =
let lines = let lines =
input_lines "ezfio.ml" input_lines "ezfio.ml"
(* /!\ Change when ezfio.ml changes *) (* /!\ Change when ezfio.ml changes *)
|> List.mapi (fun i l -> if i > 444 then Some l else None) |> List.mapi (fun i l -> if i > 442 then Some l else None)
|> List.filter (fun x -> x <> None) |> List.filter (fun x -> x <> None)
|> List.map (fun x -> |> List.map (fun x ->
match x with match x with

View File

@ -146,6 +146,10 @@ for p in properties_qmcvar:
print >>file, """| %(P)s -> "%(P)s" """%{'P':p[1].capitalize(), 'p':p[1]} print >>file, """| %(P)s -> "%(P)s" """%{'P':p[1].capitalize(), 'p':p[1]}
print >>file, """;; print >>file, """;;
let of_bytes x =
Bytes.to_string x
|> of_string
let to_bytes x = let to_bytes x =
to_string x to_string x
|> Bytes.of_string |> Bytes.of_string