2011-10-24 21:54:15 +05:30
|
|
|
class MSC_TOOLS():
|
2011-10-27 23:25:42 +05:30
|
|
|
import os,string
|
2011-11-03 18:29:51 +05:30
|
|
|
|
|
|
|
releases = { \
|
|
|
|
'2010.2':['linux64',''],
|
|
|
|
'2010': ['linux64',''],
|
|
|
|
'2008r1':[''],
|
|
|
|
'2007r1':[''],
|
|
|
|
'2005r3':[''],
|
|
|
|
}
|
|
|
|
|
2011-11-03 19:25:17 +05:30
|
|
|
def library_paths(self,callerPath='',libRelation=''):
|
2011-11-03 18:29:51 +05:30
|
|
|
import os
|
|
|
|
|
2011-11-03 19:25:17 +05:30
|
|
|
if os.getenv('DAMASK_ROOT'): DamaskRoot = os.getenv('DAMASK_ROOT')
|
|
|
|
else: DamaskRoot = os.path.normpath(os.path.join(os.path.dirname(os.path.realpath(callerPath)),libRelation))
|
2011-11-03 19:21:54 +05:30
|
|
|
|
2011-11-03 18:29:51 +05:30
|
|
|
thePath = ''
|
|
|
|
try: # check for MSC.Mentat installation location
|
2011-11-03 19:21:54 +05:30
|
|
|
file = open(os.path.join(DamaskRoot,'lib/pathinfo'))
|
2011-11-03 18:29:51 +05:30
|
|
|
for line in file.readlines():
|
2011-11-03 23:04:44 +05:30
|
|
|
if line.split()[0].lower() == 'msc': MSCpath = os.path.normpath(line.split()[1])
|
2011-11-03 18:29:51 +05:30
|
|
|
file.close()
|
|
|
|
except:
|
|
|
|
MSCpath = '/msc'
|
|
|
|
|
|
|
|
for release,subdirs in sorted(self.releases.items(),reverse=True):
|
|
|
|
for subdir in subdirs:
|
|
|
|
libPath = '%s/mentat%s/shlib/%s'%(MSCpath,release,subdir)
|
|
|
|
if os.path.exists(libPath):
|
|
|
|
thePath = libPath
|
2011-11-04 17:00:29 +05:30
|
|
|
return thePath
|
2011-11-03 18:29:51 +05:30
|
|
|
else:
|
|
|
|
continue
|
2011-11-04 17:00:29 +05:30
|
|
|
|
2011-10-24 21:54:15 +05:30
|
|
|
|
|
|
|
def submit_job(self,
|
|
|
|
run_marc_path='/msc/marc2010/tools/',
|
2011-10-27 23:25:42 +05:30
|
|
|
subroutine_dir=None,
|
2011-10-24 21:54:15 +05:30
|
|
|
subroutine_name='DAMASK_marc2010',
|
|
|
|
compile='yes',
|
|
|
|
compiled_dir='../../../code/',
|
|
|
|
modelname='one_element_model',
|
|
|
|
jobname='job1',
|
|
|
|
#IOdir='',
|
|
|
|
host=[]
|
|
|
|
):
|
2011-10-27 23:25:42 +05:30
|
|
|
import os
|
2011-10-24 21:54:15 +05:30
|
|
|
import subprocess, shlex
|
2011-10-27 23:25:42 +05:30
|
|
|
import shutil
|
|
|
|
|
|
|
|
if subroutine_dir is None:
|
|
|
|
subroutine_dir=os.getenv('DAMASK_ROOT')+'/code/'
|
2011-10-24 21:54:15 +05:30
|
|
|
# Define all options [see Marc Installation and Operation Guide, pp 23]
|
|
|
|
run_marc=run_marc_path+'run_marc'
|
|
|
|
jid=' -jid '+modelname+'_'+jobname
|
|
|
|
compilation=' -u '+subroutine_dir+subroutine_name+'.f90'+' -save y'
|
|
|
|
options=' -nprocd 1 -autorst 0 -ci n -cr n -dcoup 0 -b no -v no'
|
|
|
|
cmd=run_marc+jid+options
|
|
|
|
|
|
|
|
if compile=='yes' or compile=='y':
|
|
|
|
cmd=cmd+compilation
|
|
|
|
print 'Job submission with compilation.'
|
|
|
|
else:
|
|
|
|
shutil.copy2(subroutine_dir+subroutine_name+'.f90','./'+subroutine_name+'.f90')
|
|
|
|
shutil.copy2(compiled_dir+subroutine_name+'.marc','./'+subroutine_name+'.marc')
|
|
|
|
prog=' -prog '+subroutine_name
|
|
|
|
cmd=cmd+prog
|
|
|
|
print 'Job submission without compilation, using %s'%prog
|
|
|
|
out=open('out.log','w')
|
|
|
|
print(cmd)
|
2011-11-10 16:12:59 +05:30
|
|
|
#print shlex.split(cmd)
|
2011-10-24 21:54:15 +05:30
|
|
|
self.p=subprocess.Popen(shlex.split(cmd),stdout=out,stderr=subprocess.STDOUT)
|
|
|
|
self.p.wait()
|
|
|
|
out.close()
|
|
|
|
|
|
|
|
def exit_number_from_outFile(self,outFile=None):
|
|
|
|
import string
|
|
|
|
fid_out=open(outFile,'r')
|
|
|
|
for ln in fid_out:
|
|
|
|
if (string.find(ln,'tress iteration') is not -1):
|
|
|
|
print ln
|
|
|
|
elif (string.find(ln,'Exit number') is not -1):
|
|
|
|
substr=ln[string.find(ln,'Exit number'):len(ln)]
|
|
|
|
exitnumber=substr[12:16]
|
|
|
|
fid_out.close()
|
|
|
|
return int(exitnumber)
|
|
|
|
fid_out.close()
|
|
|
|
return -1
|