CMS 3D CMS Logo

MatrixRunner.py
Go to the documentation of this file.
1 from __future__ import print_function
2 import os, sys, time
3 
4 from Configuration.PyReleaseValidation.WorkFlow import WorkFlow
5 from Configuration.PyReleaseValidation.WorkFlowRunner import WorkFlowRunner
6 
7 # ================================================================================
8 
10 
11  def __init__(self, wfIn=None, nThrMax=4, nThreads=1):
12 
13  self.workFlows = wfIn
14 
15  self.threadList = []
16  self.maxThreads = nThrMax
17  self.nThreads = nThreads
18 
19  #the directories in which it happened
20  self.runDirs={}
21 
22  def activeThreads(self):
23 
24  nActive = 0
25  for t in self.threadList:
26  if t.is_alive() : nActive += 1
27 
28  return nActive
29 
30 
31  def runTests(self, opt):
32 
33  testList=opt.testList
34  dryRun=opt.dryRun
35  cafVeto=opt.cafVeto
36 
37  startDir = os.getcwd()
38 
39  report=''
40  noRun=(self.maxThreads==0)
41  if noRun:
42  print('Not running the wf, only creating cfgs and logs')
43  self.maxThreads=4
44  print('resetting to default number of process threads = %s' % self.maxThreads)
45 
46  print('Running %s %s %s, each with %s thread%s per process' % ('up to' if self.maxThreads > 1 else '', self.maxThreads, 'concurrent jobs' if self.maxThreads > 1 else 'job', self.nThreads, 's' if self.nThreads > 1 else ''))
47 
48 
49  for wf in self.workFlows:
50 
51  if testList and float(wf.numId) not in [float(x) for x in testList]: continue
52 
53  item = wf.nameId
54  if os.path.islink(item) : continue # ignore symlinks
55 
56  # make sure we don't run more than the allowed number of threads:
57  while self.activeThreads() >= self.maxThreads:
58  time.sleep(1)
59 
60  print('\nPreparing to run %s %s' % (wf.numId, item))
61  sys.stdout.flush()
62  current = WorkFlowRunner(wf,noRun,dryRun,cafVeto, opt.dasOptions, opt.jobReports, opt.nThreads, opt.nStreams, opt.maxSteps)
63  self.threadList.append(current)
64  current.start()
65  if not dryRun:
66  time.sleep(0.5) # try to avoid race cond by sleeping 0.5 sec
67 
68  # wait until all threads are finished
69  while self.activeThreads() > 0:
70  time.sleep(0.5)
71 
72 
73  #wrap up !
74  totpassed=[]
75  totfailed=[]
76  def count(collect,result):
77  #pad with zeros
78  for i in range(len(collect),len(result)):
79  collect.append(0)
80  for i,c in enumerate(result):
81  collect[i]+=c
82 
83  for pingle in self.threadList:
84  pingle.join()
85  try:
86  count(totpassed,pingle.npass)
87  count(totfailed,pingle.nfail)
88  report+=pingle.report
89  self.runDirs[pingle.wf.numId]=pingle.wfDir
90  except Exception as e:
91  msg = "ERROR retrieving info from thread: " + str(e)
92  report += msg
93 
94  report+=' '.join(map(str,totpassed))+' tests passed, '+' '.join(map(str,totfailed))+' failed\n'
95  print(report)
96  sys.stdout.flush()
97 
98  runall_report_name='runall-report-step123-.log'
99  runall_report=open(runall_report_name,'w')
100  runall_report.write(report)
101  runall_report.close()
102  os.chdir(startDir)
103 
104  anyFail=sum(totfailed)
105 
106  return anyFail
FastTimerService_cff.range
range
Definition: FastTimerService_cff.py:34
MatrixRunner.MatrixRunner.nThreads
nThreads
Definition: MatrixRunner.py:17
resolutioncreator_cfi.object
object
Definition: resolutioncreator_cfi.py:4
MatrixRunner.MatrixRunner.activeThreads
def activeThreads(self)
Definition: MatrixRunner.py:22
dqmMemoryStats.float
float
Definition: dqmMemoryStats.py:127
MatrixRunner.MatrixRunner.workFlows
workFlows
Definition: MatrixRunner.py:13
join
static std::string join(char **cmd)
Definition: RemoteFile.cc:17
MatrixRunner.MatrixRunner
Definition: MatrixRunner.py:9
WorkFlowRunner
Definition: WorkFlowRunner.py:1
str
#define str(s)
Definition: TestProcessor.cc:53
submitPVResolutionJobs.count
count
Definition: submitPVResolutionJobs.py:352
MatrixRunner.MatrixRunner.__init__
def __init__(self, wfIn=None, nThrMax=4, nThreads=1)
Definition: MatrixRunner.py:11
MatrixRunner.MatrixRunner.runDirs
runDirs
Definition: MatrixRunner.py:20
print
void print(TMatrixD &m, const char *label=nullptr, bool mathematicaFormat=false)
Definition: Utilities.cc:46
mps_setup.append
append
Definition: mps_setup.py:85
MatrixRunner.MatrixRunner.maxThreads
maxThreads
Definition: MatrixRunner.py:16
MatrixRunner.MatrixRunner.threadList
threadList
Definition: MatrixRunner.py:15
MatrixRunner.MatrixRunner.runTests
def runTests(self, opt)
Definition: MatrixRunner.py:31
genParticles_cff.map
map
Definition: genParticles_cff.py:11