-
Notifications
You must be signed in to change notification settings - Fork 9
/
crystalrunner.py
154 lines (132 loc) · 4.6 KB
/
crystalrunner.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
from __future__ import print_function
import os
import numpy as np
import subprocess as sub
import shutil
import submitter
from submitter import LocalSubmitter
####################################################
class LocalCrystalRunner(LocalSubmitter):
""" Runs a crystal job defined by CrystalWriter. """
_name_='LocalCrystalRunner'
def __init__(self, BIN='~/bin/'):
self.BIN=BIN
self.np=1
self.nn=1
self.jobname='ag_crystal'
self._queueid=None
#-------------------------------------------------
def check_status(self):
# This is only for a queue, so just never return 'running'.
return 'ok'
#-------------------------------------------------
def run(self,crysinpfn,crysoutfn):
""" Submits executibles using _qsub. """
exe = self.BIN+"crystal < %s"%crysinpfn
prep_commands=["cp %s INPUT"%crysinpfn]
# Not needed for nonparallel.
#final_commands = ["rm *.pe[0-9]","rm *.pe[0-9][0-9]"]
final_commands = []
loc = os.getcwd()
qids=self._qsub(exe,prep_commands,final_commands,self.jobname,crysoutfn,loc)
self._queueid=qids
####################################################
class CrystalRunnerPBS:
_name_='CrystalRunnerPBS'
def __init__(self,BIN='~/bin/',
queue='batch',
walltime='12:00:00',
np=1,
nn=1,
prefix="",#for example, load modules
postfix="rm fort.*.pe*"
):
self.BIN=BIN
self.np=np
self.nn=nn
self.jobname='CrystalRunnerPBS'
self.queue=queue
self.walltime=walltime
self.prefix=prefix
self.postfix=postfix
self.queueid=None
#-------------------------------------
def check_status(self):
return submitter.check_PBS_status(self.queueid)
#-------------------------------------
def run(self,crysinpfn,crysoutfn):
#just running in serial for now
#because I haven't gotten Pcrystal compiled for
#hawk yet.
exe=self.BIN+"Pcrystal"
jobout=crysinpfn+".jobout"
np_tot=self.np*self.nn
#"mpirun -np %i %s > %s\n"%(np_tot,exe,crysoutfn) +
qsub="#PBS -q %s \n"%self.queue +\
"#PBS -l nodes=%i:ppn=%i\n"%(self.nn,self.np) +\
"#PBS -l walltime=%s\n"%self.walltime +\
"#PBS -j oe \n" +\
"#PBS -N %s \n"%self.jobname +\
"#PBS -o %s \n"%jobout +\
self.prefix+"\n" +\
"cd ${PBS_O_WORKDIR}\n" +\
"cp %s INPUT\n"%(crysinpfn) +\
"mpirun -n %d %s > %s \n"%(self.nn*self.np,exe,crysoutfn) +\
self.postfix
qsubfile=crysinpfn+".qsub"
with open(qsubfile,'w') as f:
f.write(qsub)
result = sub.check_output("qsub %s"%(qsubfile),shell=True)
self.queueid = result.decode().split()[0]
print("Submitted as %s"%self.queueid)
####################################################
class CrystalRunnerVeritas:
_name_='CrystalRunnerPBS'
def __init__(self,BIN='~/bin/',
queue='batch',
walltime='12:00:00',
np=1,
nn=1,
prefix="",#for example, load modules
postfix="rm fort.*.pe*"
):
self.BIN=BIN
self.np=np
self.nn=nn
self.jobname='CrystalRunnerPBS'
self.queue=queue
self.walltime=walltime
self.prefix=prefix
self.postfix=postfix
self.queueid=None
#-------------------------------------
def check_status(self):
return submitter.check_PBS_status(self.queueid)
#-------------------------------------
def run(self,crysinpfn,crysoutfn):
#just running in serial for now
#because I haven't gotten Pcrystal compiled for
#hawk yet.
exe=self.BIN+"Pcrystal"
jobout=crysinpfn+".jobout"
np_tot=self.np*self.nn
#"mpirun -np %i %s > %s\n"%(np_tot,exe,crysoutfn) +
qsub="#PBS -q %s \n"%self.queue +\
"#PBS -l nodes=%i:ppn=%i\n"%(self.nn,self.np) +\
"#PBS -l walltime=%s\n"%self.walltime +\
"#PBS -j oe \n" +\
"#PBS -N %s \n"%self.jobname +\
"#PBS -o %s \n"%jobout +\
self.prefix+"\n" +\
"cd ${PBS_O_WORKDIR}\n" +\
". ~/bin/add_intel\n" +\
". ~/bin/add_ompi\n" +\
"cp %s INPUT\n"%(crysinpfn) +\
"/home/brian/programs/openmpi/openmpi-1.6.3/install/bin/mpirun -n %d %s &> %s \n"%(self.nn*self.np,exe,crysoutfn) +\
self.postfix
qsubfile=crysinpfn+".qsub"
with open(qsubfile,'w') as f:
f.write(qsub)
result = sub.check_output("qsub %s"%(qsubfile),shell=True)
self.queueid = result.decode().split()[0]
print("Submitted as %s"%self.queueid)