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