1 | %LOCALPFE cluster class definition
|
---|
2 | %
|
---|
3 | % Usage:
|
---|
4 | % cluster=localpfe('name','astrid','np',3);
|
---|
5 | % cluster=localpfe('name',oshostname(),'np',3,'login','username');
|
---|
6 |
|
---|
7 | classdef localpfe
|
---|
8 | properties (SetAccess=public)
|
---|
9 | % {{{
|
---|
10 | name = '';
|
---|
11 | login = '';
|
---|
12 | np = 1;
|
---|
13 | npocean = 0;
|
---|
14 | port = 0;
|
---|
15 | interactive = 1;
|
---|
16 | codepath = [IssmConfig('ISSM_PREFIX') '/bin'];
|
---|
17 | etcpath = [issmdir() '/etc'];
|
---|
18 | executionpath = [issmdir() '/execution'];
|
---|
19 | valgrind = [issmdir() '/externalpackages/valgrind/install/bin/valgrind'];
|
---|
20 | valgrindlib = [issmdir() '/externalpackages/valgrind/install/lib/libmpidebug.so'];
|
---|
21 | valgrindsup = [issmdir() '/externalpackages/valgrind/issm.supp'];
|
---|
22 | verbose = 1;
|
---|
23 | shell = '/bin/sh';
|
---|
24 | %}}}
|
---|
25 | end
|
---|
26 | methods
|
---|
27 | function cluster=localpfe(varargin) % {{{
|
---|
28 |
|
---|
29 | %Change the defaults if ispc and not ismingw
|
---|
30 | if ispc & ~ismingw,
|
---|
31 | cluster.codepath = [issmdir() '\bin'];
|
---|
32 | cluster.etcpath = [issmdir() '\etc'];
|
---|
33 | cluster.executionpath = [issmdir() '\execution'];
|
---|
34 | end
|
---|
35 |
|
---|
36 | %use provided options to change fields
|
---|
37 | options=pairoptions(varargin{:});
|
---|
38 |
|
---|
39 | %get name
|
---|
40 | cluster.name=getfieldvalue(options,'name',oshostname());
|
---|
41 |
|
---|
42 | %initialize cluster using user settings if provided
|
---|
43 | if (exist([cluster.name '_settings'])==2), eval([cluster.name '_settings']); end
|
---|
44 |
|
---|
45 | %OK get other fields
|
---|
46 | cluster=AssignObjectFields(pairoptions(varargin{:}),cluster);
|
---|
47 | end
|
---|
48 | %}}}
|
---|
49 | function disp(cluster) % {{{
|
---|
50 | % display the object
|
---|
51 | disp(sprintf('class ''%s'' object ''%s'' = ',class(cluster),inputname(1)));
|
---|
52 | disp(sprintf(' name: %s',cluster.name));
|
---|
53 | disp(sprintf(' login: %s',cluster.login));
|
---|
54 | disp(sprintf(' np: %i',cluster.np));
|
---|
55 | disp(sprintf(' npocean: %i',cluster.npocean));
|
---|
56 | disp(sprintf(' port: %i',cluster.port));
|
---|
57 | disp(sprintf(' interactive: %i',cluster.interactive));
|
---|
58 | disp(sprintf(' codepath: %s',cluster.codepath));
|
---|
59 | disp(sprintf(' etcpath: %s',cluster.etcpath));
|
---|
60 | disp(sprintf(' executionpath: %s',cluster.executionpath));
|
---|
61 | disp(sprintf(' valgrind: %s',cluster.valgrind));
|
---|
62 | disp(sprintf(' valgrindlib: %s',cluster.valgrindlib));
|
---|
63 | disp(sprintf(' valgrindsup: %s',cluster.valgrindsup));
|
---|
64 | disp(sprintf(' verbose: %s',cluster.verbose));
|
---|
65 | disp(sprintf(' shell: %s',cluster.shell));
|
---|
66 | end
|
---|
67 | %}}}
|
---|
68 | function md = checkconsistency(cluster,md,solution,analyses) % {{{
|
---|
69 | if cluster.np<1
|
---|
70 | md = checkmessage(md,['number of processors should be at least 1']);
|
---|
71 | end
|
---|
72 | if isnan(cluster.np),
|
---|
73 | md = checkmessage(md,'number of processors should not be NaN!');
|
---|
74 | end
|
---|
75 | end
|
---|
76 | %}}}
|
---|
77 | function BuildQueueScript(cluster,dirname,modelname,solution,io_gather,isvalgrind,isgprof,isdakota,isoceancoupling) % {{{
|
---|
78 |
|
---|
79 | %write queuing script
|
---|
80 | %what is the executable being called?
|
---|
81 | executable='issm.exe';
|
---|
82 | if isdakota,
|
---|
83 | version=IssmConfig('_DAKOTA_VERSION_'); version=str2num(version(1:3));
|
---|
84 | if (version>=6),
|
---|
85 | executable='issm_dakota.exe';
|
---|
86 | end
|
---|
87 | end
|
---|
88 |
|
---|
89 | fid=fopen([modelname '.queue'],'w');
|
---|
90 | fprintf(fid,'#!%s\n',cluster.shell);
|
---|
91 | fprintf(fid,'mpiexec -np %i %s/%s %s %s %s \n',cluster.np,cluster.codepath,executable,solution,cluster.executionpath,modelname);
|
---|
92 | fclose(fid);
|
---|
93 |
|
---|
94 | %in interactive mode, create a run file, and errlog and outlog file
|
---|
95 | if cluster.interactive,
|
---|
96 | fid=fopen([modelname '.run'],'w');
|
---|
97 | if cluster.interactive==10,
|
---|
98 | fprintf(fid,'module unload mpi-mvapich2/1.4.1/gcc\n');
|
---|
99 | fprintf(fid,'mpiexec -np %i %s/%s %s %s %s\n',cluster.np,cluster.codepath,executable,solution,[pwd() '/run'],modelname);
|
---|
100 | else
|
---|
101 | if ~isvalgrind,
|
---|
102 | fprintf(fid,'mpiexec -np %i %s/%s %s %s %s\n',cluster.np,cluster.codepath,executable,solution,cluster.executionpath,modelname);
|
---|
103 | %fprintf(fid,'mpiexec -np %i %s/%s %s %s %s\n',cluster.nprocs(),cluster.codepath,executable,solution,[cluster.executionpath '/Interactive' num2str(cluster.interactive)],modelname);
|
---|
104 | else
|
---|
105 | fprintf(fid,'mpiexec -np %i valgrind --leak-check=full %s/%s %s %s %s\n',cluster.np,cluster.codepath,executable,solution,[cluster.executionpath '/Interactive' num2str(cluster.interactive)],modelname);
|
---|
106 | end
|
---|
107 | end
|
---|
108 | if ~io_gather, %concatenate the output files:
|
---|
109 | fprintf(fid,'cat %s.outbin.* > %s.outbin',modelname,modelname);
|
---|
110 | end
|
---|
111 | fclose(fid);
|
---|
112 |
|
---|
113 | fid=fopen([modelname '.errlog'],'w'); fclose(fid);
|
---|
114 | fid=fopen([modelname '.outlog'],'w'); fclose(fid);
|
---|
115 | end
|
---|
116 | end
|
---|
117 | %}}}
|
---|
118 | function BuildQueueScriptMultipleModels(cluster,dirname,modelname,solution,dirnames,modelnames,nps) % {{{
|
---|
119 |
|
---|
120 | %some checks:
|
---|
121 | if isempty(modelname), error('BuildQueueScriptMultipleModels error message: need a non empty model name!');end
|
---|
122 |
|
---|
123 | %what is the executable being called?
|
---|
124 | executable='issm_slc.exe';
|
---|
125 |
|
---|
126 | if ispc & ~ismingw, error('BuildQueueScriptMultipleModels not support yet on windows machines');end;
|
---|
127 |
|
---|
128 | %write queuing script
|
---|
129 | fid=fopen([modelname '.queue'],'w');
|
---|
130 |
|
---|
131 | fprintf(fid,'#!%s\n',cluster.shell);
|
---|
132 |
|
---|
133 | %number of cpus:
|
---|
134 | mpistring=sprintf('mpiexec -np %i ',cluster.np);
|
---|
135 |
|
---|
136 | %executable:
|
---|
137 | mpistring=[mpistring sprintf('%s/%s ',cluster.codepath,executable)];
|
---|
138 |
|
---|
139 | %solution name:
|
---|
140 | mpistring=[mpistring sprintf('%s ',solution)];
|
---|
141 |
|
---|
142 | %execution directory and model name:
|
---|
143 | mpistring=[mpistring sprintf('%s/%s %s',cluster.executionpath,dirname,modelname)];
|
---|
144 |
|
---|
145 | %inform main executable of how many icecaps, glaciers and earth models are being run:
|
---|
146 | mpistring=[mpistring sprintf(' %i ',length(dirnames))];
|
---|
147 |
|
---|
148 | %icecaps, glaciers and earth location, names and number of processors associated:
|
---|
149 | for i=1:length(dirnames),
|
---|
150 | mpistring=[mpistring sprintf(' %s/%s %s %i ',cluster.executionpath,dirnames{i},modelnames{i},nps{i})];
|
---|
151 | end
|
---|
152 |
|
---|
153 | %log files:
|
---|
154 | if ~cluster.interactive,
|
---|
155 | mpistring=[mpistring sprintf('2> %s.errlog> %s.outlog',modelname,modelname)];
|
---|
156 | end
|
---|
157 |
|
---|
158 | %write this long string to disk:
|
---|
159 | fprintf(fid,mpistring);
|
---|
160 | fclose(fid);
|
---|
161 |
|
---|
162 | %in interactive mode, create a run file, and errlog and outlog file
|
---|
163 | if cluster.interactive,
|
---|
164 | fid=fopen([modelname '.errlog'],'w'); fclose(fid);
|
---|
165 | fid=fopen([modelname '.outlog'],'w'); fclose(fid);
|
---|
166 | end
|
---|
167 | end
|
---|
168 | %}}}
|
---|
169 | function BuildQueueScriptIceOcean(cluster,dirname,modelname,solution,io_gather,isvalgrind,isgprof,isdakota) % {{{
|
---|
170 |
|
---|
171 | %write queuing script
|
---|
172 | %what is the executable being called?
|
---|
173 | executable='issm_ocean.exe';
|
---|
174 |
|
---|
175 | fid=fopen([modelname '.queue'],'w');
|
---|
176 | fprintf(fid,'#!%s\n',cluster.shell);
|
---|
177 | fprintf(fid,'mpiexec -np %i %s/%s %s %s %s : -np %i ./mitgcmuv\n',cluster.np,cluster.codepath,executable,solution,cluster.executionpath,modelname,cluster.npocean);
|
---|
178 | fclose(fid);
|
---|
179 |
|
---|
180 | %in interactive mode, create a run file, and errlog and outlog file
|
---|
181 | if cluster.interactive,
|
---|
182 | fid=fopen([modelname '.errlog'],'w'); fclose(fid);
|
---|
183 | fid=fopen([modelname '.outlog'],'w'); fclose(fid);
|
---|
184 | end
|
---|
185 | end
|
---|
186 | %}}}
|
---|
187 | function BuildKrigingQueueScript(cluster,modelname,solution,io_gather,isvalgrind,isgprof) % {{{
|
---|
188 |
|
---|
189 | %write queuing script
|
---|
190 | if ~ispc,
|
---|
191 |
|
---|
192 | fid=fopen([modelname '.queue'],'w');
|
---|
193 | fprintf(fid,'#!/bin/sh\n');
|
---|
194 | if ~isvalgrind,
|
---|
195 | if cluster.interactive
|
---|
196 | fprintf(fid,'mpiexec -np %i %s/kriging.exe %s %s ',cluster.np,cluster.codepath,[cluster.executionpath '/' modelname],modelname);
|
---|
197 | else
|
---|
198 | 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);
|
---|
199 | end
|
---|
200 | elseif isgprof,
|
---|
201 | fprintf(fid,'\n gprof %s/kriging.exe gmon.out > %s.performance',cluster.codepath,modelname);
|
---|
202 | else
|
---|
203 | %Add --gen-suppressions=all to get suppression lines
|
---|
204 | fprintf(fid,'LD_PRELOAD=%s \\\n',cluster.valgrindlib);
|
---|
205 | fprintf(fid,'mpiexec -np %i %s --leak-check=full --suppressions=%s %s/kriging.exe %s %s 2> %s.errlog >%s.outlog ',...
|
---|
206 | cluster.np,cluster.valgrind,cluster.valgrindsup,cluster.codepath,[cluster.executionpath '/' modelname],modelname,modelname,modelname);
|
---|
207 | end
|
---|
208 | if ~io_gather, %concatenate the output files:
|
---|
209 | fprintf(fid,'\ncat %s.outbin.* > %s.outbin',modelname,modelname);
|
---|
210 | end
|
---|
211 | fclose(fid);
|
---|
212 |
|
---|
213 | else % Windows
|
---|
214 |
|
---|
215 | fid=fopen([modelname '.bat'],'w');
|
---|
216 | fprintf(fid,'@echo off\n');
|
---|
217 | if cluster.interactive
|
---|
218 | fprintf(fid,'"%s/issm.exe" %s "%s" %s ',cluster.codepath,solution,[cluster.executionpath '/' modelname],modelname);
|
---|
219 | else
|
---|
220 | fprintf(fid,'"%s/issm.exe" %s "%s" %s 2> %s.errlog >%s.outlog',...
|
---|
221 | cluster.codepath,solution,[cluster.executionpath '/' modelname],modelname,modelname,modelname);
|
---|
222 | end
|
---|
223 | fclose(fid);
|
---|
224 | end
|
---|
225 |
|
---|
226 | %in interactive mode, create a run file, and errlog and outlog file
|
---|
227 | if cluster.interactive,
|
---|
228 | fid=fopen([modelname '.errlog'],'w'); fclose(fid);
|
---|
229 | fid=fopen([modelname '.outlog'],'w'); fclose(fid);
|
---|
230 | end
|
---|
231 | end
|
---|
232 | %}}}
|
---|
233 | function UploadQueueJob(cluster,modelname,dirname,filelist)% {{{
|
---|
234 | if ~ispc | ismingw,
|
---|
235 |
|
---|
236 | %compress the files into one zip.
|
---|
237 | compressstring=['tar -zcf ' dirname '.tar.gz '];
|
---|
238 | for i=1:numel(filelist),
|
---|
239 | compressstring = [compressstring ' ' filelist{i}];
|
---|
240 | end
|
---|
241 | if cluster.interactive,
|
---|
242 | compressstring = [compressstring ' ' modelname '.run ' modelname '.errlog ' modelname '.outlog '];
|
---|
243 | end
|
---|
244 | system(compressstring);
|
---|
245 |
|
---|
246 | if cluster.verbose, disp('uploading input file and queuing script'); end
|
---|
247 | issmscpout(cluster.name,cluster.executionpath,cluster.login,cluster.port,{[dirname '.tar.gz']});
|
---|
248 | end
|
---|
249 | end %}}}
|
---|
250 | function LaunchQueueJob(cluster,modelname,dirname,filelist,restart,batch)% {{{
|
---|
251 |
|
---|
252 | %figure out what shell extension we will use:
|
---|
253 | if isempty(strfind(cluster.shell,'csh')),
|
---|
254 | shellext='sh';
|
---|
255 | else
|
---|
256 | shellext='csh';
|
---|
257 | end
|
---|
258 |
|
---|
259 | if cluster.verbose, disp('launching solution sequence on remote cluster'); end
|
---|
260 |
|
---|
261 | launchcommand=['cd ' cluster.executionpath ' && rm -rf *.lock && rm -rf ADOLC* && tar -zxf ' dirname '.tar.gz && rm -rf *.tar.gz'];
|
---|
262 | issmssh(cluster.name,cluster.login,cluster.port,launchcommand);
|
---|
263 |
|
---|
264 | end %}}}
|
---|
265 | function LaunchQueueJobIceOcean(cluster,modelname,dirname,filelist,restart,batch)% {{{
|
---|
266 |
|
---|
267 | %figure out what shell extension we will use:
|
---|
268 | if isempty(strfind(cluster.shell,'csh')),
|
---|
269 | shellext='sh';
|
---|
270 | else
|
---|
271 | shellext='csh';
|
---|
272 | end
|
---|
273 |
|
---|
274 | if cluster.verbose, disp('launching solution sequence on remote cluster'); end
|
---|
275 |
|
---|
276 | launchcommand=['cd ' cluster.executionpath ' && rm -rf *.lock && tar -zxf ' dirname '.tar.gz && rm -rf *.tar.gz'];
|
---|
277 | issmssh(cluster.name,cluster.login,cluster.port,launchcommand);
|
---|
278 |
|
---|
279 | end %}}}
|
---|
280 | function Download(cluster,dirname,filelist)% {{{
|
---|
281 |
|
---|
282 | if ispc && ~ismingw,
|
---|
283 | %do nothing
|
---|
284 | return;
|
---|
285 | end
|
---|
286 |
|
---|
287 | %copy files from cluster to current directory
|
---|
288 | issmscpin(cluster.name,cluster.login,cluster.port,cluster.executionpath,filelist);
|
---|
289 | end %}}}
|
---|
290 | end
|
---|
291 | end
|
---|