66
77import parsl
88from parsl .dataflow .dflow import DataFlowKernel
9+ from parsl .errors import InternalConsistencyError
910
1011min_iterations = 2
1112
@@ -40,19 +41,18 @@ def app(extra_payload: Any, parsl_resource_specification: Dict = {}) -> int:
4041 return 7
4142
4243
43- def performance (* , resources : dict , target_t : float , args_extra_size : int ) -> None :
44+ def performance (* , resources : dict , target_t : float , args_extra_size : int , iterate_mode : str ) -> None :
4445 n = 10
4546
4647 delta_t : float
47- delta_t = 0
48-
49- threshold_t = int (0.75 * target_t )
5048
5149 iteration = 1
5250
5351 args_extra_payload = "x" * args_extra_size
5452
55- while delta_t < threshold_t or iteration <= min_iterations :
53+ iterate = True
54+
55+ while iterate :
5656 print (f"==== Iteration { iteration } ====" )
5757 print (f"Will run { n } tasks to target { target_t } seconds runtime" )
5858 start_t = time .time ()
@@ -78,10 +78,20 @@ def performance(*, resources: dict, target_t: float, args_extra_size: int) -> No
7878 print (f"Runtime: actual { delta_t :.3f} s vs target { target_t } s" )
7979 print (f"Tasks per second: { rate :.3f} " )
8080
81- n = max (1 , int (target_t * rate ))
82-
8381 iteration += 1
8482
83+ # decide upon next iteration
84+
85+ match iterate_mode :
86+ case "estimate" :
87+ n = max (1 , int (target_t * rate ))
88+ iterate = delta_t < (0.75 * target_t ) or iteration <= min_iterations
89+ case "exponential" :
90+ n = int (n * 2 )
91+ iterate = delta_t < target_t or iteration <= min_iterations
92+ case _:
93+ raise InternalConsistencyError (f"Bad iterate mode { iterate_mode } - should have been validated at arg parse time" )
94+
8595
8696def cli_run () -> None :
8797 parser = argparse .ArgumentParser (
@@ -96,6 +106,12 @@ def cli_run() -> None:
96106 parser .add_argument ("--time" , metavar = "SECONDS" , help = "target number of seconds for an iteration" , default = 120 , type = float )
97107 parser .add_argument ("--argsize" , metavar = "BYTES" , help = "extra bytes to add into app invocation arguments" , default = 0 , type = int )
98108 parser .add_argument ("--version" , action = "version" , version = f"parsl-perf from Parsl { parsl .__version__ } " )
109+ parser .add_argument ("--iterate" ,
110+ metavar = "MODE" ,
111+ help = "Iteration mode: estimate, exponential" ,
112+ type = str ,
113+ default = "estimate" ,
114+ choices = ("estimate" , "exponential" ))
99115
100116 args = parser .parse_args ()
101117
@@ -105,7 +121,7 @@ def cli_run() -> None:
105121 resources = {}
106122
107123 with load_dfk_from_config (args .config ):
108- performance (resources = resources , target_t = args .time , args_extra_size = args .argsize )
124+ performance (resources = resources , target_t = args .time , args_extra_size = args .argsize , iterate_mode = args . iterate )
109125 print ("Tests complete - leaving DFK block" )
110126 print ("The end" )
111127
0 commit comments