-
Notifications
You must be signed in to change notification settings - Fork 55
/
espsite.py
68 lines (60 loc) · 2.88 KB
/
espsite.py
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# cluster-dependent definitions
# espresso.py will make use of all "self" variables in config class
import os
class config:
def __init__(self):
self.scratch = os.path.dirname(os.getenv('LOCAL_SCRATCH'))
u = os.getenv('USER')
if self.scratch.find(u)<0:
self.scratch = os.path.join(self.scratch,u)
if not os.path.exists(self.scratch):
self.scratch = '/tmp'
self.submitdir = os.getenv('SLURM_SUBMIT_DIR')
self.batch = self.submitdir!=None
#we typically run batch jobs without openmp threads here
if self.batch:
os.putenv('OMP_NUM_THREADS','1')
#check for batch
if self.batch:
#f = open('/home/vossj/suncat/specialpartitionsonly.txt', 'r')
#usernames = [x.strip() for x in f.readlines()]
usernames = []
#f.close()
if os.getenv('USER') in usernames:
try:
partition = os.getenv('SLURM_JOB_PARTITION')
except:
partition = ''
if not (partition in ('iric',)):
import sys
print >>sys.stderr, 'Please use the iric partition for your jobs by specifying\n-p iric when submitting your jobs.'
sys.exit(1)
self.jobid = os.getenv('SLURM_JOBID')
nodefile = self.submitdir+'/nodefile.'+self.jobid
uniqnodefile = self.submitdir+'/uniqnodefile.'+self.jobid
os.system('scontrol show hostnames $SLURM_JOB_NODELIST >'+uniqnodefile)
taskspernode = os.getenv('SLURM_TASKS_PER_NODE')
xtaskspernode = taskspernode.find('(')
if xtaskspernode > -1:
taskspernode = taskspernode[:xtaskspernode]
os.system("awk '{for(i=0;i<"+taskspernode+";i++)print}' "+uniqnodefile+" >"+nodefile)
f = open(nodefile, 'r')
procs = [x.strip() for x in f.readlines()]
f.close()
self.procs = procs
nprocs = len(procs)
self.nprocs = nprocs
p = os.popen('wc -l <'+uniqnodefile, 'r')
nnodes = p.readline().strip()
p.close()
self.perHostMpiExec = 'mpiexec -machinefile '+uniqnodefile+' -np '+nnodes
self.perProcMpiExec = 'mpiexec -machinefile '+nodefile+' -np '+str(nprocs)+' -wdir %s %s'
self.perSpecProcMpiExec = 'mpiexec -machinefile %s -np %d -wdir %s %s'
def do_perProcMpiExec(self, workdir, program):
return os.popen2(self.perProcMpiExec % (workdir, program))
def do_perProcMpiExec_outputonly(self, workdir, program):
return os.popen(self.perProcMpiExec % (workdir, program), 'r')
def runonly_perProcMpiExec(self, workdir, program):
os.system(self.perProcMpiExec % (workdir, program))
def do_perSpecProcMpiExec(self, machinefile, nproc, workdir, program):
return os.popen3(self.perSpecProcMpiExec % (machinefile, nproc, workdir, program))