| 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 | for i=1:size(options.list,1),
|
|---|
| 38 | fieldname=options.list{i,1};
|
|---|
| 39 | fieldvalue=options.list{i,2};
|
|---|
| 40 | if ismember(fieldname,properties('generic')),
|
|---|
| 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 | %}}}
|
|---|
| 62 | function checkconsistency(cluster,md,solution,analyses) % {{{1
|
|---|
| 63 | if cluster.np<1
|
|---|
| 64 | checkmessage(['number of processors should be at least 1']);
|
|---|
| 65 | end
|
|---|
| 66 | if isnan(cluster.np),
|
|---|
| 67 | checkessage('number of processors should not be NaN!');
|
|---|
| 68 | end
|
|---|
| 69 | end
|
|---|
| 70 | %}}}
|
|---|
| 71 | function BuildQueueScript(cluster,md) % {{{1
|
|---|
| 72 |
|
|---|
| 73 | %retrieve parameters
|
|---|
| 74 | modelname=md.miscellaneous.name;
|
|---|
| 75 | solution=md.private.solution;
|
|---|
| 76 | isvalgrind=md.debug.valgrind;
|
|---|
| 77 | isgprof=md.debug.gprof;
|
|---|
| 78 |
|
|---|
| 79 | %open file for writing:
|
|---|
| 80 | fid=fopen([modelname '.queue'],'w');
|
|---|
| 81 |
|
|---|
| 82 | %write instructions for launching a job on the cluster
|
|---|
| 83 | fprintf(fid,'#!/bin/sh\n');
|
|---|
| 84 | if ~isvalgrind,
|
|---|
| 85 | if cluster.interactive
|
|---|
| 86 | fprintf(fid,'mpiexec -np %i %s/issm.exe %s %s %s ',...
|
|---|
| 87 | cluster.np,cluster.codepath,EnumToString(solution),cluster.executionpath,modelname);
|
|---|
| 88 | else
|
|---|
| 89 | fprintf(fid,'mpiexec -np %i %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',...
|
|---|
| 90 | cluster.np,cluster.codepath,EnumToString(solution),cluster.executionpath,modelname,modelname,modelname);
|
|---|
| 91 | end
|
|---|
| 92 | else
|
|---|
| 93 | %Add --gen-suppressions=all to get suppression lines
|
|---|
| 94 | fprintf(fid,'LD_PRELOAD=%s \\\n',cluster.valgrindlib);
|
|---|
| 95 | fprintf(fid,'mpiexec -np %i %s --leak-check=full --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',...
|
|---|
| 96 | cluster.np,cluster.valgrind,cluster.valgrindsup, cluster.codepath,EnumToString(solution),cluster.executionpath,modelname,modelname,modelname);
|
|---|
| 97 | end
|
|---|
| 98 |
|
|---|
| 99 | if isgprof,
|
|---|
| 100 | fprintf(fid,'\n gprof %s/issm.exe gmon.out > %s.performance',cluster.codepath,modelname);
|
|---|
| 101 | end
|
|---|
| 102 |
|
|---|
| 103 | if ~md.settings.io_gather,
|
|---|
| 104 | %concatenate the output files:
|
|---|
| 105 | fprintf(fid,'\ncat %s.outbin.* > %s.outbin',modelname,modelname);
|
|---|
| 106 | end
|
|---|
| 107 |
|
|---|
| 108 | %in interactive mode, create a run file, and errlog and outlog file
|
|---|
| 109 | if cluster.interactive,
|
|---|
| 110 | fid=fopen([modelname '.errlog'],'w'); fclose(fid);
|
|---|
| 111 | fid=fopen([modelname '.outlog'],'w'); fclose(fid);
|
|---|
| 112 | end
|
|---|
| 113 |
|
|---|
| 114 | end
|
|---|
| 115 | %}}}
|
|---|
| 116 | function LaunchQueueJob(cluster,md,options)% {{{1
|
|---|
| 117 |
|
|---|
| 118 | %lauch command, to be executed via ssh
|
|---|
| 119 | launchcommand=['cd ' cluster.executionpath ' && rm -rf ./' md.private.runtimename ' && mkdir ' md.private.runtimename ...
|
|---|
| 120 | ' && cd ' md.private.runtimename ' && mv ../' md.private.runtimename '.tar.gz ./ && tar -zxf ' md.private.runtimename '.tar.gz && source ' md.miscellaneous.name '.queue '];
|
|---|
| 121 |
|
|---|
| 122 | if ~strcmpi(options.batch,'yes'),
|
|---|
| 123 |
|
|---|
| 124 | %compress the files into one zip.
|
|---|
| 125 | compressstring=['tar -zcf ' md.private.runtimename '.tar.gz ' md.miscellaneous.name '.bin ' md.miscellaneous.name '.queue ' md.miscellaneous.name '.petsc '];
|
|---|
| 126 | if md.qmu.isdakota,
|
|---|
| 127 | compressstring=[compressstring md.miscellaneous.name '.qmu.in'];
|
|---|
| 128 | end
|
|---|
| 129 | if cluster.interactive,
|
|---|
| 130 | compressstring=[compressstring ' ' md.miscellaneous.name '.errlog ' md.miscellaneous.name '.outlog '];
|
|---|
| 131 | end
|
|---|
| 132 | system(compressstring);
|
|---|
| 133 |
|
|---|
| 134 | disp('uploading input file and queueing script');
|
|---|
| 135 | issmscpout(cluster.name,cluster.executionpath,cluster.login,cluster.port,{[md.private.runtimename '.tar.gz']});
|
|---|
| 136 |
|
|---|
| 137 | disp('launching solution sequence on remote cluster');
|
|---|
| 138 | issmssh(cluster.name,cluster.login,cluster.port,launchcommand);
|
|---|
| 139 | else
|
|---|
| 140 | disp('batch mode requested: not launching job interactively');
|
|---|
| 141 | disp('launch solution sequence on remote cluster by hand');
|
|---|
| 142 | end
|
|---|
| 143 |
|
|---|
| 144 | end %}}}
|
|---|
| 145 | function Download(cluster,md)% {{{1
|
|---|
| 146 |
|
|---|
| 147 | %some check
|
|---|
| 148 | if isempty(md.private.runtimename),
|
|---|
| 149 | error('supply runtime name for results to be loaded!');
|
|---|
| 150 | end
|
|---|
| 151 |
|
|---|
| 152 | %Figure out the directory where all the files are in:
|
|---|
| 153 | directory=[cluster.executionpath '/' md.private.runtimename '/'];
|
|---|
| 154 |
|
|---|
| 155 | %What packages are we picking up from remote cluster
|
|---|
| 156 | packages={[md.miscellaneous.name '.outlog'],[md.miscellaneous.name '.errlog']};
|
|---|
| 157 | if md.qmu.isdakota,
|
|---|
| 158 | packages{end+1}=[md.miscellaneous.name '.qmu.err'];
|
|---|
| 159 | packages{end+1}=[md.miscellaneous.name '.qmu.out'];
|
|---|
| 160 | if isfield(md.qmu.params,'tabular_graphics_data'),
|
|---|
| 161 | if md.qmu.params.tabular_graphics_data==true,
|
|---|
| 162 | packages{end+1}='dakota_tabular.dat';
|
|---|
| 163 | end
|
|---|
| 164 | end
|
|---|
| 165 | else
|
|---|
| 166 | packages{end+1}=[md.miscellaneous.name '.outbin'];
|
|---|
| 167 | end
|
|---|
| 168 |
|
|---|
| 169 | %copy files from cluster to present directory
|
|---|
| 170 | issmscpin(cluster.name, cluster.login, cluster.port, directory, packages);
|
|---|
| 171 | end %}}}
|
|---|
| 172 | end
|
|---|
| 173 | end
|
|---|