Changeset 12753
- Timestamp:
- 07/26/12 11:05:24 (13 years ago)
- Location:
- issm/trunk-jpl/src/m/classes/clusters
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
issm/trunk-jpl/src/m/classes/clusters/generic.m
r12663 r12753 6 6 7 7 classdef generic 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 8 properties (SetAccess=public) 9 % {{{ 10 name=''; 11 login=''; 12 np=1; 13 port=0; 14 interactive=1; 15 codepath=[issmdir() '/bin']; 16 executionpath=[issmdir() '/execution']; 17 valgrind=[issmdir() '/externalpackages/valgrind/install/bin/valgrind']; 18 valgrindlib=[issmdir() '/externalpackages/valgrind/install/lib/libmpidebug.so']; 19 valgrindsup=[issmdir() '/externalpackages/valgrind/issm.supp']; 20 %}}} 21 end 22 methods 23 function cluster=generic(varargin) % {{{ 24 24 25 26 25 %use provided options to change fields 26 options=pairoptions(varargin{:}); 27 27 28 29 28 %get name 29 cluster.name=getfieldvalue(options,'name',oshostname()); 30 30 31 32 31 %initialize cluster using user settings if provided 32 if (exist([cluster.name '_settings'])==2), eval([cluster.name '_settings']); end 33 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 34 %OK get other fields 35 cluster=AssignObjectFields(pairoptions(varargin{:}),cluster); 36 end 37 %}}} 38 function disp(cluster) % {{{ 39 % display the object 40 disp(sprintf('class ''%s'' object ''%s'' = ',class(cluster),inputname(1))); 41 disp(sprintf(' name: %s',cluster.name)); 42 disp(sprintf(' login: %s',cluster.login)); 43 disp(sprintf(' np: %i',cluster.np)); 44 disp(sprintf(' port: %i',cluster.port)); 45 disp(sprintf(' codepath: %s',cluster.codepath)); 46 disp(sprintf(' executionpath: %s',cluster.executionpath)); 47 disp(sprintf(' valgrind: %s',cluster.valgrind)); 48 disp(sprintf(' valgrindlib: %s',cluster.valgrindlib)); 49 disp(sprintf(' valgrindsup: %s',cluster.valgrindsup)); 50 end 51 %}}} 52 function md = checkconsistency(cluster,md,solution,analyses) % {{{ 53 if cluster.np<1 54 md = checkmessage(md,['number of processors should be at least 1']); 55 end 56 if isnan(cluster.np), 57 checkessage('number of processors should not be NaN!'); 58 end 59 end 60 %}}} 61 function BuildQueueScript(cluster,modelname,solution,io_gather,isvalgrind,isgprof) % {{{ 62 62 63 64 63 %write queuing script 64 if ~ispc, 65 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 66 fid=fopen([modelname '.queue'],'w'); 67 fprintf(fid,'#!/bin/sh\n'); 68 if ~isvalgrind, 69 if cluster.interactive 70 fprintf(fid,'mpiexec -np %i %s/issm.exe %s %s %s ',cluster.np,cluster.codepath,EnumToString(solution),cluster.executionpath,modelname); 71 else 72 fprintf(fid,'mpiexec -np %i %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',cluster.np,cluster.codepath,EnumToString(solution),cluster.executionpath,modelname,modelname,modelname); 73 end 74 elseif isgprof, 75 fprintf(fid,'\n gprof %s/issm.exe gmon.out > %s.performance',cluster.codepath,modelname); 76 else 77 %Add --gen-suppressions=all to get suppression lines 78 fprintf(fid,'LD_PRELOAD=%s \\\n',cluster.valgrindlib); 79 fprintf(fid,'mpiexec -np %i %s --leak-check=full --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',... 80 cluster.np,cluster.valgrind,cluster.valgrindsup,cluster.codepath,EnumToString(solution),cluster.executionpath,modelname,modelname,modelname); 81 end 82 if ~io_gather, %concatenate the output files: 83 fprintf(fid,'\ncat %s.outbin.* > %s.outbin',modelname,modelname); 84 end 85 fclose(fid); 86 86 87 87 else % Windows 88 88 89 90 91 92 93 94 95 96 97 98 89 fid=fopen([modelname '.bat'],'w'); 90 fprintf(fid,'@echo off\n'); 91 if cluster.interactive 92 fprintf(fid,'"%s/issm.exe" %s "%s" %s ',cluster.codepath,EnumToString(solution),cluster.executionpath,modelname); 93 else 94 fprintf(fid,'"%s/issm.exe" %s "%s" %s 2> %s.errlog >%s.outlog',... 95 cluster.codepath,EnumToString(solution),cluster.executionpath,modelname,modelname,modelname); 96 end 97 fclose(fid); 98 end 99 99 100 101 102 103 104 105 106 107 100 %in interactive mode, create a run file, and errlog and outlog file 101 if cluster.interactive, 102 fid=fopen([modelname '.errlog'],'w'); fclose(fid); 103 fid=fopen([modelname '.outlog'],'w'); fclose(fid); 104 end 105 end 106 %}}} 107 function BuildKrigingQueueScript(cluster,modelname,solution,io_gather,isvalgrind,isgprof) % {{{ 108 108 109 110 109 %write queuing script 110 if ~ispc, 111 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 112 fid=fopen([modelname '.queue'],'w'); 113 fprintf(fid,'#!/bin/sh\n'); 114 if ~isvalgrind, 115 if cluster.interactive 116 fprintf(fid,'mpiexec -np %i %s/kriging.exe %s %s ',cluster.np,cluster.codepath,cluster.executionpath,modelname); 117 else 118 fprintf(fid,'mpiexec -np %i %s/kriging.exe %s %s 2> %s.errlog >%s.outlog ',cluster.np,cluster.codepath,cluster.executionpath,modelname,modelname,modelname); 119 end 120 elseif isgprof, 121 fprintf(fid,'\n gprof %s/kriging.exe gmon.out > %s.performance',cluster.codepath,modelname); 122 else 123 %Add --gen-suppressions=all to get suppression lines 124 fprintf(fid,'LD_PRELOAD=%s \\\n',cluster.valgrindlib); 125 fprintf(fid,'mpiexec -np %i %s --leak-check=full --suppressions=%s %s/kriging.exe %s %s 2> %s.errlog >%s.outlog ',... 126 cluster.np,cluster.valgrind,cluster.valgrindsup,cluster.codepath,cluster.executionpath,modelname,modelname,modelname); 127 end 128 if ~io_gather, %concatenate the output files: 129 fprintf(fid,'\ncat %s.outbin.* > %s.outbin',modelname,modelname); 130 end 131 fclose(fid); 132 132 133 133 else % Windows 134 134 135 136 137 138 139 140 141 142 143 144 135 fid=fopen([modelname '.bat'],'w'); 136 fprintf(fid,'@echo off\n'); 137 if cluster.interactive 138 fprintf(fid,'"%s/issm.exe" %s "%s" %s ',cluster.codepath,EnumToString(solution),cluster.executionpath,modelname); 139 else 140 fprintf(fid,'"%s/issm.exe" %s "%s" %s 2> %s.errlog >%s.outlog',... 141 cluster.codepath,EnumToString(solution),cluster.executionpath,modelname,modelname,modelname); 142 end 143 fclose(fid); 144 end 145 145 146 147 148 149 150 151 152 153 146 %in interactive mode, create a run file, and errlog and outlog file 147 if cluster.interactive, 148 fid=fopen([modelname '.errlog'],'w'); fclose(fid); 149 fid=fopen([modelname '.outlog'],'w'); fclose(fid); 150 end 151 end 152 %}}} 153 function LaunchQueueJob(cluster,modelname,dirname,filelist)% {{{ 154 154 155 156 157 158 159 160 161 162 163 155 %compress the files into one zip. 156 compressstring=['tar -zcf ' dirname '.tar.gz ']; 157 for i=1:numel(filelist), 158 compressstring = [compressstring ' ' filelist{i}]; 159 end 160 if cluster.interactive, 161 compressstring = [compressstring ' ' modelname '.errlog ' modelname '.outlog ']; 162 end 163 system(compressstring); 164 164 165 166 165 disp('uploading input file and queueing script'); 166 issmscpout(cluster.name,cluster.executionpath,cluster.login,cluster.port,{[dirname '.tar.gz']}); 167 167 168 169 170 171 172 173 168 disp('launching solution sequence on remote cluster'); 169 launchcommand=['cd ' cluster.executionpath ' && rm -rf ./' dirname ' && mkdir ' dirname ... 170 ' && cd ' dirname ' && mv ../' dirname '.tar.gz ./ && tar -zxf ' dirname '.tar.gz && source ' modelname '.queue ']; 171 issmssh(cluster.name,cluster.login,cluster.port,launchcommand); 172 end %}}} 173 function Download(cluster,dirname,filelist)% {{{ 174 174 175 175 if ispc, -
issm/trunk-jpl/src/m/classes/clusters/generic.py
r12351 r12753 1 #GENERIC cluster class definition 2 # 3 # Usage: 4 # cluster=generic('name','astrid',); 5 # cluster=generic('name','astrid','np',3); 6 # cluster=generic('name',oshostname(),'np',3,'login','username'); 1 """ 2 GENERIC cluster class definition 3 4 Usage: 5 cluster=generic('name','astrid','np',3); 6 cluster=generic('name',oshostname(),'np',3,'login','username'); 7 """ 7 8 9 import socket 10 import os 11 import math 12 import platform 13 import subprocess 14 from issmdir import * 15 from pairoptions import * 16 from issmssh import * 17 from issmscpin import * 18 from issmscpout import * 8 19 9 class generic: 10 #properties 11 def __init__(self): 12 # {{{ Properties 20 class generic(object): 21 def __init__(self,*args): # {{{ 22 13 23 self.name='' 14 24 self.login='' … … 16 26 self.port=0 17 27 self.interactive=1 18 self.codepath=issmdir() + '/bin' 19 self.executionpath=issmdir() + '/execution' 20 self.valgrind=issmdir() + '/externalpackages/valgrind/install/bin/valgrind' 21 self.valgrindlib=issmdir() + '/externalpackages/valgrind/install/lib/libmpidebug.so' 22 self.valgrindsup=issmdir() + '/externalpackages/valgrind/issm.supp' 23 #}}} 24 def __repr__(obj): 25 # {{{ Display 26 27 string="class 'generic' object:" 28 string="%s\n\n%s"%(string,"%s%s"%(' name: ',obj.name)) 29 string="%s\n%s"%(string,"%s%i"%(' np: ',obj.np)) 30 string="%s\n%s"%(string,"%s%i"%(' port: ',obj.port)) 31 string="%s\n%s"%(string,"%s%s"%(' codepath: ',obj.codepath)) 32 string="%s\n%s"%(string,"%s%s"%(' executionpath: ',obj.executionpath)) 33 string="%s\n%s"%(string,"%s%s"%(' valgrind: ',obj.valgrind)) 34 string="%s\n%s"%(string,"%s%s"%(' valgrindlib: ',obj.valgrindlib)) 35 string="%s\n%s"%(string,"%s%s"%(' valgrindsup: ',obj.valgrindsup)) 36 return string 37 #}}} 28 self.codepath=issmdir()+'/bin' 29 self.executionpath=issmdir()+'/execution' 30 self.valgrind=issmdir()+'/externalpackages/valgrind/install/bin/valgrind' 31 self.valgrindlib=issmdir()+'/externalpackages/valgrind/install/lib/libmpidebug.so' 32 self.valgrindsup=issmdir()+'/externalpackages/valgrind/issm.supp' 33 34 #use provided options to change fields 35 options=pairoptions(*args) 36 37 #get name 38 self.name=options.getfieldvalue('name',socket.gethostname().lower().split('.')[0]) 39 40 #initialize cluster using user settings if provided 41 if os.path.exists(self.name+'_settings.py'): 42 execfile(self.name+'_settings.py',globals()) 43 44 #OK get other fields 45 cluster=options.AssignObjectFields(cluster) 46 # }}} 47 48 def __repr__(self): # {{{ 49 # display the object 50 print "class '%s' object '%s' = " % (type(self),'self') 51 print " name: %s" % self.name 52 print " login: %s" % self.login 53 print " np: %i" % self.np 54 print " port: %i" % self.port 55 print " codepath: %s" % self.codepath 56 print " executionpath: %s" % self.executionpath 57 print " valgrind: %s" % self.valgrind 58 print " valgrindlib: %s" % self.valgrindlib 59 print " valgrindsup: %s" % self.valgrindsup 60 # }}} 61 62 def checkconsistency(self,md,solution,analyses): # {{{ 63 if self.np<1: 64 md = checkmessage(md,'number of processors should be at least 1') 65 if math.isnan(self.np): 66 md = checkmessage(md,'number of processors should not be NaN!') 67 68 return md 69 # }}} 70 71 def BuildQueueScript(self,modelname,solution,io_gather,isvalgrind,isgprof): # {{{ 72 73 #write queuing script 74 if not 'Windows' in platform.system(): 75 76 fid=open(modelname+'.queue','w') 77 fid.write('#!/bin/sh\n') 78 if not isvalgrind: 79 if self.interactive: 80 fid.write('mpiexec -np %i %s/issm.exe %s %s %s ' % (self.np,self.codepath,EnumToString(solution),self.executionpath,modelname)) 81 else: 82 fid.write('mpiexec -np %i %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ' % (self.np,self.codepath,EnumToString(solution),self.executionpath,modelname,modelname,modelname)) 83 elif isgprof: 84 fid.write('\n gprof %s/issm.exe gmon.out > %s.performance' % (self.codepath,modelname)) 85 else: 86 #Add --gen-suppressions=all to get suppression lines 87 fid.write('LD_PRELOAD=%s \\\n' % self.valgrindlib) 88 fid.write('mpiexec -np %i %s --leak-check=full --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ' % \ 89 (self.np,self.valgrind,self.valgrindsup,self.codepath,EnumToString(solution),self.executionpath,modelname,modelname,modelname)) 90 if not io_gather: #concatenate the output files: 91 fid.write('\ncat %s.outbin.* > %s.outbin' % (modelname,modelname)) 92 fid.close() 93 94 else: # Windows 95 96 fid=open(modelname+'.bat','w') 97 fid.write('@echo off\n') 98 if self.interactive: 99 fid.write('"%s/issm.exe" %s "%s" %s ' % (self.codepath,EnumToString(solution),self.executionpath,modelname)) 100 else: 101 fid.write('"%s/issm.exe" %s "%s" %s 2> %s.errlog >%s.outlog' % \ 102 (self.codepath,EnumToString(solution),self.executionpath,modelname,modelname,modelname)) 103 fid.close() 104 105 #in interactive mode, create a run file, and errlog and outlog file 106 if self.interactive: 107 fid=open(modelname+'.errlog','w') 108 fid.close() 109 fid=open(modelname+'.outlog','w') 110 fid.close() 111 # }}} 112 113 def BuildKrigingQueueScript(self,modelname,solution,io_gather,isvalgrind,isgprof): # {{{ 114 115 #write queuing script 116 if not 'Windows' in platform.system(): 117 118 fid=open(modelname+'.queue','w') 119 fid.write('#!/bin/sh\n') 120 if not isvalgrind: 121 if self.interactive: 122 fid.write('mpiexec -np %i %s/kriging.exe %s %s ' % (self.np,self.codepath,self.executionpath,modelname)) 123 else: 124 fid.write('mpiexec -np %i %s/kriging.exe %s %s 2> %s.errlog >%s.outlog ' % (self.np,self.codepath,self.executionpath,modelname,modelname,modelname)) 125 elif isgprof: 126 fid.write('\n gprof %s/kriging.exe gmon.out > %s.performance' & (self.codepath,modelname)) 127 else: 128 #Add --gen-suppressions=all to get suppression lines 129 fid.write('LD_PRELOAD=%s \\\n' % self.valgrindlib) 130 fid.write('mpiexec -np %i %s --leak-check=full --suppressions=%s %s/kriging.exe %s %s 2> %s.errlog >%s.outlog ' % \ 131 (self.np,self.valgrind,self.valgrindsup,self.codepath,self.executionpath,modelname,modelname,modelname)) 132 if not io_gather: #concatenate the output files: 133 fid.write('\ncat %s.outbin.* > %s.outbin' % (modelname,modelname)) 134 fid.close() 135 136 else: # Windows 137 138 fid=open(modelname+'.bat','w') 139 fid.write('@echo off\n') 140 if self.interactive: 141 fid.write('"%s/issm.exe" %s "%s" %s ' % (self.codepath,EnumToString(solution),self.executionpath,modelname)) 142 else: 143 fid.write('"%s/issm.exe" %s "%s" %s 2> %s.errlog >%s.outlog' % \ 144 (self.codepath,EnumToString(solution),self.executionpath,modelname,modelname,modelname)) 145 fid.close() 146 147 #in interactive mode, create a run file, and errlog and outlog file 148 if self.interactive: 149 fid=open(modelname+'.errlog','w') 150 fid.close() 151 fid=open(modelname+'.outlog','w') 152 fid.close() 153 # }}} 154 155 def LaunchQueueJob(self,modelname,dirname,filelist): # {{{ 156 157 #compress the files into one zip. 158 compressstring='tar -zcf %s.tar.gz ' % dirname 159 for file in filelist: 160 compressstring += ' %s' % file 161 if self.interactive: 162 compressstring += ' %s.errlog %s.outlog ' % (modelname,modelname) 163 subprocess.call(compressstring,shell=True) 164 165 print 'uploading input file and queueing script' 166 issmscpout(self.name,self.executionpath,self.login,self.port,[dirname+'.tar.gz']) 167 168 print 'launching solution sequence on remote cluster' 169 launchcommand='cd %s && rm -rf ./%s && mkdir %s && cd %s && mv ../%s.tar.gz ./ && tar -zxf %s.tar.gz && source %s.queue ' % \ 170 (self.executionpath,dirname,dirname,dirname,dirname,dirname,modelname) 171 issmssh(self.name,self.login,self.port,launchcommand) 172 # }}} 173 174 def Download(self,dirname,filelist): # {{{ 175 176 if 'Windows' in platform.system(): 177 #do nothing 178 return 179 180 #copy files from cluster to current directory 181 directory='%s/%s/' % (self.executionpath,dirname) 182 issmscpin(self.name,self.login,self.port,directory,filelist) 183 # }}} 184
Note:
See TracChangeset
for help on using the changeset viewer.