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

Last change on this file since 22758 was 22758, checked in by Mathieu Morlighem, 7 years ago

merged trunk-jpl and trunk for revision 22757

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