prologue.user 2.47 KB
Newer Older
Andrew McNab's avatar
Andrew McNab committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#!/usr/bin/python
#
#  prologue.user script for Machine/Job Features on Torque/PBS
#
#  Andrew McNab, University of Manchester.
#  Copyright (c) 2016. All rights reserved.
#
#  Redistribution and use in source and binary forms, with or
#  without modification, are permitted provided that the following
#  conditions are met:
#
#    o Redistributions of source code must retain the above
#      copyright notice, this list of conditions and the following
#      disclaimer. 
#    o Redistributions in binary form must reproduce the above
#      copyright notice, this list of conditions and the following
#      disclaimer in the documentation and/or other materials
#      provided with the distribution. 
#
#  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
#  CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
#  INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
#  DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
#  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
#  EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
#  TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
#  DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
#  ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
#  OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
#  OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
#  POSSIBILITY OF SUCH DAMAGE.
#

import os
Andrew McNab's avatar
Andrew McNab committed
36
import re
Andrew McNab's avatar
Andrew McNab committed
37
38
39
40
41
42
43
import sys
import time

#
# PROGRAM MAIN !!!
# 

Andrew McNab's avatar
Andrew McNab committed
44
45
46
47
48
49
50
51
52
53
54

homdeDir = os.path.expanduser('~')

job_id = os.environ['PBS_JOBID']

jobfeaturesDir = homeDir + '/jobfeatures-' + jobID

os.mkdir(jobfeaturesDir)

open(jobfeaturesDir + '/job_id', 'w').write(job_id)

Andrew McNab's avatar
Andrew McNab committed
55
try:
Andrew McNab's avatar
Andrew McNab committed
56
  allocated_cpu = int(os.environ['PBS_NUM_PPN'])
Andrew McNab's avatar
Andrew McNab committed
57
except:
Andrew McNab's avatar
Andrew McNab committed
58
  allocated_cpu = 1
Andrew McNab's avatar
Andrew McNab committed
59
  
Andrew McNab's avatar
Andrew McNab committed
60
61
open(jobfeaturesDir + '/job_id', 'w').write(str(allocated_cpu))

Andrew McNab's avatar
Andrew McNab committed
62
try:
Andrew McNab's avatar
Andrew McNab committed
63
  hs06 = float(open('/etc/machinefeatures/hs06','r').readline())
Andrew McNab's avatar
Andrew McNab committed
64
except:
Andrew McNab's avatar
Andrew McNab committed
65
  hs06 = None
Andrew McNab's avatar
Andrew McNab committed
66
67

try:
Andrew McNab's avatar
Andrew McNab committed
68
  total_cpu = int(open('/etc/machinefeatures/total_cpu','r').readline())
Andrew McNab's avatar
Andrew McNab committed
69
except:
Andrew McNab's avatar
Andrew McNab committed
70
  total_cpu = None
Andrew McNab's avatar
Andrew McNab committed
71
  
Andrew McNab's avatar
Andrew McNab committed
72
73
74
75
76
77
78
79
80
81
82
83
84
if hs06 and total_cpu:
  # Simple pro-rata allocation of total hs06 depending on processors for this job
  hs06_job = (allocated_cpu * hs06) / total_cpu
  open(jobfeaturesDir + '/hs06_job', 'w').write(str(hs06_job))

try: 
  qstatResult = os.popen('qstat -f ' + jobID,'r').read()
except:
  pass

jobstart_secs = int(time.time())
open(jobfeaturesDir + '/jobstart_secs', 'w').write(str(jobstart_secs))