Ignore:
Timestamp:
08/02/12 17:13:12 (13 years ago)
Author:
cborstad
Message:

merged trunk-jpl into trunk-jpl-damage through revision 12877

Location:
issm/branches/trunk-jpl-damage
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • issm/branches/trunk-jpl-damage

  • issm/branches/trunk-jpl-damage/src/m/classes/clusters/generic.py

    r12168 r12878  
    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');
     1import socket
     2import os
     3import math
     4import platform
     5import subprocess
     6from issmdir import *
     7from pairoptions import *
     8from issmssh import *
     9from issmscpin import *
     10from issmscpout import *
    711
     12class generic(object):
     13        """
     14        GENERIC cluster class definition
     15 
     16            Usage:
     17               cluster=generic('name','astrid','np',3);
     18               cluster=generic('name',oshostname(),'np',3,'login','username');
     19        """
    820
    9 class generic:
    10         #properties
    11         def __init__(self):
    12                 # {{{ Properties
     21        def __init__(self,*args):    # {{{
     22
    1323                self.name=''
    1424                self.login=''
     
    1626                self.port=0
    1727                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                 #}}}
    38                
     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'
    3933
    40 #old matlab
    41 #               function cluster=generic(varargin) % {{{1
    42 #
    43 #                        %use provided options to change fields
    44 #                        options=pairoptions(varargin{:});
    45 #
    46 #                        %get name
    47 #                        if ~exist(options,'name'), error('option ''name'' has not been provided'); end
    48 #                        cluster.name=getfieldvalue(options,'name');
    49 #
    50 #                        %initialize cluster using user settings if provided
    51 #                        if (exist([cluster.name '_settings'])==2), eval([cluster.name '_settings']); end
    52 #
    53 #                        %OK get other fields
    54 #                        for i=1:size(options.list,1),
    55 #                                fieldname=options.list{i,1};
    56 #                                fieldvalue=options.list{i,2};
    57 #                                if ismember(fieldname,properties('generic')),
    58 #                                        cluster.(fieldname)=fieldvalue;
    59 #                                else
    60 #                                        disp(['''' fieldname ''' is not a property of cluster generic']);
    61 #                                end
    62 #                        end
    63 #                end
    64 #                %}}}
    65 #                function checkconsistency(cluster,md,solution,analyses) % {{{1
    66 #                        if cluster.np<1
    67 #                                checkmessage(['number of processors should be at least 1']);
    68 #                        end
    69 #                        if isnan(cluster.np),
    70 #                                checkessage('number of processors should not be NaN!');
    71 #                        end
    72 #                end
    73 #                %}}}
    74 #                function BuildQueueScript(cluster,md) % {{{1
    75 #               
    76 #                        %retrieve parameters
    77 #                        modelname=md.miscellaneous.name;
    78 #                        solution=md.private.solution;
    79 #                        isvalgrind=md.debug.valgrind;
    80 #                        isgprof=md.debug.gprof;
    81 #
    82 #                        %open file for writing:
    83 #                        if ~ispc,
    84 #                                fid=fopen([modelname '.queue'],'w');
    85 #                        else
    86 #                                fid=fopen([modelname '.bat'],'w');
    87 #                        end
    88 #
    89 #                        %write instructions for launching a job on the cluster
    90 #                        if ~ispc,
    91 #                                fprintf(fid,'#!/bin/sh\n');
    92 #                        else
    93 #                                fprintf(fid,'@echo off\n');
    94 #                        end
    95 #                       
    96 #                        if ~isvalgrind,
    97 #                                if cluster.interactive
    98 #                                        if ~ispc,
    99 #                                                fprintf(fid,'mpiexec -np %i %s/issm.exe %s %s %s ',cluster.np,cluster.codepath,EnumToString(solution),cluster.executionpath,modelname);
    100 #                                        else
    101 #                                                fprintf(fid,'"%s/issm.exe" %s "%s" %s ',cluster.codepath,EnumToString(solution),cluster.executionpath,modelname);
    102 #                                        end
    103 #                                else
    104 #                                        if ~ispc,
    105 #                                                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);
    106 #                                        else
    107 #                                                fprintf(fid,'"%s/issm.exe" %s "%s" %s 2> %s.errlog >%s.outlog ',cluster.codepath,EnumToString(solution),cluster.executionpath,modelname,modelname,modelname);
    108 #                                        end
    109 #                                end
    110 #                        else
    111 #                                if ~ispc,
    112 #                                        %Add --gen-suppressions=all to get suppression lines
    113 #                                        fprintf(fid,'LD_PRELOAD=%s \\\n',cluster.valgrindlib);
    114 #                                        fprintf(fid,'mpiexec -np %i %s --leak-check=full --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',...
    115 #                                        cluster.np,cluster.valgrind,cluster.valgrindsup, cluster.codepath,EnumToString(solution),cluster.executionpath,modelname,modelname,modelname);
    116 #                                else
    117 #                                        error('valgrind not supported on windows platforms');
    118 #                                end
    119 #                        end
    120 #
    121 #                        if isgprof,
    122 #                                if ~ispc,
    123 #                                        fprintf(fid,'\n gprof %s/issm.exe gmon.out > %s.performance',cluster.codepath,modelname);
    124 #                                else
    125 #                                        error('gprof not supported on windows platforms');
    126 #                                end
    127 #
    128 #                        end
    129 #
    130 #                        if ~md.settings.io_gather,
    131 #                                if ~ispc,
    132 #                                        %concatenate the output files:
    133 #                                        fprintf(fid,'\ncat %s.outbin.* > %s.outbin',modelname,modelname);
    134 #                                else
    135 #                                        error('iogather not supported on windows platforms');
    136 #                                end
    137 #
    138 #                        end
    139 #                       
    140 #                        %close file:
    141 #                        fclose(fid);
    142 #
    143 #                        %in interactive mode, create a run file, and errlog and outlog file
    144 #                        if cluster.interactive,
    145 #                                fid=fopen([modelname '.errlog'],'w'); fclose(fid);
    146 #                                fid=fopen([modelname '.outlog'],'w'); fclose(fid);
    147 #                        end
    148 #
    149 #
    150 #                end
    151 #                %}}}
    152 #                function LaunchQueueJob(cluster,md,options)% {{{1
    153 #                       
    154 #                        if ~ispc,
    155 #                                        %lauch command, to be executed via ssh
    156 #                                        launchcommand=['cd ' cluster.executionpath ' && rm -rf ./' md.private.runtimename ' && mkdir ' md.private.runtimename ...
    157 #                                        ' && cd ' md.private.runtimename ' && mv ../' md.private.runtimename '.tar.gz ./ && tar -zxf ' md.private.runtimename '.tar.gz  && source  ' md.miscellaneous.name '.queue '];
    158 #
    159 #                                        if ~strcmpi(options.batch,'yes'),
    160 #
    161 #                                                %compress the files into one zip.
    162 #                                                compressstring=['tar -zcf ' md.private.runtimename '.tar.gz ' md.miscellaneous.name '.bin ' md.miscellaneous.name '.queue '  md.miscellaneous.name '.petsc '];
    163 #                                                if md.qmu.isdakota,
    164 #                                                        compressstring=[compressstring md.miscellaneous.name '.qmu.in'];
    165 #                                       end
    166 #                                       if cluster.interactive,
    167 #                                               compressstring=[compressstring ' ' md.miscellaneous.name '.errlog ' md.miscellaneous.name '.outlog '];
    168 #                                       end
    169 #                                       system(compressstring);
    170 #
    171 #                                       disp('uploading input file and queueing script');
    172 #                                       issmscpout(cluster.name,cluster.executionpath,cluster.login,cluster.port,{[md.private.runtimename '.tar.gz']});
    173 #
    174 #                                       disp('launching solution sequence on remote cluster');
    175 #                                       issmssh(cluster.name,cluster.login,cluster.port,launchcommand);
    176 #                               else
    177 #                                       disp('batch mode requested: not launching job interactively');
    178 #                                       disp('launch solution sequence on remote cluster by hand');
    179 #                               end
    180 #                       else
    181 #                               %launch right here, do not compress or archive.
    182 #                               system([md.miscellaneous.name '.bat']);
    183 #                       end
    184 #
    185 #               end %}}}
    186 #                function Download(cluster,md)% {{{1
    187 #
    188 #                       if ~ispc,
    189 #                               %some check
    190 #                               if isempty(md.private.runtimename),
    191 #                                       error('supply runtime name for results to be loaded!');
    192 #                               end
    193 #
    194 #                               %Figure out the  directory where all the files are in:
    195 #                               directory=[cluster.executionpath '/' md.private.runtimename '/'];
    196 #
    197 #                               %What packages are we picking up from remote cluster
    198 #                               packages={[md.miscellaneous.name '.outlog'],[md.miscellaneous.name '.errlog']};
    199 #                               if md.qmu.isdakota,
    200 #                                       packages{end+1}=[md.miscellaneous.name '.qmu.err'];
    201 #                                       packages{end+1}=[md.miscellaneous.name '.qmu.out'];
    202 #                                       if isfield(md.qmu.params,'tabular_graphics_data'),
    203 #                                               if md.qmu.params.tabular_graphics_data==true,
    204 #                                                       packages{end+1}='dakota_tabular.dat';
    205 #                                               end
    206 #                                       end
    207 #                               else
    208 #                                       packages{end+1}=[md.miscellaneous.name '.outbin'];
    209 #                               end
    210 #
    211 #                               %copy files from cluster to present directory
    212 #                               issmscpin(cluster.name, cluster.login, cluster.port, directory, packages);
    213 #                       else
    214 #                               %do nothing!
    215 #                       end
    216 #               end %}}}
    217 #
     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                self=options.AssignObjectFields(self)
     46        # }}}
     47
     48        def __repr__(self):    # {{{
     49                #  display the object
     50                s ="class '%s' object '%s' = \n" % (type(self),'self')
     51                s+="    name: %s\n" % self.name
     52                s+="    login: %s\n" % self.login
     53                s+="    np: %i\n" % self.np
     54                s+="    port: %i\n" % self.port
     55                s+="    codepath: %s\n" % self.codepath
     56                s+="    executionpath: %s\n" % self.executionpath
     57                s+="    valgrind: %s\n" % self.valgrind
     58                s+="    valgrindlib: %s\n" % self.valgrindlib
     59                s+="    valgrindsup: %s\n" % self.valgrindsup
     60                return s
     61        # }}}
     62
     63        def checkconsistency(self,md,solution,analyses):    # {{{
     64                if self.np<1:
     65                        md = checkmessage(md,'number of processors should be at least 1')
     66                if math.isnan(self.np):
     67                        md = checkmessage(md,'number of processors should not be NaN!')
     68
     69                return md
     70        # }}}
     71
     72        def BuildQueueScript(self,dirname,modelname,solution,io_gather,isvalgrind,isgprof):    # {{{
     73
     74                #write queuing script
     75                if not 'Windows' in platform.system():
     76
     77                        fid=open(modelname+'.queue','w')
     78                        fid.write('#!/bin/sh\n')
     79                        if not isvalgrind:
     80                                if self.interactive:
     81                                        fid.write('mpiexec -np %i %s/issm.exe %s %s %s ' % (self.np,self.codepath,EnumToString(solution),self.executionpath,modelname))
     82                                else:
     83                                        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))
     84                        elif isgprof:
     85                                fid.write('\n gprof %s/issm.exe gmon.out > %s.performance' % (self.codepath,modelname))
     86                        else:
     87                                #Add --gen-suppressions=all to get suppression lines
     88                                fid.write('LD_PRELOAD=%s \\\n' % self.valgrindlib)
     89                                fid.write('mpiexec -np %i %s --leak-check=full --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ' % \
     90                                        (self.np,self.valgrind,self.valgrindsup,self.codepath,EnumToString(solution),self.executionpath,modelname,modelname,modelname))
     91                        if not io_gather:    #concatenate the output files:
     92                                fid.write('\ncat %s.outbin.* > %s.outbin' % (modelname,modelname))
     93                        fid.close()
     94
     95                else:    # Windows
     96
     97                        fid=open(modelname+'.bat','w')
     98                        fid.write('@echo off\n')
     99                        if self.interactive:
     100                                fid.write('"%s/issm.exe" %s "%s" %s ' % (self.codepath,EnumToString(solution),self.executionpath,modelname))
     101                        else:
     102                                fid.write('"%s/issm.exe" %s "%s" %s 2> %s.errlog >%s.outlog' % \
     103                                        (self.codepath,EnumToString(solution),self.executionpath,modelname,modelname,modelname))
     104                        fid.close()
     105
     106                #in interactive mode, create a run file, and errlog and outlog file
     107                if self.interactive:
     108                        fid=open(modelname+'.errlog','w')
     109                        fid.close()
     110                        fid=open(modelname+'.outlog','w')
     111                        fid.close()
     112        # }}}
     113
     114        def BuildKrigingQueueScript(self,modelname,solution,io_gather,isvalgrind,isgprof):    # {{{
     115
     116                #write queuing script
     117                if not 'Windows' in platform.system():
     118
     119                        fid=open(modelname+'.queue','w')
     120                        fid.write('#!/bin/sh\n')
     121                        if not isvalgrind:
     122                                if self.interactive:
     123                                        fid.write('mpiexec -np %i %s/kriging.exe %s %s ' % (self.np,self.codepath,self.executionpath,modelname))
     124                                else:
     125                                        fid.write('mpiexec -np %i %s/kriging.exe %s %s 2> %s.errlog >%s.outlog ' % (self.np,self.codepath,self.executionpath,modelname,modelname,modelname))
     126                        elif isgprof:
     127                                fid.write('\n gprof %s/kriging.exe gmon.out > %s.performance' & (self.codepath,modelname))
     128                        else:
     129                                #Add --gen-suppressions=all to get suppression lines
     130                                fid.write('LD_PRELOAD=%s \\\n' % self.valgrindlib)
     131                                fid.write('mpiexec -np %i %s --leak-check=full --suppressions=%s %s/kriging.exe %s %s 2> %s.errlog >%s.outlog ' % \
     132                                        (self.np,self.valgrind,self.valgrindsup,self.codepath,self.executionpath,modelname,modelname,modelname))
     133                        if not io_gather:    #concatenate the output files:
     134                                fid.write('\ncat %s.outbin.* > %s.outbin' % (modelname,modelname))
     135                        fid.close()
     136
     137                else:    # Windows
     138
     139                        fid=open(modelname+'.bat','w')
     140                        fid.write('@echo off\n')
     141                        if self.interactive:
     142                                fid.write('"%s/issm.exe" %s "%s" %s ' % (self.codepath,EnumToString(solution),self.executionpath,modelname))
     143                        else:
     144                                fid.write('"%s/issm.exe" %s "%s" %s 2> %s.errlog >%s.outlog' % \
     145                                        (self.codepath,EnumToString(solution),self.executionpath,modelname,modelname,modelname))
     146                        fid.close()
     147
     148                #in interactive mode, create a run file, and errlog and outlog file
     149                if self.interactive:
     150                        fid=open(modelname+'.errlog','w')
     151                        fid.close()
     152                        fid=open(modelname+'.outlog','w')
     153                        fid.close()
     154        # }}}
     155
     156        def LaunchQueueJob(self,modelname,dirname,filelist):    # {{{
     157
     158                #compress the files into one zip.
     159                compressstring='tar -zcf %s.tar.gz ' % dirname
     160                for file in filelist:
     161                        compressstring += ' %s' % file
     162                if self.interactive:
     163                        compressstring += ' %s.errlog %s.outlog ' % (modelname,modelname)
     164                subprocess.call(compressstring,shell=True)
     165
     166                print 'uploading input file and queueing script'
     167                issmscpout(self.name,self.executionpath,self.login,self.port,[dirname+'.tar.gz'])
     168
     169                print 'launching solution sequence on remote cluster'
     170                launchcommand='cd %s && rm -rf ./%s && mkdir %s && cd %s && mv ../%s.tar.gz ./ && tar -zxf %s.tar.gz  && source  %s.queue ' % \
     171                        (self.executionpath,dirname,dirname,dirname,dirname,dirname,modelname)
     172                issmssh(self.name,self.login,self.port,launchcommand)
     173        # }}}
     174
     175        def Download(self,dirname,filelist):     # {{{
     176
     177                if 'Windows' in platform.system():
     178                        #do nothing
     179                        return
     180
     181                #copy files from cluster to current directory
     182                directory='%s/%s/' % (self.executionpath,dirname)
     183                issmscpin(self.name,self.login,self.port,directory,filelist)
     184        # }}}
     185
Note: See TracChangeset for help on using the changeset viewer.