source: issm/trunk/src/m/classes/clusters/generic.m@ 26744

Last change on this file since 26744 was 26744, checked in by Mathieu Morlighem, 3 years ago

merged trunk-jpl and trunk for revision 26742

File size: 14.4 KB
Line 
1%GENERIC cluster class definition
2%
3% Usage:
4% cluster=generic('name','astrid','np',3);
5% cluster=generic('name',oshostname(),'np',3,'login','username');
6%
7% TODO:
8% - Add support for restart to Windows (under MSYS2), then activate tests 125
9% and 126 in test suite
10%
11
12classdef generic
13 properties (SetAccess=public)
14 % {{{
15 name = '';
16 login = '';
17 np = 1;
18 npocean = 1;
19 port = 0;
20 interactive = 1;
21 codepath = [IssmConfig('ISSM_PREFIX') '/bin'];
22 etcpath = [issmdir() '/etc'];
23 executionpath = [issmdir() '/execution'];
24 valgrind = [issmdir() '/externalpackages/valgrind/install/bin/valgrind'];
25 valgrindlib = [issmdir() '/externalpackages/valgrind/install/lib/libmpidebug.so'];
26 valgrindsup = [issmdir() '/externalpackages/valgrind/issm.supp'];
27 verbose = 1;
28 shell = '/bin/sh';
29 %}}}
30 end
31 methods
32 function cluster=generic(varargin) % {{{
33
34 %Change the defaults if ispc
35 if ispc & ~ismingw,
36 cluster.codepath = [issmdir() '\bin'];
37 cluster.etcpath = [issmdir() '\etc'];
38 cluster.executionpath = [issmdir() '\execution'];
39 end
40
41 %use provided options to change fields
42 options=pairoptions(varargin{:});
43
44 %get name
45 cluster.name=getfieldvalue(options,'name',oshostname());
46
47 %initialize cluster using user settings if provided
48 if (exist([cluster.name '_settings'])==2), eval([cluster.name '_settings']); end
49
50 %OK get other fields
51 cluster=AssignObjectFields(pairoptions(varargin{:}),cluster);
52 end
53 %}}}
54 function disp(cluster) % {{{
55 % display the object
56 disp(sprintf('class ''%s'' object ''%s'' = ',class(cluster),inputname(1)));
57 disp(sprintf(' name: %s',cluster.name));
58 disp(sprintf(' login: %s',cluster.login));
59 disp(sprintf(' np: %i',cluster.np));
60 disp(sprintf(' npocean: %i',cluster.npocean));
61 disp(sprintf(' port: %i',cluster.port));
62 disp(sprintf(' codepath: %s',cluster.codepath));
63 disp(sprintf(' executionpath: %s',cluster.executionpath));
64 disp(sprintf(' etcpath: %s',cluster.etcpath));
65 disp(sprintf(' valgrind: %s',cluster.valgrind));
66 disp(sprintf(' valgrindlib: %s',cluster.valgrindlib));
67 disp(sprintf(' valgrindsup: %s',cluster.valgrindsup));
68 disp(sprintf(' verbose: %s',cluster.verbose));
69 disp(sprintf(' shell: %s',cluster.shell));
70 end
71 %}}}
72 function numprocs=nprocs(cluster) % {{{
73 numprocs=cluster.np;
74 end
75 %}}}
76 function md = checkconsistency(cluster,md,solution,analyses) % {{{
77 if cluster.np<1
78 md = checkmessage(md,['number of processors should be at least 1']);
79 end
80 if isnan(cluster.np),
81 md = checkmessage(md,'number of processors should not be NaN!');
82 end
83 end
84 %}}}
85 function BuildQueueScript(cluster,dirname,modelname,solution,io_gather,isvalgrind,isgprof,isdakota,isoceancoupling) % {{{
86 % Which executable are we calling?
87 executable='issm.exe'; % default
88
89 if isdakota,
90 version=IssmConfig('_DAKOTA_VERSION_');
91 version=str2num(version(1:3));
92 if (version>=6),
93 executable='issm_dakota.exe';
94 end
95 end
96 if isoceancoupling,
97 executable='issm_ocean.exe';
98 end
99
100 if ~ispc(),
101 fid=fopen([modelname '.queue'],'w');
102 fprintf(fid,'#!%s\n',cluster.shell);
103 if ~isvalgrind,
104 if cluster.interactive
105 if IssmConfig('_HAVE_MPI_'),
106 fprintf(fid,'mpiexec -np %i %s/%s %s %s %s\n',cluster.np,cluster.codepath,executable,solution,[cluster.executionpath '/' dirname],modelname);
107 else
108 fprintf(fid,'%s/%s %s %s %s',cluster.codepath,executable,solution,[cluster.executionpath '/' dirname],modelname);
109 end
110 else
111 if IssmConfig('_HAVE_MPI_'),
112 fprintf(fid,'mpiexec -np %i %s/%s %s %s %s 2> %s.errlog > %s.outlog &',cluster.np,cluster.codepath,executable,solution,[cluster.executionpath '/' dirname],modelname,modelname,modelname);
113 else
114 fprintf(fid,'%s/%s %s %s %s 2> %s.errlog > %s.outlog &',cluster.codepath,executable,solution,[cluster.executionpath '/' dirname],modelname,modelname,modelname);
115 end
116 end
117 elseif isgprof,
118 fprintf(fid,'\n gprof %s/issm.exe gmon.out > %s.performance',cluster.codepath,modelname);
119 else
120 %Add --gen-suppressions=all to get suppression lines
121 %fprintf(fid,'LD_PRELOAD=%s \\\n',cluster.valgrindlib); it could be deleted
122 if ismac,
123 if IssmConfig('_HAVE_MPI_'),
124 fprintf(fid,'mpiexec -np %i %s --leak-check=full --error-limit=no --dsymutil=yes --suppressions=%s %s/%s %s %s %s 2> %s.errlog > %s.outlog ',...
125 cluster.np,cluster.valgrind,cluster.valgrindsup,cluster.codepath,executable,solution,[cluster.executionpath '/' dirname], modelname,modelname,modelname);
126 else
127 fprintf(fid,'%s --leak-check=full --dsymutil=yes --error-limit=no --suppressions=%s %s/%s %s %s %s 2> %s.errlog > %s.outlog',...
128 cluster.valgrind,cluster.valgrindsup,cluster.codepath,executable,solution,[cluster.executionpath '/' dirname], modelname,modelname,modelname);
129 end
130 else
131 if IssmConfig('_HAVE_MPI_'),
132 fprintf(fid,'mpiexec -np %i %s --leak-check=full --error-limit=no --suppressions=%s %s/%s %s %s %s 2> %s.errlog > %s.outlog',...
133 cluster.np,cluster.valgrind,cluster.valgrindsup,cluster.codepath,executable,solution,[cluster.executionpath '/' dirname],modelname,modelname,modelname);
134 else
135 fprintf(fid,'%s --leak-check=full --error-limit=no --suppressions=%s %s/%s %s %s %s 2> %s.errlog > %s.outlog',...
136 cluster.valgrind,cluster.valgrindsup,cluster.codepath,executable,solution,[cluster.executionpath '/' dirname],modelname,modelname,modelname);
137 end
138 end
139 end
140 if ~io_gather, %concatenate the output files:
141 fprintf(fid,'\ncat %s.outbin.* > %s.outbin',modelname,modelname);
142 end
143 fclose(fid);
144
145 else % Windows
146
147 fid=fopen([modelname '.bat'],'w');
148 fprintf(fid,'@echo off\n');
149
150 % if IssmConfig('_HAVE_PETSC_MPI_'),
151 % warning('parallel runs not allowed yet in Windows. Defaulting to 1 cpus');
152 % cluster.np=1;
153 % end
154
155 if cluster.np>1,
156 % fprintf(fid,'"C:\\Program Files\\MPICH2\\bin\\mpiexec.exe" -n %i "%s/%s" %s ./ %s',cluster.np,cluster.codepath,executable,solution,modelname);
157 fprintf(fid,'"C:\\Program Files\\Microsoft MPI\\Bin\\mpiexec.exe" -n %i "%s/%s" %s ./ %s',cluster.np,cluster.codepath,executable,solution,modelname);
158 else
159 fprintf(fid,'"%s/%s" %s ./ %s',cluster.codepath,executable,solution,modelname);
160 end
161 fclose(fid);
162 end
163
164 %in interactive mode, create a run file, and errlog and outlog file
165 if cluster.interactive,
166 fid=fopen([modelname '.errlog'],'w'); fclose(fid);
167 fid=fopen([modelname '.outlog'],'w'); fclose(fid);
168 end
169 end
170 %}}}
171 function BuildQueueScriptMultipleModels(cluster,dirname,modelname,solution,dirnames,modelnames,nps) % {{{
172
173 %some checks:
174 if isempty(modelname), error('BuildQueueScriptMultipleModels error message: need a non empty model name!');end
175
176 %what is the executable being called?
177 executable='issm_slc.exe';
178
179 if ispc(), error('BuildQueueScriptMultipleModels not support yet on windows machines');end;
180
181 %write queuing script
182 fid=fopen([modelname '.queue'],'w');
183
184 fprintf(fid,'#!%s\n',cluster.shell);
185
186 %number of cpus:
187 mpistring=sprintf('mpiexec -np %i ',cluster.np);
188
189 %executable:
190 mpistring=[mpistring sprintf('%s/%s ',cluster.codepath,executable)];
191
192 %solution name:
193 mpistring=[mpistring sprintf('%s ',solution)];
194
195 %execution directory and model name:
196 mpistring=[mpistring sprintf('%s/%s %s',cluster.executionpath,dirname,modelname)];
197
198 %inform main executable of how many icecaps, glaciers and earth models are being run:
199 mpistring=[mpistring sprintf(' %i ',length(dirnames))];
200
201 %icecaps, glaciers and earth location, names and number of processors associated:
202 for i=1:length(dirnames),
203 mpistring=[mpistring sprintf(' %s/%s %s %i ',cluster.executionpath,dirnames{i},modelnames{i},nps{i})];
204 end
205
206 %log files:
207 if ~cluster.interactive,
208 mpistring=[mpistring sprintf('2> %s.errlog> %s.outlog',modelname,modelname)];
209 end
210
211 %write this long string to disk:
212 fprintf(fid,mpistring);
213 fclose(fid);
214
215 %in interactive mode, create a run file, and errlog and outlog file
216 if cluster.interactive,
217 fid=fopen([modelname '.errlog'],'w'); fclose(fid);
218 fid=fopen([modelname '.outlog'],'w'); fclose(fid);
219 end
220 end
221 %}}}
222 function BuildQueueScriptIceOcean(cluster,dirname,modelname,solution,io_gather,isvalgrind,isgprof,isdakota) % {{{
223
224 %write queuing script
225 %what is the executable being called?
226 executable='issm_ocean.exe';
227
228 fid=fopen([modelname '.queue'],'w');
229 fprintf(fid,'#!%s\n',cluster.shell);
230 if ~isvalgrind,
231 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);
232
233 else
234 fprintf(fid,'mpiexec -np %i %s --leak-check=full --error-limit=no --dsymutil=yes --suppressions=%s %s/%s %s %s %s : -np %i ./mitgcmuv\n',...
235 cluster.np,cluster.valgrind,cluster.valgrindsup,cluster.codepath,executable,solution,cluster.executionpath,modelname,cluster.npocean);
236 end
237 fclose(fid);
238
239 %in interactive mode, create a run file, and errlog and outlog file
240 if cluster.interactive,
241 fid=fopen([modelname '.errlog'],'w'); fclose(fid);
242 fid=fopen([modelname '.outlog'],'w'); fclose(fid);
243 end
244 end
245 %}}}
246 function BuildKrigingQueueScript(cluster,modelname,solution,io_gather,isvalgrind,isgprof) % {{{
247
248 %write queuing script
249 if ~ispc(),
250
251 fid=fopen([modelname '.queue'],'w');
252 fprintf(fid,'#!/bin/sh\n');
253 if ~isvalgrind,
254 if cluster.interactive
255 fprintf(fid,'mpiexec -np %i %s/kriging.exe %s %s ',cluster.np,cluster.codepath,[cluster.executionpath '/' modelname],modelname);
256 else
257 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);
258 end
259 elseif isgprof,
260 fprintf(fid,'\n gprof %s/kriging.exe gmon.out > %s.performance',cluster.codepath,modelname);
261 else
262 %Add --gen-suppressions=all to get suppression lines
263 %fprintf(fid,'LD_PRELOAD=%s \\\n',cluster.valgrindlib); it could be deleted
264 fprintf(fid,'mpiexec -np %i %s --leak-check=full --suppressions=%s %s/kriging.exe %s %s 2> %s.errlog >%s.outlog ',...
265 cluster.np,cluster.valgrind,cluster.valgrindsup,cluster.codepath,[cluster.executionpath '/' modelname],modelname,modelname,modelname);
266 end
267 if ~io_gather, %concatenate the output files:
268 fprintf(fid,'\ncat %s.outbin.* > %s.outbin',modelname,modelname);
269 end
270 fclose(fid);
271
272 else % Windows
273
274 fid=fopen([modelname '.bat'],'w');
275 fprintf(fid,'@echo off\n');
276 if cluster.interactive
277 fprintf(fid,'"%s/issm.exe" %s "%s" %s ',cluster.codepath,solution,[cluster.executionpath '/' modelname],modelname);
278 else
279 fprintf(fid,'"%s/issm.exe" %s "%s" %s 2> %s.errlog >%s.outlog',...
280 cluster.codepath,solution,[cluster.executionpath '/' modelname],modelname,modelname,modelname);
281 end
282 fclose(fid);
283 end
284
285 %in interactive mode, create a run file, and errlog and outlog file
286 if cluster.interactive,
287 fid=fopen([modelname '.errlog'],'w'); fclose(fid);
288 fid=fopen([modelname '.outlog'],'w'); fclose(fid);
289 end
290 end
291 %}}}
292 function UploadQueueJob(cluster,modelname,dirname,filelist) % {{{
293
294 if ~ispc,
295
296 %compress the files into one zip.
297 compressstring=['tar -zcf ' dirname '.tar.gz '];
298 for i=1:numel(filelist),
299 if ~exist(filelist{i},'file')
300 error(['File ' filelist{i} ' not found']);
301 end
302 compressstring = [compressstring ' ' filelist{i}];
303 end
304 if cluster.interactive,
305 compressstring = [compressstring ' ' modelname '.errlog ' modelname '.outlog '];
306 end
307 system(compressstring);
308
309 if cluster.verbose, disp('uploading input file and queueing script'); end
310 issmscpout(cluster.name,cluster.executionpath,cluster.login,cluster.port,{[dirname '.tar.gz']});
311 end
312 end %}}}
313 function LaunchQueueJob(cluster,modelname,dirname,filelist,restart,batch) % {{{
314
315 if ~ispc,
316 %figure out what shell extension we will use:
317 if isempty(strfind(cluster.shell,'csh')),
318 shellext='sh';
319 else
320 shellext='csh';
321 end
322
323 if cluster.verbose, disp('launching solution sequence on remote cluster'); end
324
325 if ~isempty(restart)
326 launchcommand=['source ' cluster.etcpath '/environment.' shellext ' && cd ' cluster.executionpath ' && cd ' dirname ' && source ' modelname '.queue '];
327 else
328 if ~batch,
329 launchcommand=['source ' cluster.etcpath '/environment.' shellext ' && cd ' cluster.executionpath ' && rm -rf ./' dirname ' && mkdir ' dirname ...
330 ' && cd ' dirname ' && mv ../' dirname '.tar.gz ./ && tar -zxf ' dirname '.tar.gz && source ' modelname '.queue '];
331 else
332 launchcommand=['source ' cluster.etcpath '/environment.' shellext ' && cd ' cluster.executionpath ' && rm -rf ./' dirname ' && mkdir ' dirname ...
333 ' && cd ' dirname ' && mv ../' dirname '.tar.gz ./ && tar -zxf ' dirname '.tar.gz '];
334 end
335 end
336 issmssh(cluster.name,cluster.login,cluster.port,launchcommand);
337 else
338 system([modelname '.bat']);
339 end
340
341 end %}}}
342 function LaunchQueueJobIceOcean(cluster,modelname,dirname,filelist,restart,batch) % {{{
343
344 if ~ispc,
345
346 %figure out what shell extension we will use:
347 if isempty(strfind(cluster.shell,'csh')),
348 shellext='sh';
349 else
350 shellext='csh';
351 end
352
353 if cluster.verbose, disp('launching solution sequence on remote cluster'); end
354
355 if ~isempty(restart)
356 launchcommand=['source ' cluster.etcpath '/environment.' shellext ' && cd ' cluster.executionpath ' && cd ' dirname ' && source ' modelname '.queue '];
357 else
358 if ~batch,
359 launchcommand=['source ' cluster.etcpath '/environment.' shellext ' && cd ' cluster.executionpath ' && tar -zxf ' dirname '.tar.gz && source ' modelname '.queue '];
360 else
361 launchcommand=['source ' cluster.etcpath '/environment.' shellext ' && cd ' cluster.executionpath ' && rm -rf ./' dirname ' && mkdir ' dirname ...
362 ' && cd ' dirname ' && mv ../' dirname '.tar.gz ./ && tar -zxf ' dirname '.tar.gz '];
363 end
364 end
365 issmssh(cluster.name,cluster.login,cluster.port,launchcommand);
366 else
367 system([modelname '.bat']);
368 end
369
370 end %}}}
371 function Download(cluster,dirname,filelist) % {{{
372
373 if ispc(),
374 %do nothing
375 return;
376 end
377
378 %copy files from cluster to current directory
379 directory=[cluster.executionpath '/' dirname '/'];
380 issmscpin(cluster.name,cluster.login,cluster.port,directory,filelist);
381 end %}}}
382 end
383end
Note: See TracBrowser for help on using the repository browser.