diff --git a/bin/demon.ml b/bin/demon.ml index 7b0eb4b017fe37332f420679e785e538698b1b50..f479bbcae04bb942314e65bd306a41c96cefa771 100644 --- a/bin/demon.ml +++ b/bin/demon.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 13/03/2019 (at 10:10) by Erwan Jahier> *) +(* Time-stamp: <modified the 13/03/2019 (at 17:44) by Erwan Jahier> *) type t = | Synchronous (* select all actions *) @@ -29,21 +29,6 @@ let (synchrone: 'a list list -> 'a list) = fun all -> al -(* xxx use RifIO.read instead ! *) -let read_bool rif_mode p = - let x = input_char stdin in - if not rif_mode then ( - Printf.printf "Enter a bool [1,t,T|0,f,F] for process %s\n" p.Process.pid; - flush stdout - ); - let rec aux x = - match x with - | '0' | 'f' | 'F' -> false - | '1' | 't' | 'T' -> true - | 'q' -> Printf.eprintf "bye\n"; flush stdout; exit 0 - | _ -> aux (input_char stdin) - in - aux x type pna = Process.t * Topology.neighbor list * Algo.action (* From a list of enabled actions (pna) returns: @@ -68,23 +53,23 @@ let rec map3 f l1 l2 l3 = let (custom: bool -> pna list list -> Process.t list -> bool list list -> string * pna list) = - fun rif_mode all pl enab_ll -> - let f p al enab_l = + fun verbose_mode pnall pl enab_ll -> + let f p pnal enab_l = let actions = p.Process.actions in - let trigger_l = List.map (fun _a -> read_bool rif_mode p) actions in + let trigger_l = List.map (fun a -> RifRead.bool verbose_mode p a) actions in let acti_l_al = map3 (fun trig enab a -> let acti = trig && enab in acti, if acti then - let pna = List.find (fun (_,_,a') -> a=a') al in + let pna = List.find (fun (_,_,a') -> a=a') pnal in [pna] else [] ) trigger_l enab_l actions in acti_l_al in - let acti_l_all = map3 f pl all enab_ll in + let acti_l_all = map3 f pl pnall enab_ll in let acti_l_al = List.flatten acti_l_all in let acti_l,al = List.split acti_l_al in let acti = String.concat " " (List.map (fun b -> if b then "t" else "f") acti_l) in @@ -96,13 +81,13 @@ let (remove_empty_list: 'a list list -> 'a list list) = let (f: bool -> t -> Process.t list -> pna list list -> bool list list -> string * pna list) = - fun rif_mode demon pl all enab -> + fun verbose_mode demon pl all enab -> match demon with | Synchronous -> "", synchrone (remove_empty_list all) | Central -> "", random1 (remove_empty_list all) | LocallyCentral -> assert false | Distributed -> "", random (remove_empty_list all) - | Custom -> custom rif_mode all pl enab + | Custom -> custom verbose_mode all pl enab diff --git a/bin/rifRead.ml b/bin/rifRead.ml new file mode 100644 index 0000000000000000000000000000000000000000..f1df668d0f2247e4ae29a570481d823cda053bf8 --- /dev/null +++ b/bin/rifRead.ml @@ -0,0 +1,30 @@ +(* Time-stamp: <modified the 13/03/2019 (at 17:54) by Erwan Jahier> *) + +(* xxx use RifIO.read instead ! *) +let bool verbose_mode p a = + if verbose_mode then ( + Printf.eprintf "Enter a bool [1,t,T|0,f,F] for process %s\n" p.Process.pid; + flush stderr + ); + let x = input_char stdin in + let rec aux x = + match x with + | '0' | 'f' | 'F' -> false + | '1' | 't' | 'T' -> true + | 'q' -> Printf.eprintf "bye\n"; flush stderr; exit 0 + | '#' -> skip_comment () + | x -> + if verbose_mode then (Printf.eprintf "'%c'" x; flush stderr); + aux (input_char stdin) + and skip_comment () = + match input_char stdin with + | '\n' -> aux (input_char stdin) + | _ -> skip_comment () + in + let res = aux x in + if verbose_mode then ( + flush stderr; + Printf.eprintf "%s_%s<-%s\n" p.Process.pid a (if res then "t" else "f"); + flush stderr + ); + res diff --git a/bin/rifRead.mli b/bin/rifRead.mli new file mode 100644 index 0000000000000000000000000000000000000000..feeec92f00fe87782e7fa3c4fb2da22eef78f2b4 --- /dev/null +++ b/bin/rifRead.mli @@ -0,0 +1,5 @@ +(* Time-stamp: <modified the 13/03/2019 (at 17:45) by Erwan Jahier> *) + +(** Reads on stdin a bool *) + +val bool: bool -> Process.t -> string -> bool diff --git a/bin/sasArg.ml b/bin/sasArg.ml index 39e82b7672e095bc289dbb29962e92344880c1ec..5dca76ec1aa8b3288e426f54bfa30fab3e02ff53 100644 --- a/bin/sasArg.ml +++ b/bin/sasArg.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 10/03/2019 (at 14:03) by Erwan Jahier> *) +(* Time-stamp: <modified the 13/03/2019 (at 16:59) by Erwan Jahier> *) type t = { @@ -7,6 +7,7 @@ type t = { mutable verbose: int; mutable demon: Demon.t; mutable rif: bool; + mutable ifi: bool; mutable _args : (string * Arg.spec * string) list; mutable _user_man : (string * string list) list; @@ -30,6 +31,7 @@ let (make_args : unit -> t) = verbose = 0; demon = Demon.Distributed; rif = false; + ifi = false; _args = []; _user_man = []; _hidden_man = []; @@ -105,6 +107,10 @@ let (mkoptab : t -> unit) = (Arg.Unit(fun () -> args.rif <- true)) ["Follows RIF conventions"]; + mkopt opt ["--ignore-first-inputs"; "-ifi"] + (Arg.Unit(fun () -> args.ifi <- true)) + ["Ignore first inputs (necessary to use luciole via lurette/rdbg/luciole-rif)"]; + mkopt opt ["--length";"-l"] ~arg:" <int>" (Arg.Int (fun i -> args.length <- i)) ["Maximum number of steps to be done (" ^ (string_of_int args.length) ^ " by default).\n"]; diff --git a/bin/sasa.ml b/bin/sasa.ml index a8123b6007a2bea45cdcb26c8dc0c45882a435a3..392cb5c142d60380df8f0b7a8b5381ad5330752e 100644 --- a/bin/sasa.ml +++ b/bin/sasa.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 13/03/2019 (at 10:57) by Erwan Jahier> *) +(* Time-stamp: <modified the 13/03/2019 (at 18:04) by Erwan Jahier> *) (* XXX Je pourrais utiliser Lwt pour rendre step non-bloquant, ce qui permettrait d'accelerer la simu sur les machines qui ont plusieurs @@ -100,15 +100,16 @@ let rec (simu: int -> int -> Process.t list -> string -> al::acc) [] pl_n in - let all = if custom then List.rev all else all in assert (List.length pl = List.length all); + let all = List.rev all in let enab_ll = - List.map2 - (fun p al -> - let al = List.map (fun (_,_,a) -> a) al in - List.map (fun a_static -> List.mem a_static al) p.actions) - pl - all + if not custom then [] else + List.map2 + (fun p al -> + let al = List.map (fun (_,_,a) -> a) al in + List.map (fun a_static -> List.mem a_static al) p.actions) + pl + all in let enable_val = String.concat " " (List.map (fun b -> if b then "t" else "f") @@ -119,7 +120,9 @@ let rec (simu: int -> int -> Process.t list -> string -> raise (Silent (n-i+1)) ); print_step n i e pl activate_val enable_val; - let next_activate_val, al = Demon.f SasArg.args.rif args.demon pl all enab_ll in + let next_activate_val, pnal = + Demon.f (SasArg.args.verbose > 1) args.demon pl all enab_ll + in (* Do the steps *) let lenv_list = @@ -127,18 +130,15 @@ let rec (simu: int -> int -> Process.t list -> string -> let nl4algo = List.map (to_algo_neighbor e) nl in let lenv = Env.get e p.pid in p, p.step nl4algo lenv a) - al + pnal in (* update the env *) let ne = List.fold_left update_env e lenv_list in - match all with - (* | [_] -> () *) - | [] -> assert false - | _ -> if i > 0 then simu n (i-1) pl next_activate_val pl_n ne else ( - if SasArg.args.rif && custom then ( - print_string "q\n"; flush stdout - )) + if i > 0 then simu n (i-1) pl next_activate_val pl_n ne else ( + if SasArg.args.rif then ( + print_string "q\n"; flush stdout + )) let () = ( try SasArg.parse Sys.argv; @@ -168,7 +168,6 @@ let () = let pl_n = List.combine pl neighors in if !Algo.verbose_level > 0 then List.iter dump_process pl_n; let n = SasArg.args.length in - let pl = List.rev pl in if SasArg.args.rif then ( Printf.printf "#inputs %s\n" (if SasArg.args.demon = Demon.Custom then ( @@ -181,6 +180,13 @@ let () = Printf.printf "#outputs %s\n" (StringOf.env_rif_decl pl); flush stdout ); + if SasArg.args.ifi then ( + List.iter + (fun p -> List.iter + (fun a -> ignore (RifRead.bool (args.verbose > 1) p a)) p.actions) + pl; + Printf.eprintf "Ignoring the first vectors of sasa inputs\n"; flush stderr; + ); simu n n pl "" pl_n e with | Dynlink.Error e -> Printf.printf "Error: %s\n" (Dynlink.error_message e) diff --git a/bin/topology.ml b/bin/topology.ml index 699a9913c3f4d7e53da56d46048203aada4ccd95..acb62645fc4ac4fce1ed17bf59a2c59edb476b64 100644 --- a/bin/topology.ml +++ b/bin/topology.ml @@ -1,4 +1,4 @@ -(* Time-stamp: <modified the 21/02/2019 (at 11:31) by Erwan Jahier> *) +(* Time-stamp: <modified the 13/03/2019 (at 14:49) by Erwan Jahier> *) open Graph open Graph.Dot_ast @@ -108,7 +108,8 @@ let (do_stmt: bool -> node list -> Dot_ast.stmt -> node list) = let (read: string -> t) = fun f -> let dot_file = Graph.Dot.parse_dot_ast f in assert (not dot_file.strict); - List.fold_left (do_stmt dot_file.digraph) [] dot_file.stmts + let res = List.fold_left (do_stmt dot_file.digraph) [] dot_file.stmts in + List.rev res type neighbor = { n_id: string; diff --git a/test/bfs-spanning-tree/Makefile b/test/bfs-spanning-tree/Makefile index bf1cad4afeb207da3340dd859050303776fb44d3..5e8f5b9d1fd8fdb6c91896e42e073a70fa799346 100644 --- a/test/bfs-spanning-tree/Makefile +++ b/test/bfs-spanning-tree/Makefile @@ -1,4 +1,4 @@ -# Time-stamp: <modified the 12/03/2019 (at 22:52) by Erwan Jahier> +# Time-stamp: <modified the 13/03/2019 (at 18:01) by Erwan Jahier> test: test0 lurette0 test0: cmxs @@ -27,7 +27,7 @@ lurette: lurette0 manual:cmxs lurette -o lurette.rif --sim2chro \ - -sut "$(sasa) fig5.1-noinit.dot -custd -rif" \ + -sut "$(sasa) fig5.1-noinit.dot -custd -rif -ifi" \ -env "lutin demon.lut -n manual" &&\ gnuplot-rif lurette.rif diff --git a/test/unison/Makefile b/test/unison/Makefile index 6420d43469f221a14e4251eb5b259dbee3a28bd3..68c3e4827c81cf5e8e10d9cdb8daa775bbf061d6 100644 --- a/test/unison/Makefile +++ b/test/unison/Makefile @@ -1,4 +1,4 @@ -# Time-stamp: <modified the 13/03/2019 (at 11:10) by Erwan Jahier> +# Time-stamp: <modified the 13/03/2019 (at 18:02) by Erwan Jahier> test: test1 test2 lurette0 @@ -18,7 +18,7 @@ gnuplot: ring.rif gnuplot-rif $< luciole: - luciole-rif $(sasa) ring.dot -custd -rif + luciole-rif $(sasa) ring.dot -custd -rif -ifi lurette0:cmxs lurette -o lurette.rif \