11#!/usr/bin/env python3
22
33def cli ():
4- import os ,sys , argparse
4+ import os ,argparse
55 cli = argparse .ArgumentParser (description = 'CLARA scaling test' )
6- cli .add_argument ('-y' ,help = 'YAML file' ,required = True )
7- cli .add_argument ('-c' ,help = 'CLARA_HOME path (default=$CLARA_HOME)' ,default = os .getenv ('CLARA_HOME' ,None ))
8- cli .add_argument ('-t' ,help = 'threads (default=4,8)' ,default = '4,8' )
9- cli .add_argument ('-e' ,help = 'events per thread (default=555)' ,default = 555 ,type = int )
10- cli .add_argument ('-i' , help = 'input data file' , required = True )
11- cli .add_argument ('-N' , help = 'NUMA socket' , default = - 1 , type = int , choices = [ 0 , 1 ] )
6+ cli .add_argument ('-y' ,'--yaml' , metavar = 'YAML' , help = 'path to YAML file' ,required = True )
7+ cli .add_argument ('-c' ,'--clara' , metavar = 'DIR' , help = 'CLARA_HOME path (default=$CLARA_HOME)' ,default = os .getenv ('CLARA_HOME' ,None ))
8+ cli .add_argument ('-t' ,'--threads' , metavar = '#' , help = 'threads (default=4,8)' ,default = '4,8' )
9+ cli .add_argument ('-e' ,'--events' , metavar = '#' , help = 'events per thread (default=555)' ,default = 555 ,type = int )
10+ cli .add_argument ('-N' , '--numa' , metavar = '#' , help = 'NUMA socket (default=None, choices=[0,1])' , default = None , type = int , choices = [ 0 , 1 ] )
11+ cli .add_argument ('datafile' , help = 'input EVIO/HIPO data file' )
1212 cfg = cli .parse_args ()
13- cfg .t = cfg .t .split (',' )
14- if cfg .c is None :
15- sys .exit ('ERROR: cannot find CLARA installation, -c or $CLARA_HOME required.' )
16- if cfg .N >= 0 and not shutil .which ('numactl' ):
17- sys .exit ('ERROR: numactl is not in $PATH, -N option not supported.' )
13+ cfg .threads = cfg .threads .split (',' )
14+ cfg .run_clara = find_run_clara (cfg .clara )
15+ import sys ,shutil
16+ if not cfg .clara :
17+ sys .exit ('ERROR: cannot find CLARA installation, -c or $CLARA_HOME required' )
18+ if not cfg .run_clara :
19+ sys .exit ('ERROR: Cannot find run-clara in $PATH or CLARA installation' )
20+ if cfg .numa is not None :
21+ if not shutil .which ('numactl' ):
22+ sys .exit ('ERROR: numactl is not in $PATH, -N option not supported' )
23+ if len (list (get_numa_cpus (cfg .numa ))) == 0 :
24+ sys .exit ('ERROR: invalid NUMA node: {cfg.numa}' )
25+ cfg .numa = ',' .join (list (get_numa_cpus (cfg .numa )))
1826 return cfg
1927
28+ def find_run_clara (clara_home ):
29+ import os ,shutil
30+ if shutil .which ('run-clara' ):
31+ return shutil .which ('run-clara' )
32+ elif os .path .exists (clara_home + '/plugins/clas12/bin/run-clara' ):
33+ return clara_home + '/plugins/clas12/bin/run-clara'
34+
35+ def get_numa_cpus (node ):
36+ for line in run (['numactl' ,'-H' ]):
37+ if line .startswith (f'node { node } cpus:' ):
38+ for col in line .strip ().split ()[3 :]:
39+ yield col
40+
2041def run (cmd ):
2142 import subprocess
2243 print ('run >>> ' + ' ' .join (cmd ))
@@ -29,36 +50,21 @@ def run(cmd):
2950 if p .returncode != 0 :
3051 pass
3152
32- def find_run_clara (clara_home ):
33- import os ,sys ,shutil
34- if shutil .which ('run-clara' )
35- return shutil .which ('run-clara' )
36- elif os .path .exists (clara_home + '/plugins/clas12/bin/run-clara' ):
37- return clara_home + '/plugins/clas12/bin/run-clara'
38- else :
39- sys .exit ('ERROR: Cannot find run-clara in $PATH or CLARA installation.' )
40-
41- def get_numa_cpus (node ):
42- for line in run (['numactl' ,'-H' ]):
43- if line .startswith (f'node { node } cpus:' ):
44- for col in line .strip ().split ()[3 :]:
45- yield col
46-
4753def benchmark (cfg , threads , log ):
4854 import collections
4955 cmd = []
5056 # use taskset:
51- if cfg .N >= 0 :
52- cmd .extend (['taskset' ,'-c' ,',' . join ( get_numa_cpus ( cfg .N )) ])
57+ if cfg .numa is not None :
58+ cmd .extend (['taskset' ,'-c' ,cfg .numa ])
5359 # add the run-clara command:
54- cmd .extend ([find_run_clara ( cfg .c ) ,
55- '-c' ,cfg .c ,
56- '-n' ,str (cfg .e * int (threads )),
60+ cmd .extend ([cfg .run_clara ,
61+ '-c' ,cfg .clara ,
62+ '-n' ,str (cfg .events * int (threads )),
5763 '-t' ,str (threads ),
5864 '-l' ,
59- '-y' ,cfg .y ,
65+ '-y' ,cfg .yaml ,
6066 '-o' ,f'tmp-scaling-{ threads } ' ,
61- cfg .i ])
67+ cfg .datafile ])
6268 exiting ,benchmarks = False ,collections .OrderedDict ()
6369 for line in run (cmd ):
6470 cols = line .split ()
@@ -122,7 +128,7 @@ if __name__ == '__main__':
122128 cfg = cli ()
123129 import os
124130 benchmarks = []
125- for threads in cfg .t :
131+ for threads in cfg .threads :
126132 os .makedirs ('tmp-scaling-' + threads )
127133 with open (f'tmp-scaling-{ threads } /run-clara.log' ,'w' ) as log :
128134 benchmarks .append ([threads , benchmark (cfg , threads , log )])
0 commit comments