source: issm/branches/trunk-larour-NatGeoScience2016/src/m/classes/clusters/vilje.py@ 21759

Last change on this file since 21759 was 21759, checked in by Eric.Larour, 8 years ago

CHG: merged branch back to trunk-jpl 21754.

File size: 5.5 KB
Line 
1import subprocess
2from fielddisplay import fielddisplay
3from pairoptions import pairoptions
4from issmssh import issmssh
5from issmscpin import issmscpin
6from issmscpout import issmscpout
7from QueueRequirements import QueueRequirements
8import datetime
9try:
10 from vilje_settings import vilje_settings
11except ImportError:
12 print 'You need vilje_settings.py to proceed, check presence and sys.path'
13
14class vilje(object):
15 """
16 Vilje cluster class definition
17
18 Usage:
19 cluster=vilje();
20 """
21
22 def __init__(self,*args):
23 # {{{
24 self.name = 'vilje'
25 self.login = ''
26 self.numnodes = 2
27 self.cpuspernode = 32
28 self.procspernodes = 16
29 self.mem = 28
30 self.queue = 'workq'
31 self.time = 2*60
32 self.codepath = ''
33 self.executionpath = ''
34 self.interactive = 0
35 self.port = []
36 self.accountname = ''
37
38 #use provided options to change fields
39 options=pairoptions(*args)
40
41 #initialize cluster using user settings if provided
42 self=vilje_settings(self)
43 #OK get other fields
44 self=options.AssignObjectFields(self)
45 self.np=self.numnodes*self.procspernodes
46 # }}}
47 def __repr__(self):
48 # {{{
49 # display the object
50 s = "class vilje object:"
51 s = "%s\n%s"%(s,fielddisplay(self,'name','name of the cluster'))
52 s = "%s\n%s"%(s,fielddisplay(self,'login','login'))
53 s = "%s\n%s"%(s,fielddisplay(self,'numnodes','number of nodes'))
54 s = "%s\n%s"%(s,fielddisplay(self,'cpuspernode','number of nodes per CPUs (32)'))
55 s = "%s\n%s"%(s,fielddisplay(self,'procspernodes','number of mpi procs per nodes'))
56 s = "%s\n%s"%(s,fielddisplay(self,'mem','node memory'))
57 s = "%s\n%s"%(s,fielddisplay(self,'queue','name of the queue (test is an option, workq the default)'))
58 s = "%s\n%s"%(s,fielddisplay(self,'time','walltime requested in minutes'))
59 s = "%s\n%s"%(s,fielddisplay(self,'codepath','code path on the cluster'))
60 s = "%s\n%s"%(s,fielddisplay(self,'executionpath','execution path on the cluster'))
61 s = "%s\n%s"%(s,fielddisplay(self,'interactive',''))
62 s = "%s\n%s"%(s,fielddisplay(self,'accountname','your cluster account'))
63 return s
64 # }}}
65 def checkconsistency(self,md,solution,analyses):
66 # {{{
67 #Queue dictionarry gives queu name as key and max walltime and cpus as var
68 queuedict = {'workq':[5*24*60, 30],
69 'test':[30,4]}
70 QueueRequirements(queuedict,self.queue,self.np,self.time)
71
72 #Miscelaneous
73 if not self.login:
74 md = md.checkmessage('login empty')
75 if not self.codepath:
76 md = md.checkmessage('codepath empty')
77 if not self.executionpath:
78 md = md.checkmessage('executionpath empty')
79 if self.interactive==1:
80 md = md.checkmessage('interactive mode not implemented')
81 return self
82 # }}}
83 def BuildQueueScript(self,dirname,modelname,solution,io_gather,isvalgrind,isgprof,isdakota,isoceancoupling):
84 # {{{
85
86 executable='issm.exe'
87 if isdakota:
88 version=IssmConfig('_DAKOTA_VERSION_')[0:2]
89 version=float(version)
90 if version>=6:
91 executable='issm_dakota.exe'
92 if isoceancoupling:
93 executable='issm_ocean.exe'
94
95 #write queuing script
96 shortname=modelname[0:min(12,len(modelname))]
97 fid=open(modelname+'.queue','w')
98 fid.write('#PBS -S /bin/bash\n')
99 fid.write('#PBS -N %s \n' % shortname)
100 fid.write('#PBS -q %s \n' % self.queue)
101 fid.write('#PBS -l select=%i:ncpus=%i:mpiprocs=%s\n' % (self.numnodes,self.cpuspernode,self.procspernodes))
102 timeobj=datetime.timedelta(minutes=self.time)
103 m,s=divmod(timeobj.total_seconds(), 60)
104 h,m=divmod(m, 60)
105 timestring="%02d:%02d:%02d" % (h, m, s)
106 fid.write('#PBS -l walltime=%s\n' % timestring) #walltime is hh:mm:ss
107 #fid.write('#PBS -l mem=%igb\n' % self.mem)
108 fid.write('#PBS -A %s\n' % self.accountname)
109 fid.write('#PBS -o %s/%s/%s.outlog \n' % (self.executionpath,dirname,modelname))
110 fid.write('#PBS -e %s/%s/%s.errlog \n\n' % (self.executionpath,dirname,modelname))
111 fid.write('export ISSM_DIR="%s/../"\n' % self.codepath)
112 fid.write('module load intelcomp/17.0.0\n')
113 fid.write('module load mpt/2.14\n')
114 fid.write('module load petsc/3.7.4d\n')
115 fid.write('module load parmetis/4.0.3\n')
116 fid.write('module load mumps/5.0.2\n')
117 fid.write('cd %s/%s/\n\n' % (self.executionpath,dirname))
118 fid.write('mpiexec_mpt -np %i %s/%s %s %s/%s %s\n' % (self.np,self.codepath,executable,str(solution),self.executionpath,dirname,modelname))
119 fid.close()
120
121 # }}}
122 def UploadQueueJob(self,modelname,dirname,filelist):
123 # {{{
124 #compress the files into one zip.
125 compressstring='tar -zcf %s.tar.gz ' % dirname
126 for file in filelist:
127 compressstring += ' %s' % file
128 subprocess.call(compressstring,shell=True)
129
130 print 'uploading input file and queueing script'
131 issmscpout(self.name,self.executionpath,self.login,self.port,[dirname+'.tar.gz'])
132
133 # }}}
134 def LaunchQueueJob(self,modelname,dirname,filelist,restart,batch):
135 # {{{
136
137 print 'launching solution sequence on remote cluster'
138 if restart:
139 launchcommand='cd %s && cd %s && qsub %s.queue' % (self.executionpath,dirname,modelname)
140 else:
141 launchcommand='cd %s && rm -rf ./%s && mkdir %s && cd %s && mv ../%s.tar.gz ./ && tar -zxf %s.tar.gz && qsub %s.queue' % (self.executionpath,dirname,dirname,dirname,dirname,dirname,modelname)
142 issmssh(self.name,self.login,self.port,launchcommand)
143
144 # }}}
145 def Download(self,dirname,filelist):
146 # {{{
147
148 #copy files from cluster to current directory
149 directory='%s/%s/' % (self.executionpath,dirname)
150 issmscpin(self.name,self.login,self.port,directory,filelist)
151 # }}}
Note: See TracBrowser for help on using the repository browser.