Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
verimag
synchrone
sasa
Commits
698a46ae
Commit
698a46ae
authored
May 20, 2021
by
erwan
Browse files
Chore: put all the seed handling in a dedicated module (so that I can use it in rdbgui)
parent
7b88e1cc
Changes
5
Hide whitespace changes
Inline
Side-by-side
lib/sasacore/sasArg.ml
View file @
698a46ae
(* Time-stamp: <modified the
0
2/0
4
/2021 (at
15:45
) by Erwan Jahier> *)
(* Time-stamp: <modified the 2
0
/0
5
/2021 (at
09:02
) by Erwan Jahier> *)
type
t
=
{
...
...
@@ -9,8 +9,6 @@ type t = {
mutable
rif
:
bool
;
mutable
no_data_file
:
bool
;
mutable
quiet
:
bool
;
mutable
seed
:
int
option
;
mutable
replay_seed
:
bool
;
mutable
ifi
:
bool
;
mutable
gen_lutin
:
bool
;
mutable
gen_oracle
:
bool
;
...
...
@@ -42,8 +40,6 @@ let (make_args : unit -> t) =
rif
=
false
;
no_data_file
=
false
;
quiet
=
false
;
seed
=
None
;
replay_seed
=
false
;
ifi
=
false
;
gen_lutin
=
false
;
gen_oracle
=
false
;
...
...
@@ -95,58 +91,6 @@ let (mkopt : t -> string list -> ?hide:bool -> ?arg:string -> Arg.spec ->
let
myexit
i
=
exit
i
(*******************************************************************************)
(* seeds stuff *)
let
seed_set
args
s
=
(
match
s
with
|
Some
i
->
if
args
.
verbose
>
0
then
Printf
.
fprintf
stderr
" [sasa] The sasa random engine seed is set to %i
\n
%!"
i
;
Random
.
init
i
;
flush
stderr
;
|
None
->
()
);
args
.
seed
<-
s
let
seed_file_name
args
=
Printf
.
sprintf
"sasa-%s.seed"
args
.
topo
(* for --replay *)
let
reset_the_seed_to_last
args
=
let
f
=
seed_file_name
args
in
try
let
ic
=
open_in
f
in
let
seed
=
int_of_string
(
input_line
ic
)
in
args
.
seed
<-
Some
seed
;
seed_set
args
(
Some
seed
);
Printf
.
eprintf
" [sasa] Replay the sasa run using the seed in %s
\n
"
f
;
flush
stderr
;
true
with
_
->
Printf
.
eprintf
" [sasa] W: cannot recover the seed in %s
\n
"
f
;
flush
stderr
;
false
let
rec
seed_get
args
=
match
args
.
seed
with
|
Some
i
->
i
|
None
->
(* No seed is set:
- in -replay mode, we first try to read the seed in the seed file
- otherwise, we create a random seed and save if into args, and
into a file for -replay *)
if
args
.
replay_seed
&&
reset_the_seed_to_last
args
then
(
seed_get
args
)
else
(
let
seed
=
Random
.
self_init
()
;
Random
.
int
1073741823
in
let
seed_file
=
seed_file_name
args
in
let
oc
=
open_out
seed_file
in
Printf
.
fprintf
oc
"%d
\n
%s
\n
"
seed
(
Mypervasives
.
entete
"#"
SasaVersion
.
str
SasaVersion
.
sha
);
flush
oc
;
close_out
oc
;
seed_set
args
(
Some
seed
);
seed
)
(*******************************************************************************)
(*** User Options Tab **)
let
(
mkoptab
:
string
array
->
t
->
unit
)
=
...
...
@@ -197,11 +141,11 @@ let (mkoptab : string array -> t -> unit) =
[
"Do not generate any data file"
];
mkopt
args
[
"--seed"
;
"-seed"
]
(
Arg
.
Int
(
fun
i
->
s
eed
_
set
args
(
Some
i
)
))
(
Arg
.
Int
(
fun
i
->
S
eed
.
set
i
))
[
"Set the pseudo-random generator seed of build-in daemons (wins over --replay)"
];
mkopt
args
[
"--replay"
;
"-replay"
]
(
Arg
.
Unit
(
fun
()
->
args
.
replay_seed
<-
true
))
(
Arg
.
Unit
(
fun
()
->
Seed
.
replay_seed
:=
true
))
[
"Use the last generated seed to replay the last run"
];
mkopt
args
~
hide
:
true
[
"--gen-lutin-daemon"
;
"-gld"
]
...
...
lib/sasacore/sasArg.mli
View file @
698a46ae
(* Time-stamp: <modified the 2
2
/0
1
/202
0
(at
1
0:02) by Erwan Jahier> *)
(* Time-stamp: <modified the 2
0
/0
5
/202
1
(at 0
9
:02) by Erwan Jahier> *)
type
t
=
{
mutable
topo
:
string
;
...
...
@@ -8,8 +8,6 @@ type t = {
mutable
rif
:
bool
;
mutable
no_data_file
:
bool
;
mutable
quiet
:
bool
;
mutable
seed
:
int
option
;
mutable
replay_seed
:
bool
;
mutable
ifi
:
bool
;
mutable
gen_lutin
:
bool
;
mutable
gen_oracle
:
bool
;
...
...
@@ -25,7 +23,6 @@ type t = {
mutable
_margin
:
int
;
}
val
seed_get
:
t
->
int
val
usage_msg
:
string
->
string
val
parse
:
string
array
->
t
lib/sasacore/seed.ml
0 → 100644
View file @
698a46ae
(* Time-stamp: <modified the 20/05/2021 (at 09:23) by Erwan Jahier> *)
let
seed
=
ref
None
let
replay_seed
=
ref
false
let
verbose
=
true
let
set
s
=
if
verbose
then
Printf
.
fprintf
stderr
" [sasa] The sasa random engine seed is set to %i
\n
%!"
s
;
Random
.
init
s
;
seed
:=
Some
s
let
seed_file_name
label
=
Printf
.
sprintf
"sasa-%s.seed"
label
(* for --replay *)
let
reset_the_seed_to_last
label
=
let
f
=
seed_file_name
label
in
try
let
ic
=
open_in
f
in
let
seed
=
int_of_string
(
input_line
ic
)
in
set
seed
;
Printf
.
eprintf
" [sasa] Replay the sasa run using the seed in %s
\n
"
f
;
flush
stderr
;
true
with
_
->
Printf
.
eprintf
" [sasa] W: cannot recover the seed in %s
\n
"
f
;
flush
stderr
;
false
let
rec
(
get
:
string
->
int
)
=
fun
label
->
match
!
seed
with
|
Some
i
->
i
|
None
->
(* No seed is set:
- in -replay mode, we first try to read the seed in the seed file
- otherwise, we create a random seed and save if into args, and
into a file for -replay *)
if
!
replay_seed
&&
reset_the_seed_to_last
label
then
(
get
label
)
else
(
let
seed
=
Random
.
self_init
()
;
Random
.
int
1073741823
in
let
seed_file
=
seed_file_name
label
in
let
oc
=
open_out
seed_file
in
Printf
.
fprintf
oc
"%d
\n
%s
\n
"
seed
(
Mypervasives
.
entete
"#"
SasaVersion
.
str
SasaVersion
.
sha
);
flush
oc
;
close_out
oc
;
set
seed
;
seed
)
lib/sasacore/seed.mli
0 → 100644
View file @
698a46ae
(* Time-stamp: <modified the 20/05/2021 (at 09:25) by Erwan Jahier> *)
val
set
:
int
->
unit
(** The string is used to create a file name to save/restore the seed
when the --replay option is used *)
val
get
:
string
->
int
val
replay_seed
:
bool
ref
lib/sasacore/simuState.ml
View file @
698a46ae
(* Time-stamp: <modified the 0
4
/05/2021 (at 0
8:36
) by Erwan Jahier> *)
(* Time-stamp: <modified the
2
0/05/2021 (at 0
9:09
) by Erwan Jahier> *)
open
Register
...
...
@@ -198,7 +198,7 @@ let (make : bool -> string array -> 'v t) =
flush
stdout
;
exit
2
in
let
seed
=
s
eed
_
get
args
in
let
seed
=
S
eed
.
get
args
.
topo
in
try
let
dynlink
=
if
args
.
output_algos
then
false
else
dynlink
in
let
dot_file
=
args
.
topo
in
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment