Skip to content
Snippets Groups Projects
Commit 44fa68e2 authored by erwan's avatar erwan
Browse files

Update: continue to refactor files and functions for SasaRun implementation

parent cd7bcd23
No related branches found
No related tags found
No related merge requests found
S bin S src
S lib/sasacore
S lib/algo S lib/algo
B /home/jahier/.opam/4.07.0/lib/ocaml B /home/jahier/.opam/4.07.0/lib/ocaml
B /home/jahier/.opam/4.07.0/lib/ocamlgraph B /home/jahier/.opam/4.07.0/lib/ocamlgraph
B _build/default/bin/.sasa.eobjs B _build/default/src/.sasaMain.eobjs
B _build/default/lib/algo/.algo.objs B _build/default/lib/algo/.algo.objs
B _build/default/lib/sasacore/.sascore.objs
...@@ -13,4 +13,5 @@ lib/sasacore/sasaVersion.ml: ...@@ -13,4 +13,5 @@ lib/sasacore/sasaVersion.ml:
echo "(* generated by ../Makefile.version *)" > lib/sasacore/sasaVersion.ml ; \ echo "(* generated by ../Makefile.version *)" > lib/sasacore/sasaVersion.ml ; \
echo "let str=\"$(VERSION)\"" >> lib/sasacore/sasaVersion.ml ; \ echo "let str=\"$(VERSION)\"" >> lib/sasacore/sasaVersion.ml ; \
echo "let sha=\"$(SHA)\"" >> lib/sasacore/sasaVersion.ml ; \ echo "let sha=\"$(SHA)\"" >> lib/sasacore/sasaVersion.ml ; \
echo "let branch=\"$(BRANCH)\"" >> lib/sasacore/sasaVersion.ml echo "let branch=\"$(BRANCH)\"" >> lib/sasacore/sasaVersion.ml ; \
echo "let maintainer = \"erwan.jahier@univ-grenoble-alpes.fr\"" >> lib/sasacore/sasaVersion.ml ;
(* Time-stamp: <modified the 14/03/2019 (at 17:31) by Erwan Jahier> *) (* Time-stamp: <modified the 15/03/2019 (at 22:37) by Erwan> *)
type t = { type t = {
...@@ -19,10 +19,10 @@ type t = { ...@@ -19,10 +19,10 @@ type t = {
mutable _margin : int; mutable _margin : int;
} }
let usage_msg = ("usage: " ^Sys.argv.(0) ^ " [<option>]* <topology>.dot let usage_msg tool = ("usage: " ^ tool ^ " [<option>]* <topology>.dot
use -h to see the available options. use -h to see the available options.
" ) " )
let print_usage () = Printf.printf "%s\n" usage_msg; flush stdout let print_usage tool = Printf.printf "%s\n" (usage_msg tool); flush stdout
let (make_args : unit -> t) = let (make_args : unit -> t) =
...@@ -36,16 +36,15 @@ let (make_args : unit -> t) = ...@@ -36,16 +36,15 @@ let (make_args : unit -> t) =
seed = (Random.self_init (); Random.int 1073741823); seed = (Random.self_init (); Random.int 1073741823);
ifi = false; ifi = false;
gen_lutin = false; gen_lutin = false;
_args = []; _args = [];
_user_man = []; _user_man = [];
_hidden_man = []; _hidden_man = [];
_others = []; _others = [];
_margin =12; _margin =12;
} }
let (args : t) = make_args ()
let pspec os (c, ml) = ( let pspec args os (c, ml) = (
let (m1, oth) = match ml with let (m1, oth) = match ml with
| h::t -> (h,t) | h::t -> (h,t)
| _ -> ("",[]) | _ -> ("",[])
...@@ -62,13 +61,13 @@ let pspec os (c, ml) = ( ...@@ -62,13 +61,13 @@ let pspec os (c, ml) = (
Printf.fprintf os "\n" ; Printf.fprintf os "\n" ;
) )
let options oc = ( let options args oc = (
let l = List.rev args._user_man in let l = List.rev args._user_man in
List.iter (pspec oc) l List.iter (pspec args oc) l
) )
let more_options oc = ( let more_options args oc = (
let l = List.rev (args._hidden_man) in let l = List.rev (args._hidden_man) in
List.iter (pspec oc) l List.iter (pspec args oc) l
) )
let (mkopt : t -> string list -> ?hide:bool -> ?arg:string -> Arg.spec -> let (mkopt : t -> string list -> ?hide:bool -> ?arg:string -> Arg.spec ->
string list -> unit) = string list -> unit) =
...@@ -83,67 +82,66 @@ let (mkopt : t -> string list -> ?hide:bool -> ?arg:string -> Arg.spec -> ...@@ -83,67 +82,66 @@ let (mkopt : t -> string list -> ?hide:bool -> ?arg:string -> Arg.spec ->
let myexit i = exit i let myexit i = exit i
(*** User Options Tab **) (*** User Options Tab **)
let (mkoptab : t -> unit) = let (mkoptab : string array -> t -> unit) =
fun opt -> fun argv args ->
let _nl = "\n"^(String.make args._margin ' ') in
( (
mkopt opt ["--synchronous-demon";"-sd"] mkopt args ["--synchronous-demon";"-sd"]
(Arg.Unit(fun () -> args.demon <- Demon.Synchronous)) (Arg.Unit(fun () -> args.demon <- Demon.Synchronous))
["Use a Synchronous deamon"]; ["Use a Synchronous deamon"];
mkopt opt ["--central-demon";"-cd"] mkopt args ["--central-demon";"-cd"]
(Arg.Unit(fun () -> args.demon <- Demon.Central)) (Arg.Unit(fun () -> args.demon <- Demon.Central))
["Use a Central deamon (which selects exactly one action)"]; ["Use a Central deamon (which selects exactly one action)"];
mkopt opt ["--locally-central-demon";"-lcd"] mkopt args ["--locally-central-demon";"-lcd"]
(Arg.Unit(fun () -> args.demon <- Demon.LocallyCentral)) (Arg.Unit(fun () -> args.demon <- Demon.LocallyCentral))
["Use a Locally Central deamon (which never activates two neighbors"; ["Use a Locally Central deamon (which never activates two neighbors";
"actions in the same step)"]; "actions in the same step)"];
mkopt opt ["--distributed-demon";"-dd"] mkopt args ["--distributed-demon";"-dd"]
(Arg.Unit(fun () -> args.demon <- Demon.Distributed)) (Arg.Unit(fun () -> args.demon <- Demon.Distributed))
["Use a Distributed deamon (which select at least one action)"]; ["Use a Distributed deamon (which select at least one action)"];
mkopt opt ["--custom-demon";"-custd"] mkopt args ["--custom-demon";"-custd"]
(Arg.Unit(fun () -> args.demon <- Demon.Custom;args.rif <- true)) (Arg.Unit(fun () -> args.demon <- Demon.Custom;args.rif <- true))
["Use a Custom deamon (forces --rif)"]; ["Use a Custom deamon (forces --rif)"];
mkopt opt ["--rif";"-rif"] mkopt args ["--rif";"-rif"]
(Arg.Unit(fun () -> args.rif <- true)) (Arg.Unit(fun () -> args.rif <- true))
["Follows RIF conventions"]; ["Follows RIF conventions"];
mkopt opt ["--seed";"-seed"] mkopt args ["--seed";"-seed"]
(Arg.Int(fun i -> args.seed <- i)) (Arg.Int(fun i -> args.seed <- i))
["Set the pseudo-random generator seed of build-in demons"]; ["Set the pseudo-random generator seed of build-in demons"];
mkopt opt ~hide:true ["--gen-lutin-demon";"-gld"] mkopt args ~hide:true ["--gen-lutin-demon";"-gld"]
(Arg.Unit(fun () -> args.gen_lutin <- true)) (Arg.Unit(fun () -> args.gen_lutin <- true))
["Generate Lutin demons and exit"]; ["Generate Lutin demons and exit"];
mkopt opt ~hide:true ["--ignore-first-inputs"; "-ifi"] mkopt args ~hide:true ["--ignore-first-inputs"; "-ifi"]
(Arg.Unit(fun () -> args.ifi <- true)) (Arg.Unit(fun () -> args.ifi <- true))
["Ignore first inputs (necessary to use luciole via lurette/rdbg/luciole-rif)"]; ["Ignore first inputs (necessary to use luciole via lurette/rdbg/luciole-rif)"];
mkopt opt ["--length";"-l"] ~arg:" <int>" mkopt args ["--length";"-l"] ~arg:" <int>"
(Arg.Int (fun i -> args.length <- i)) (Arg.Int (fun i -> args.length <- i))
["Maximum number of steps to be done (" ^ (string_of_int args.length) ^ " by default).\n"]; ["Maximum number of steps to be done (" ^ (string_of_int args.length) ^ " by default).\n"];
mkopt opt ~hide:true ["--version";"-version";"-v"] mkopt args ~hide:true ["--version";"-version";"-v"]
(Arg.Unit (fun _ -> (Arg.Unit (fun _ ->
(print_string (SasaVersion.str^"-"^SasaVersion.sha^"\n");flush stdout;exit 0))) (print_string (SasaVersion.str^"-"^SasaVersion.sha^"\n");flush stdout;exit 0)))
["Display the sasa version and exit."]; ["Display the sasa version and exit."];
mkopt opt ~hide:true ["--ocaml-version"] mkopt args ~hide:true ["--ocaml-version"]
(Arg.Unit (fun _ -> (print_string (Sys.ocaml_version^"\n"); flush stdout; exit 0))) (Arg.Unit (fun _ -> (print_string (Sys.ocaml_version^"\n"); flush stdout; exit 0)))
["Display the version ocaml version sasa was compiled with and exit."]; ["Display the version ocaml version sasa was compiled with and exit."];
mkopt opt ["--verbose";"-vl"] ~arg:" <int>" mkopt args ["--verbose";"-vl"] ~arg:" <int>"
(Arg.Int (fun i -> args.verbose <- i)) ["Set the verbose level"]; (Arg.Int (fun i -> args.verbose <- i)) ["Set the verbose level"];
mkopt opt ["--help";"-help"; "-h"] mkopt args ["--help";"-help"; "-h"]
(Arg.Unit (fun _ -> print_usage();options stdout; exit 0)) (Arg.Unit (fun _ -> print_usage (argv.(0)); options args stdout; exit 0))
["Display main options"]; ["Display main options"];
mkopt opt ["--more";"-m"] (Arg.Unit (fun () -> more_options stdout; exit 0)) mkopt args ["--more";"-m"] (Arg.Unit (fun () -> more_options args stdout; exit 0))
["Display more options"] ["Display more options"]
) )
...@@ -174,8 +172,9 @@ let unexpected s = ( ...@@ -174,8 +172,9 @@ let unexpected s = (
let parse argv = ( let parse argv = (
let save_current = !current in let save_current = !current in
try ( try (
mkoptab args; let args = make_args () in
Arg.parse_argv ~current:current argv args._args (add_other args) usage_msg; mkoptab argv args;
Arg.parse_argv ~current:current argv args._args (add_other args) (usage_msg argv.(0));
(List.iter (List.iter
(fun f -> (fun f ->
if (String.sub f 0 1 = "-") then if (String.sub f 0 1 = "-") then
...@@ -189,17 +188,17 @@ let parse argv = ( ...@@ -189,17 +188,17 @@ let parse argv = (
args.topo <- (match args._others with args.topo <- (match args._others with
[] -> [] ->
Printf.fprintf stderr "*** The topology file is missing in '%s'\n%s\n" Printf.fprintf stderr "*** The topology file is missing in '%s'\n%s\n"
(Sys.argv.(0)) usage_msg; (argv.(0)) (usage_msg argv.(0));
exit 2; exit 2;
| x::_ -> x | x::_ -> x
) );
args
) )
with with
(* only 1rst line is interesting ! *)
| Arg.Bad msg -> | Arg.Bad msg ->
Printf.fprintf stderr "*** Error when calling '%s': %s\n%s\n" (Sys.argv.(0)) Printf.fprintf stderr "*** Error when calling '%s': %s\n%s\n" (argv.(0))
(first_line msg) usage_msg; exit 2; (first_line msg) (usage_msg argv.(0)); exit 2;
| Arg.Help msg -> | Arg.Help msg ->
Printf.fprintf stdout "%s\n%s\n" msg usage_msg; Printf.fprintf stdout "%s\n%s\n" msg (usage_msg argv.(0));
options stdout; exit 0 exit 0
) )
(* Time-stamp: <modified the 15/03/2019 (at 22:37) by Erwan> *)
type t = {
mutable topo: string;
mutable length: int;
mutable verbose: int;
mutable demon: Demon.t;
mutable rif: bool;
mutable seed: int;
mutable ifi: bool;
mutable gen_lutin: bool;
mutable _args : (string * Arg.spec * string) list;
mutable _user_man : (string * string list) list;
mutable _hidden_man: (string * string list) list;
mutable _others : string list;
mutable _margin : int;
}
val usage_msg : string -> string
val parse : string array -> t
(* Time-stamp: <modified the 15/03/2019 (at 17:28) by Erwan Jahier> *) (* Time-stamp: <modified the 17/03/2019 (at 11:50) by Erwan Jahier> *)
(* XXX Je pourrais utiliser Lwt pour rendre step non-bloquant, ce qui (* XXX Je pourrais utiliser Lwt pour rendre step non-bloquant, ce qui
permettrait d'accelerer la simu sur les machines qui ont plusieurs permettrait d'accelerer la simu sur les machines qui ont plusieurs
...@@ -62,13 +62,11 @@ let (to_algo_neighbor: Env.t -> Topology.neighbor -> Algo.neighbor) = ...@@ -62,13 +62,11 @@ let (to_algo_neighbor: Env.t -> Topology.neighbor -> Algo.neighbor) =
n_vars = n.Topology.n_vars n_vars = n.Topology.n_vars
} }
exception Silent of int let (print_step : int -> int -> SasArg.t -> Env.t -> Process.t list -> string ->
string -> unit) =
fun n i args e pl activate_val enable_val ->
let (print_step : int -> int -> Env.t -> Process.t list -> string -> string -> unit) = if args.rif then (
fun n i e pl activate_val enable_val -> if args.demon = Demon.Custom then (
if SasArg.args.rif then (
if SasArg.args.demon = Demon.Custom then (
(* in custom mode, to be able to talk with lurette, this should not be (* in custom mode, to be able to talk with lurette, this should not be
printed on stdout printed on stdout
*) *)
...@@ -86,12 +84,14 @@ let (print_step : int -> int -> Env.t -> Process.t list -> string -> string -> u ...@@ -86,12 +84,14 @@ let (print_step : int -> int -> Env.t -> Process.t list -> string -> string -> u
(string_of_int (n-i+1)) (StringOf.env e pl) activate_val; (string_of_int (n-i+1)) (StringOf.env e pl) activate_val;
flush stderr flush stderr
) )
let rec (simu: int -> int -> Process.t list -> string -> exception Silent of int
(Process.t * Topology.neighbor list) list -> Env.t -> unit) =
fun n i pl activate_val pl_n e -> let (simustep: int -> int -> SasArg.t -> Process.t list -> string ->
(Process.t * Topology.neighbor list) list -> Env.t -> Env.t * string) =
fun n i args pl activate_val pl_n e ->
let custom = args.demon = Demon.Custom in let custom = args.demon = Demon.Custom in
(* 1: Get enable processes *)
let all = List.fold_left let all = List.fold_left
(fun acc (p,nl) -> (fun acc (p,nl) ->
let nl4algo = List.map (to_algo_neighbor e) nl in let nl4algo = List.map (to_algo_neighbor e) nl in
...@@ -117,15 +117,14 @@ let rec (simu: int -> int -> Process.t list -> string -> ...@@ -117,15 +117,14 @@ let rec (simu: int -> int -> Process.t list -> string ->
(List.flatten enab_ll)) (List.flatten enab_ll))
in in
if (List.flatten all = []) then ( if (List.flatten all = []) then (
print_step n i e pl activate_val enable_val; print_step n i args e pl activate_val enable_val;
raise (Silent (n-i+1)) raise (Silent (n-i+1))
); );
print_step n i e pl activate_val enable_val; print_step n i args e pl activate_val enable_val;
let next_activate_val, pnal = let next_activate_val, pnal =
Demon.f (SasArg.args.verbose > 1) args.demon pl all enab_ll Demon.f (args.verbose > 1) args.demon pl all enab_ll
in in
(* 2: Do the steps *)
(* Do the steps *)
let lenv_list = let lenv_list =
List.map (fun (p,nl,a) -> List.map (fun (p,nl,a) ->
let nl4algo = List.map (to_algo_neighbor e) nl in let nl4algo = List.map (to_algo_neighbor e) nl in
...@@ -133,33 +132,35 @@ let rec (simu: int -> int -> Process.t list -> string -> ...@@ -133,33 +132,35 @@ let rec (simu: int -> int -> Process.t list -> string ->
p, p.step nl4algo lenv a) p, p.step nl4algo lenv a)
pnal pnal
in in
(* update the env *) (* 3: update the env *)
let ne = List.fold_left update_env e lenv_list in let ne = List.fold_left update_env e lenv_list in
ne, next_activate_val
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; type t = SasArg.t * Process.t list * (Process.t * Topology.neighbor list) list * Env.t
with
Failure(e) -> let (make : string array -> t) =
output_string stdout e; fun argv ->
flush stdout ; let args =
exit 2 try SasArg.parse argv;
| e -> with
output_string stdout (Printexc.to_string e); Failure(e) ->
flush stdout; output_string stdout e;
exit 2 flush stdout ;
); exit 2
let dot_file = SasArg.args.topo in | e ->
let nl = Topology.read dot_file in output_string stdout (Printexc.to_string e);
let nstrl = List.map (fun n -> n.Topology.id) nl in flush stdout;
let nstr = String.concat "," nstrl in exit 2
try in
Algo.verbose_level := SasArg.args.verbose; try
Random.init SasArg.args.seed; let dot_file = args.topo in
let nl = Topology.read dot_file in
let nstrl = List.map (fun n -> n.Topology.id) nl in
let nstr = String.concat "," nstrl in
Algo.verbose_level := args.verbose;
Random.init args.seed;
if !Algo.verbose_level > 0 then Printf.eprintf "nodes: %s\nedges:\n" nstr; if !Algo.verbose_level > 0 then Printf.eprintf "nodes: %s\nedges:\n" nstr;
let e = Env.init () in let e = Env.init () in
let pl = List.map (Process.make (args.demon=Custom)) nl in let pl = List.map (Process.make (args.demon=Custom)) nl in
...@@ -168,23 +169,22 @@ let () = ...@@ -168,23 +169,22 @@ let () =
let e = update_env_with_init e pl algo_neighors in let e = update_env_with_init e pl algo_neighors in
let pl_n = List.combine pl neighors in let pl_n = List.combine pl neighors in
if !Algo.verbose_level > 0 then List.iter dump_process pl_n; if !Algo.verbose_level > 0 then List.iter dump_process pl_n;
if SasArg.args.gen_lutin then ( if args.gen_lutin then (
let fn = (Filename.remove_extension SasArg.args.topo) ^ ".lut" in let fn = (Filename.remove_extension args.topo) ^ ".lut" in
if Sys.file_exists fn then ( if Sys.file_exists fn then (
Printf.eprintf "%s already exists.\n" fn; flush stderr Printf.eprintf "%s already exists.\n" fn; flush stderr
) else ) else
let oc = open_out fn in let oc = open_out fn in
Printf.fprintf oc "%s" (GenLutin.f pl); Printf.fprintf oc "%s" (GenLutin.f pl);
flush oc; flush oc;
close_out oc; close_out oc;
exit 0); exit 0);
let n = SasArg.args.length in if args.rif then (
if SasArg.args.rif then (
Printf.printf "%s" (Mypervasives.entete "#" SasaVersion.str SasaVersion.sha); Printf.printf "%s" (Mypervasives.entete "#" SasaVersion.str SasaVersion.sha);
if SasArg.args.demon <> Demon.Custom then if args.demon <> Demon.Custom then
Printf.printf "#seed %i\n" SasArg.args.seed; Printf.printf "#seed %i\n" args.seed;
Printf.printf "#inputs %s\n" Printf.printf "#inputs %s\n"
(if SasArg.args.demon = Demon.Custom then ( (if args.demon = Demon.Custom then (
let f p = List.map let f p = List.map
(fun a -> "\""^p.pid ^(if a="" then "" else "_")^a^ "\":bool") (fun a -> "\""^p.pid ^(if a="" then "" else "_")^a^ "\":bool")
p.actions p.actions
...@@ -194,26 +194,21 @@ let () = ...@@ -194,26 +194,21 @@ let () =
Printf.printf "#outputs %s\n" (StringOf.env_rif_decl pl); Printf.printf "#outputs %s\n" (StringOf.env_rif_decl pl);
flush stdout flush stdout
) else ( ) else (
if SasArg.args.demon <> Demon.Custom then ( if args.demon <> Demon.Custom then (
Printf.printf "The pseudo-random engine is used with seed %i\n" SasArg.args.seed; Printf.printf "The pseudo-random engine is used with seed %i\n" args.seed;
flush stdout flush stdout
); );
); );
if SasArg.args.ifi then ( if args.ifi then (
List.iter List.iter
(fun p -> List.iter (fun p -> List.iter
(fun a -> ignore (RifRead.bool (args.verbose > 1) p a)) p.actions) (fun a -> ignore (RifRead.bool (args.verbose > 1) p a)) p.actions)
pl; pl;
Printf.eprintf "Ignoring the first vectors of sasa inputs\n"; flush stderr; Printf.eprintf "Ignoring the first vectors of sasa inputs\n"; flush stderr;
); );
simu n n pl "" pl_n e args, pl, pl_n, e
with with
| Dynlink.Error e -> Printf.printf "Error: %s\n" (Dynlink.error_message e) | Dynlink.Error e ->
| Failure msg -> Printf.printf "Error: %s\n" msg Printf.printf "Error: %s\n" (Dynlink.error_message e); flush stdout;
| Silent i -> exit 2
let str = if SasArg.args.rif then "#" else "" in
Printf.printf "%sThis algo is silent after %i steps\n" str i ;
flush stdout;
if SasArg.args.rif && args.demon = Custom then (
print_string "q\n"; flush stdout
)
;; Time-stamp: <modified the 15/03/2019 (at 16:03) by Erwan Jahier> ;; Time-stamp: <modified the 17/03/2019 (at 11:34) by Erwan Jahier>
(library (library
(name sasalib) (name sasalib)
(public_name sasalib) (public_name sasalib)
(libraries dynlink ocamlgraph rdbg-plugin algo sasacore) (libraries dynlink ocamlgraph rdbg-plugin algo sasacore lutils)
(synopsis "The Sasa rdbg plugin") (synopsis "The Sasa rdbg plugin")
) )
......
;; Time-stamp: <modified the 15/03/2019 (at 16:04) by Erwan Jahier> ;; Time-stamp: <modified the 15/03/2019 (at 23:07) by Erwan>
(executable (executable
(name sasa) (name sasaMain)
(libraries dynlink ocamlgraph lutils sasacore algo) (libraries dynlink ocamlgraph lutils sasacore algo)
) )
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
(install (install
(section bin) (section bin)
(files (sasa.exe as sasa)) (files (sasaMain.exe as sasa))
; (files sasaRun.cmxa) ; (files sasaRun.cmxa)
) )
open Sasacore
open Sasa
let rec (simuloop: int -> int -> SasArg.t -> Process.t list -> string ->
(Process.t * Topology.neighbor list) list -> Env.t -> unit) =
fun n i args pl activate_val pl_n e ->
let ne, next_activate_val = simustep n i args pl activate_val pl_n e in
if i > 0 then simuloop n (i-1) args pl next_activate_val pl_n ne else (
if args.rif then (
print_string "q\n"; flush stdout
))
let () =
let args, pl, pl_n, e = Sasa.make Sys.argv in
try
let n = args.length in
simuloop n n args pl "" pl_n e
with
| Failure msg -> Printf.printf "Error: %s\n" msg
| Silent i ->
let str = if args.rif then "#" else "" in
Printf.printf "%sThis algo is silent after %i steps\n" str i ;
flush stdout;
if args.rif && args.demon = Custom then (
print_string "q\n"; flush stdout
)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment