[8586] | 1 | %GENERIC cluster class definition
|
---|
[8578] | 2 | %
|
---|
| 3 | % Usage:
|
---|
[8586] | 4 | % cluster=generic('name','astrid','np',3);
|
---|
| 5 | % cluster=generic('name',oshostname(),'np',3,'login','username');
|
---|
[8578] | 6 |
|
---|
| 7 | classdef generic
|
---|
[13395] | 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) % {{{
|
---|
[8586] | 24 |
|
---|
[13395] | 25 | %use provided options to change fields
|
---|
| 26 | options=pairoptions(varargin{:});
|
---|
[8586] | 27 |
|
---|
[13395] | 28 | %get name
|
---|
| 29 | cluster.name=getfieldvalue(options,'name',oshostname());
|
---|
[8586] | 30 |
|
---|
[13395] | 31 | %initialize cluster using user settings if provided
|
---|
| 32 | if (exist([cluster.name '_settings'])==2), eval([cluster.name '_settings']); end
|
---|
[8578] | 33 |
|
---|
[13395] | 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 | md = checkmessage(md,'number of processors should not be NaN!');
|
---|
| 58 | end
|
---|
| 59 | end
|
---|
| 60 | %}}}
|
---|
| 61 | function BuildQueueScript(cluster,dirname,modelname,solution,io_gather,isvalgrind,isgprof) % {{{
|
---|
[8578] | 62 |
|
---|
[13395] | 63 | %write queuing script
|
---|
| 64 | if ~ispc(),
|
---|
[12706] | 65 |
|
---|
[13395] | 66 | fid=fopen([modelname '.queue'],'w');
|
---|
| 67 | fprintf(fid,'#!/bin/sh\n');
|
---|
| 68 | if ~isvalgrind,
|
---|
| 69 | if cluster.interactive
|
---|
| 70 | if ismpi,
|
---|
| 71 | fprintf(fid,'mpiexec -np %i %s/issm.exe %s %s %s ',cluster.np,cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname);
|
---|
| 72 | else
|
---|
| 73 | fprintf(fid,'%s/issm.exe %s %s %s ',cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname);
|
---|
| 74 | end
|
---|
| 75 | else
|
---|
| 76 | if ismpi,
|
---|
| 77 | fprintf(fid,'mpiexec -np %i %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',cluster.np,cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname,modelname,modelname);
|
---|
| 78 | else
|
---|
| 79 | fprintf(fid,'%s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname,modelname,modelname);
|
---|
| 80 | end
|
---|
| 81 | end
|
---|
| 82 | elseif isgprof,
|
---|
| 83 | fprintf(fid,'\n gprof %s/issm.exe gmon.out > %s.performance',cluster.codepath,modelname);
|
---|
| 84 | else
|
---|
| 85 | %Add --gen-suppressions=all to get suppression lines
|
---|
| 86 | fprintf(fid,'LD_PRELOAD=%s \\\n',cluster.valgrindlib);
|
---|
| 87 | if ismac,
|
---|
| 88 | if ismpi,
|
---|
| 89 | fprintf(fid,'mpiexec -np %i %s --leak-check=full --dsymutil=yes --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',...
|
---|
| 90 | cluster.np,cluster.valgrind,cluster.valgrindsup,cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname], modelname,modelname,modelname);
|
---|
| 91 | else
|
---|
| 92 | fprintf(fid,'%s --leak-check=full --dsymutil=yes --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',...
|
---|
| 93 | cluster.valgrind,cluster.valgrindsup,cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname], modelname,modelname,modelname);
|
---|
| 94 | end
|
---|
| 95 | else
|
---|
| 96 | if ismpi,
|
---|
| 97 | fprintf(fid,'mpiexec -np %i %s --leak-check=full --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',...
|
---|
| 98 | cluster.np,cluster.valgrind,cluster.valgrindsup,cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname,modelname,modelname);
|
---|
| 99 | else
|
---|
| 100 | fprintf(fid,'%s --leak-check=full --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',...
|
---|
| 101 | cluster.valgrind,cluster.valgrindsup,cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname,modelname,modelname);
|
---|
| 102 | end
|
---|
| 103 | end
|
---|
| 104 | end
|
---|
| 105 | if ~io_gather, %concatenate the output files:
|
---|
| 106 | fprintf(fid,'\ncat %s.outbin.* > %s.outbin',modelname,modelname);
|
---|
| 107 | end
|
---|
| 108 | fclose(fid);
|
---|
[12706] | 109 |
|
---|
[13395] | 110 | else % Windows
|
---|
[12706] | 111 |
|
---|
[13395] | 112 | fid=fopen([modelname '.bat'],'w');
|
---|
| 113 | fprintf(fid,'@echo off\n');
|
---|
| 114 | if cluster.interactive
|
---|
| 115 | fprintf(fid,'"%s/issm.exe" %s "%s" %s ',cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname);
|
---|
| 116 | else
|
---|
| 117 | fprintf(fid,'"%s/issm.exe" %s "%s" %s 2> %s.errlog >%s.outlog',...
|
---|
| 118 | cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname,modelname,modelname);
|
---|
| 119 | end
|
---|
| 120 | fclose(fid);
|
---|
| 121 | end
|
---|
[8578] | 122 |
|
---|
[13395] | 123 | %in interactive mode, create a run file, and errlog and outlog file
|
---|
| 124 | if cluster.interactive,
|
---|
| 125 | fid=fopen([modelname '.errlog'],'w'); fclose(fid);
|
---|
| 126 | fid=fopen([modelname '.outlog'],'w'); fclose(fid);
|
---|
| 127 | end
|
---|
| 128 | end
|
---|
| 129 | %}}}
|
---|
| 130 | function BuildKrigingQueueScript(cluster,modelname,solution,io_gather,isvalgrind,isgprof) % {{{
|
---|
[12706] | 131 |
|
---|
[13395] | 132 | %write queuing script
|
---|
| 133 | if ~ispc(),
|
---|
[12706] | 134 |
|
---|
[13395] | 135 | fid=fopen([modelname '.queue'],'w');
|
---|
| 136 | fprintf(fid,'#!/bin/sh\n');
|
---|
| 137 | if ~isvalgrind,
|
---|
| 138 | if cluster.interactive
|
---|
| 139 | fprintf(fid,'mpiexec -np %i %s/kriging.exe %s %s ',cluster.np,cluster.codepath,[cluster.executionpath '/' modelname],modelname);
|
---|
| 140 | else
|
---|
| 141 | fprintf(fid,'mpiexec -np %i %s/kriging.exe %s %s 2> %s.errlog >%s.outlog ',cluster.np,cluster.codepath,[cluster.executionpath '/' modelname],modelname,modelname,modelname);
|
---|
| 142 | end
|
---|
| 143 | elseif isgprof,
|
---|
| 144 | fprintf(fid,'\n gprof %s/kriging.exe gmon.out > %s.performance',cluster.codepath,modelname);
|
---|
| 145 | else
|
---|
| 146 | %Add --gen-suppressions=all to get suppression lines
|
---|
| 147 | fprintf(fid,'LD_PRELOAD=%s \\\n',cluster.valgrindlib);
|
---|
| 148 | fprintf(fid,'mpiexec -np %i %s --leak-check=full --suppressions=%s %s/kriging.exe %s %s 2> %s.errlog >%s.outlog ',...
|
---|
| 149 | cluster.np,cluster.valgrind,cluster.valgrindsup,cluster.codepath,[cluster.executionpath '/' modelname],modelname,modelname,modelname);
|
---|
| 150 | end
|
---|
| 151 | if ~io_gather, %concatenate the output files:
|
---|
| 152 | fprintf(fid,'\ncat %s.outbin.* > %s.outbin',modelname,modelname);
|
---|
| 153 | end
|
---|
| 154 | fclose(fid);
|
---|
[11527] | 155 |
|
---|
[13395] | 156 | else % Windows
|
---|
[8578] | 157 |
|
---|
[13395] | 158 | fid=fopen([modelname '.bat'],'w');
|
---|
| 159 | fprintf(fid,'@echo off\n');
|
---|
| 160 | if cluster.interactive
|
---|
| 161 | fprintf(fid,'"%s/issm.exe" %s "%s" %s ',cluster.codepath,EnumToString(solution),[cluster.executionpath '/' modelname],modelname);
|
---|
| 162 | else
|
---|
| 163 | fprintf(fid,'"%s/issm.exe" %s "%s" %s 2> %s.errlog >%s.outlog',...
|
---|
| 164 | cluster.codepath,EnumToString(solution),[cluster.executionpath '/' modelname],modelname,modelname,modelname);
|
---|
| 165 | end
|
---|
| 166 | fclose(fid);
|
---|
| 167 | end
|
---|
[8578] | 168 |
|
---|
[13395] | 169 | %in interactive mode, create a run file, and errlog and outlog file
|
---|
| 170 | if cluster.interactive,
|
---|
| 171 | fid=fopen([modelname '.errlog'],'w'); fclose(fid);
|
---|
| 172 | fid=fopen([modelname '.outlog'],'w'); fclose(fid);
|
---|
| 173 | end
|
---|
| 174 | end
|
---|
| 175 | %}}}
|
---|
| 176 | function LaunchQueueJob(cluster,modelname,dirname,filelist)% {{{
|
---|
[8578] | 177 |
|
---|
[13395] | 178 | %compress the files into one zip.
|
---|
| 179 | compressstring=['tar -zcf ' dirname '.tar.gz '];
|
---|
| 180 | for i=1:numel(filelist),
|
---|
| 181 | compressstring = [compressstring ' ' filelist{i}];
|
---|
| 182 | end
|
---|
| 183 | if cluster.interactive,
|
---|
| 184 | compressstring = [compressstring ' ' modelname '.errlog ' modelname '.outlog '];
|
---|
| 185 | end
|
---|
| 186 | system(compressstring);
|
---|
[11527] | 187 |
|
---|
[13395] | 188 | disp('uploading input file and queueing script');
|
---|
| 189 | issmscpout(cluster.name,cluster.executionpath,cluster.login,cluster.port,{[dirname '.tar.gz']});
|
---|
[11527] | 190 |
|
---|
[13395] | 191 | disp('launching solution sequence on remote cluster');
|
---|
| 192 | launchcommand=['source ' issmdir '/etc/environment.sh && cd ' cluster.executionpath ' && rm -rf ./' dirname ' && mkdir ' dirname ...
|
---|
| 193 | ' && cd ' dirname ' && mv ../' dirname '.tar.gz ./ && tar -zxf ' dirname '.tar.gz && source ' modelname '.queue '];
|
---|
| 194 | issmssh(cluster.name,cluster.login,cluster.port,launchcommand);
|
---|
| 195 | end %}}}
|
---|
| 196 | function Download(cluster,dirname,filelist)% {{{
|
---|
[11527] | 197 |
|
---|
[13395] | 198 | if ispc(),
|
---|
[12706] | 199 | %do nothing
|
---|
| 200 | return;
|
---|
[8578] | 201 | end
|
---|
| 202 |
|
---|
[12706] | 203 | %copy files from cluster to current directory
|
---|
| 204 | directory=[cluster.executionpath '/' dirname '/'];
|
---|
| 205 | issmscpin(cluster.name,cluster.login,cluster.port,directory,filelist);
|
---|
[11527] | 206 | end %}}}
|
---|
[8578] | 207 | end
|
---|
| 208 | end
|
---|