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