Removing core

This commit is contained in:
Anthony Scemama 2019-07-19 11:46:29 +02:00
parent 4c870cb62b
commit a719c694ce
3 changed files with 70 additions and 30 deletions

View File

@ -147,11 +147,12 @@ let raw_data ?(locked=true) () =
module StringSet = Set.Make(String)
let properties = lazy (
List.fold_left (fun s x -> StringSet.add (Property.to_string x.property) s) StringSet.empty (raw_data ())
|> StringSet.elements
let h = Hashtbl.create 63 in
List.iter (fun x ->
Hashtbl.add h (Property.to_string x.property) x.property)
(raw_data ());
Hashtbl.fold (fun k v a -> v :: a) h []
)

View File

@ -565,7 +565,7 @@ let compress =
(** Last value on each compute node (for wall_time) *)
let max_value_per_compute_node t =
let table = String.Table.create ()
let table = Hashtbl.create 63
in
let create_key block =
Printf.sprintf "%s %10.10d"
@ -603,8 +603,8 @@ let max_value_per_compute_node t =
(** String representation *)
let to_string p =
match p.property with
| Property.Cpu -> Printf.sprintf "%s" (Time.Span.to_string (Time.Span.of_sec (sum p)))
| Property.Wall -> Printf.sprintf "%s" (Time.Span.to_string (Time.Span.of_sec (sum (max_value_per_compute_node p))))
| Property.Cpu -> Printf.sprintf "%s" (Time.string_of_sec (sum p))
| Property.Wall -> Printf.sprintf "%s" (Time.string_of_sec (sum (max_value_per_compute_node p)))
| Property.Accep -> Printf.sprintf "%16.10f" (average p |> Average.to_float)
| _ ->
begin
@ -667,17 +667,28 @@ let compress_files () =
Lazy.force dir_name
in
let files =
Sys.ls_dir dir_name
Sys.readdir dir_name
|> Array.to_list
|> List.filter (fun x ->
match String.substr_index ~pattern:"locked" x with
| Some x -> false
| None -> true
try
Str.search_backward (Str.regexp "locked") x (String.length x) >= 0
with
| Not_found -> true
)
|> List.map (fun x -> dir_name^x)
in
let out_channel_dir =
Filename.temp_dir ~in_dir:(!Ezfio.ezfio_filename ^ "/blocks/") "qmc" ""
let rand_num = Random.int 1000000 |> string_of_int in
let tmp_dir =
Filename.concat "!Ezfio.ezfio_filename" @@
Filename.concat "blocks" @@
Filename.concat "qmc" rand_num
in
try
Unix.mkdir tmp_dir 0o600;
tmp_dir
with _ -> raise (Sys_error "Cannot create temp dir")
in
let out_channel_name =
@ -687,11 +698,12 @@ let compress_files () =
Unix.getpid ()
|> string_of_int
in
String.concat [ hostname ; "." ; suffix ]
String.concat "." [ hostname ; suffix ]
in
let block_channel =
Out_channel.create (out_channel_dir ^ out_channel_name)
Filename.concat out_channel_dir out_channel_name
|> open_out
in
List.iter (fun p ->
@ -709,14 +721,15 @@ let compress_files () =
|> merge_per_compute_node_and_block_id
in
List.iter (fun x ->
Out_channel.output_string block_channel (Block.to_string x);
Out_channel.output_char block_channel '\n';
output_string block_channel (Block.to_string x);
output_char block_channel '\n';
) l.data
) properties ;
Out_channel.close block_channel;
close_out block_channel;
List.iter Unix.remove files ;
Unix.rename ~src:(out_channel_dir^out_channel_name) ~dst:(dir_name^out_channel_name);
List.iter Unix.unlink files ;
Unix.rename (Filename.concat out_channel_dir out_channel_name)
(Filename.concat dir_name out_channel_name);
Unix.rmdir out_channel_dir
@ -738,7 +751,7 @@ let autocovariance { property ; data } =
if (i > 1) then (float_of_int i) else 1.
in
let r =
Array.sub 0 i x_t
Array.sub x_t 0 i
|> Array.fold_left (fun accu x ->
accu +. x *. x_t.(i)) 0.
in
@ -756,7 +769,7 @@ let centered_cumulants { property ; data } =
|> Average.to_float
in
let centered_data =
List.map ~f:(fun x ->
List.map (fun x ->
( (Weight.to_float x.Block.weight),
(Sample.to_float x.Block.value) -. ave )
)
@ -764,20 +777,20 @@ let centered_cumulants { property ; data } =
in
let var =
let (num, denom) =
List.fold_left ~init:(0., 0.) ~f:(fun (a2, ad) (w,x) ->
List.fold_left (fun (a2, ad) (w,x) ->
let x2 = x *. x
in
let var = w *. x2
and den = w
in (a2 +. var, ad +. den)
) centered_data
) (0., 0.) centered_data
in num /. denom
in
let centered_data =
let sigma_inv =
1. /. (sqrt var)
in
List.map ~f:(fun x ->
List.map (fun x ->
( (Weight.to_float x.Block.weight),
( (Sample.to_float x.Block.value) -. ave ) *. sigma_inv )
)
@ -785,14 +798,14 @@ let centered_cumulants { property ; data } =
in
let (cum3,cum4) =
let (cum3, cum4, denom) =
List.fold_left ~init:(0., 0., 0.) ~f:(fun (a3, a4, ad) (w,x) ->
List.fold_left (fun (a3, a4, ad) (w,x) ->
let x2 = x *. x
in
let cum3 = w *. x2 *. x
and cum4 = w *. x2 *. x2
and den = w
in (a3 +. cum3, a4 +. cum4, ad +. den)
) centered_data
) (0., 0., 0.) centered_data
in
( cum3 /. denom, cum4 /. denom -. 3. )
in
@ -817,9 +830,9 @@ let histogram { property ; data } =
let delta_x =
length /. (n-.1.)
and result =
Array.init ~f:(fun _ -> 0.) (int_of_float (n +. 1.))
Array.init (int_of_float n + 1) (fun _ -> 0.)
in
List.iter ~f:(fun x ->
List.iter (fun x ->
let w =
(Weight.to_float x.Block.weight)
and x =
@ -834,10 +847,10 @@ let histogram { property ; data } =
;
let norm =
1. /. ( delta_x *. (
Array.fold_left ~init:0. ~f:(fun accu x -> accu +. x) result
Array.fold_left (fun accu x -> accu +. x) 0. result
) )
in
Array.mapi ~f:(fun i x -> (min +. (float_of_int i)*.delta_x, x *. norm) ) result
Array.mapi (fun i x -> (min +. (float_of_int i)*.delta_x, x *. norm) ) result
|> Array.to_list

26
ocaml/Time.ml Normal file
View File

@ -0,0 +1,26 @@
let of_sec s =
Unix.gmtime s
let to_sec t =
let sec = t.Unix.tm_sec
and min = t.Unix.tm_min
and hour = t.Unix.tm_hour
and mday = t.Unix.tm_mday
in
sec +
min * 60 +
hour * 60 * 60 +
mday * 60 * 60 * 24
let string_of_t t =
let mday = t.Unix.tm_mday in
let sec = t.Unix.tm_sec
and min = t.Unix.tm_min
and hour = t.Unix.tm_hour + 24*mday
in
Printf.sprintf "%2d:%2d:%2d" hour min sec
let string_of_sec s =
of_sec s
|> string_of_t