7 Usage: %s [options] <num dect and src> <num sink> <qsize> <run#>\n\
9 %s 4 4 --nodes=grunt{1-5} --ddnodes=1 # 1 node sending to 4\n\
10 %s 4 4 --nodes=grunt{1-5} --ddnodes=4 # 4 nodes sending to 1\n\
11 %s 5 5 --nodes=grunt{1-5} --ddnodes=0 # \n\
12 %s 5 5 --nodes=grunt{1-5} # same as above\
13 "%((os.path.basename(sys.argv[0]),)*6)
21 if sys.version_info[0] == 2: exec(
'trc_one=1L' )
22 else: exec(
'trc_one=1' )
25 def TRACE( lvl, fmt_s, *args ):
29 if g_opt[
'tlvlmsk'] & (trc_one<<lvl):
30 if g_thisnode ==
None: g_thisnode=NodeInfo()
31 fo = open(
"%s.%s.trc"%(g_thisnode.hostnames_l[0],os.getenv(
'RGANG_MACH_ID')),
"a+" )
33 os.write( fd,
'%.2f:%s:%s:%d:%s\n'%(time.time(),socket.gethostname(),
34 g_thisnode.mach_idx,lvl,fmt_s%args))
52 if reg_ex: self.
compiled = self.re.compile(reg_ex,flags)
57 if string: self.
match_obj = self.re.search(arg1, string)
58 else: self.
match_obj = self.compiled.search( arg1 )
62 re_numeric =
Re(
r"([0-9a-f]+)-((0x{0,1}){0,1}[0-9a-f]+)" )
63 re_1alpha =
Re(
r"([a-zA-Z])-([a-zA-Z])" )
64 re_hex =
Re(
r"^[0-9a-f]+" )
68 def findall_expands( ss ):
69 result = []; result_idx = 0; brace_lvl = 0
72 brace_lvl = brace_lvl + 1
73 if brace_lvl == 1: result.append(
'')
74 if brace_lvl > 0: result[result_idx] = result[result_idx] + cc
76 brace_lvl = brace_lvl - 1
77 if brace_lvl == 0: result_idx = result_idx + 1
78 if brace_lvl != 0: result.pop()
83 def numeric_expand( ss_l ):
88 if re_1alpha.search( sss ):
89 start = re_1alpha.match_obj.group(1)
90 end = re_1alpha.match_obj.group(2)
94 start = chr(ord(start)+1)
95 elif re_numeric.search( sss ):
96 start = re_numeric.match_obj.group(1)
97 end = re_numeric.match_obj.group(2)
98 bb = re_numeric.match_obj.group(3)
100 for num
in range(int(start),eval(end)+1):
101 ret.append(
'%0*d'%(len(start),num) )
103 for num
in range(eval(
'0%s'%(start,)),eval(end)+1):
104 ret.append(
'%0*o'%(len(start),num) )
106 for num
in range(eval(
'0x%s'%(start,)),eval(end)+1):
107 ret.append(
'%0*x'%(len(start),num) )
108 else: ret.append( sss )
109 TRACE( 28,
'numeric_expand returning %s', ret )
116 TRACE( 29,
'expand(%s)', ss )
120 expands = findall_expands( ss )
121 if not expands:
return ss.split(
',')
124 ss = ss.replace( exp,
'<%d>'%(placeholder_idx,), 1 )
125 placeholder_idx = placeholder_idx + 1
127 for sss
in ss.split(
','):
128 TRACE( 30,
'expand sss=%s of ss=%s', sss, ss )
129 place_holders = re.findall(
'<[0-9]+>', sss )
130 for idx
in range(len(place_holders)):
131 p_holder =
'<%d>'%(placeholder_idx+idx,)
132 expanding = expand( expands[placeholder_idx+idx][1:-1] )
133 expanding = numeric_expand( expanding )
135 for ssss
in sss.split(
','):
136 holder_idx = ssss.find(p_holder)
138 pre = ssss[:holder_idx]
139 post= ssss[holder_idx+len(p_holder):]
140 for expanded
in expanding:
141 result.append( pre+expanded+post )
142 sss =
','.join(result)
143 exp_result = exp_result + sss.split(
',')
144 placeholder_idx = placeholder_idx + len(place_holders)
146 TRACE( 31,
'except - expand' )
147 exc, value, tb = sys.exc_info()
148 sys.stderr.write(
'Error expanding node list "%s": %s: %s\n'%(ssIn,exc,value) )
149 sys.stderr.write(
'Prehaps an invalid decimal/octal/hex digit\n' )
150 sys.stderr.write(
'remember: in the \'{seq1-seq2}\' syntax, seq2\n' )
151 sys.stderr.write(
'can begin with \'0x\' to force hex or \'0\' to\n' )
152 sys.stderr.write(
'force octal\n' )
154 for ln
in traceback.format_exception( exc, value, tb ):
162 def build_quoted_str( args ):
166 if repr(arg)[0] ==
"'": quoted_args.append(
"'%s'"%(arg,) )
167 else: quoted_args.append(
'"%s"'%(arg,) )
168 return ' '.join( quoted_args )
176 if sys.argv.count(
'--'):
177 art_args = build_quoted_str( sys.argv[sys.argv.index(
'--' ) + 1:] )
179 long_opt_spec=[
"help",
"ddnodes=",
"nodes="]
181 opts, args = getopt.gnu_getopt(sys.argv[1:],
"h", long_opt_spec)
182 except getopt.GetoptError, err:
190 if o
in (
"-h",
"--help"):
193 elif o
in (
"--ddnodes",):
195 elif o
in (
"--nodes",):
198 assert False,
"unhandled option"
201 if len(args) < 4: print(USAGE); sys.exit()
203 num_det = int( args[0],0 )
204 num_sink = int( args[1],0 )
206 builder=os.popen(
"which builder 2>/dev/null").readline()
208 print(
"Error: builder executable not found.")
212 print(
"opts=%s args=%s nodes=%s"%(opts,args,nodes))
215 if ddnodes >= len(nodes):
216 print(
"invalid configuration. ddnodes must be < nodes")
221 nodes_file=
"/tmp/nodes%s.txt"%(os.getpid(),)
222 fo=open(nodes_file,
'w')
226 for xx
in range(num_det):
227 fo.write(
"%s\n"%(nodes[node_idx],) ); node_idx += 1
228 if node_idx == len(nodes)
or node_idx == ddnodes: node_idx=0
230 if ddnodes: nodes=nodes[ddnodes:]
235 for xx
in range(num_sink):
236 fo.write(
"%s\n"%(nodes[node_idx],) ); node_idx += 1
237 if node_idx == len(nodes): node_idx=0
242 os.system(
"cat %s"%(nodes_file,))
245 cmd =
"mpirun_rsh -rsh -hostfile %s "%(nodes_file,)
246 cmd+=
"-n %d "%(num_det+num_sink,)
247 cmd+=
" FHICL_FILE_PATH=\"$FHICL_FILE_PATH\" "
249 if art_args: cmd+=
" %s"%(art_args,)
250 print(
"executing cmd: %s"%(cmd,) )
253 cmd =
"mpirun -n %d "%(num_det+num_sink,)
255 if art_args: cmd+=
" %s"%(art_args,)
256 print(
"executing cmd: %s"%(cmd,) )
257 rc = (os.system( cmd ) >> 8)
258 print "return status of %s is: %d\n" %(cmd, rc)
260 print "return status is (really!) : %d\n" %(rc,)
264 if __name__ ==
"__main__":
def search
Find matches for the regular expression.
match_obj
Match object representing all matches for the regex.
def __init__
Create an instance of the regular expression.
compiled
The compiled version of the regex.
General Regular Expression class that allows for: xx = Re( re ) ...