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
|
---|
30 | if ispc,
|
---|
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(' port: %i',cluster.port));
|
---|
56 | disp(sprintf(' codepath: %s',cluster.codepath));
|
---|
57 | disp(sprintf(' executionpath: %s',cluster.executionpath));
|
---|
58 | disp(sprintf(' etcpath: %s',cluster.etcpath));
|
---|
59 | disp(sprintf(' valgrind: %s',cluster.valgrind));
|
---|
60 | disp(sprintf(' valgrindlib: %s',cluster.valgrindlib));
|
---|
61 | disp(sprintf(' valgrindsup: %s',cluster.valgrindsup));
|
---|
62 | disp(sprintf(' verbose: %s',cluster.verbose));
|
---|
63 | disp(sprintf(' shell: %s',cluster.shell));
|
---|
64 | end
|
---|
65 | %}}}
|
---|
66 | function md = checkconsistency(cluster,md,solution,analyses) % {{{
|
---|
67 | if cluster.np<1
|
---|
68 | md = checkmessage(md,['number of processors should be at least 1']);
|
---|
69 | end
|
---|
70 | if isnan(cluster.np),
|
---|
71 | md = checkmessage(md,'number of processors should not be NaN!');
|
---|
72 | end
|
---|
73 | end
|
---|
74 | %}}}
|
---|
75 | function BuildQueueScript(cluster,dirname,modelname,solution,io_gather,isvalgrind,isgprof,isdakota,isoceancoupling) % {{{
|
---|
76 |
|
---|
77 | %write queuing script
|
---|
78 | %what is the executable being called?
|
---|
79 | executable='issm.exe';
|
---|
80 | if isdakota,
|
---|
81 | version=IssmConfig('_DAKOTA_VERSION_'); version=str2num(version(1:3));
|
---|
82 | if (version>=6),
|
---|
83 | executable='issm_dakota.exe';
|
---|
84 | end
|
---|
85 | end
|
---|
86 |
|
---|
87 | fid=fopen([modelname '.queue'],'w');
|
---|
88 | fprintf(fid,'#!%s\n',cluster.shell);
|
---|
89 | fprintf(fid,'mpiexec -np %i %s/%s %s %s %s \n',cluster.np,cluster.codepath,executable,solution,cluster.executionpath,modelname);
|
---|
90 | fclose(fid);
|
---|
91 |
|
---|
92 |
|
---|
93 | %in interactive mode, create a run file, and errlog and outlog file
|
---|
94 | if cluster.interactive,
|
---|
95 | fid=fopen([modelname '.errlog'],'w'); fclose(fid);
|
---|
96 | fid=fopen([modelname '.outlog'],'w'); fclose(fid);
|
---|
97 | end
|
---|
98 | end
|
---|
99 | %}}}
|
---|
100 | function BuildQueueScriptMultipleModels(cluster,dirname,modelname,solution,dirnames,modelnames,nps) % {{{
|
---|
101 |
|
---|
102 | %some checks:
|
---|
103 | if isempty(modelname), error('BuildQueueScriptMultipleModels error message: need a non empty model name!');end
|
---|
104 |
|
---|
105 | %what is the executable being called?
|
---|
106 | executable='issm_slr.exe';
|
---|
107 |
|
---|
108 | if ispc(), error('BuildQueueScriptMultipleModels not support yet on windows machines');end;
|
---|
109 |
|
---|
110 | %write queuing script
|
---|
111 | fid=fopen([modelname '.queue'],'w');
|
---|
112 |
|
---|
113 | fprintf(fid,'#!%s\n',cluster.shell);
|
---|
114 |
|
---|
115 | %number of cpus:
|
---|
116 | mpistring=sprintf('mpiexec -np %i ',cluster.np);
|
---|
117 |
|
---|
118 | %executable:
|
---|
119 | mpistring=[mpistring sprintf('%s/%s ',cluster.codepath,executable)];
|
---|
120 |
|
---|
121 | %solution name:
|
---|
122 | mpistring=[mpistring sprintf('%s ',solution)];
|
---|
123 |
|
---|
124 | %execution directory and model name:
|
---|
125 | mpistring=[mpistring sprintf('%s/%s %s',cluster.executionpath,dirname,modelname)];
|
---|
126 |
|
---|
127 | %inform main executable of how many icecaps, glaciers and earth models are being run:
|
---|
128 | mpistring=[mpistring sprintf(' %i ',length(dirnames))];
|
---|
129 |
|
---|
130 | %icecaps, glaciers and earth location, names and number of processors associated:
|
---|
131 | for i=1:length(dirnames),
|
---|
132 | mpistring=[mpistring sprintf(' %s/%s %s %i ',cluster.executionpath,dirnames{i},modelnames{i},nps{i})];
|
---|
133 | end
|
---|
134 |
|
---|
135 | %log files:
|
---|
136 | if ~cluster.interactive,
|
---|
137 | mpistring=[mpistring sprintf('2> %s.errlog> %s.outlog',modelname,modelname)];
|
---|
138 | end
|
---|
139 |
|
---|
140 | %write this long string to disk:
|
---|
141 | fprintf(fid,mpistring);
|
---|
142 | fclose(fid);
|
---|
143 |
|
---|
144 | %in interactive mode, create a run file, and errlog and outlog file
|
---|
145 | if cluster.interactive,
|
---|
146 | fid=fopen([modelname '.errlog'],'w'); fclose(fid);
|
---|
147 | fid=fopen([modelname '.outlog'],'w'); fclose(fid);
|
---|
148 | end
|
---|
149 | end
|
---|
150 | %}}}
|
---|
151 | function BuildQueueScriptIceOcean(cluster,dirname,modelname,solution,io_gather,isvalgrind,isgprof,isdakota) % {{{
|
---|
152 |
|
---|
153 | %write queuing script
|
---|
154 | %what is the executable being called?
|
---|
155 | executable='issm_ocean.exe';
|
---|
156 |
|
---|
157 | fid=fopen([modelname '.queue'],'w');
|
---|
158 | fprintf(fid,'#!%s\n',cluster.shell);
|
---|
159 | 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);
|
---|
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 BuildKrigingQueueScript(cluster,modelname,solution,io_gather,isvalgrind,isgprof) % {{{
|
---|
170 |
|
---|
171 | %write queuing script
|
---|
172 | if ~ispc(),
|
---|
173 |
|
---|
174 | fid=fopen([modelname '.queue'],'w');
|
---|
175 | fprintf(fid,'#!/bin/sh\n');
|
---|
176 | if ~isvalgrind,
|
---|
177 | if cluster.interactive
|
---|
178 | fprintf(fid,'mpiexec -np %i %s/kriging.exe %s %s ',cluster.np,cluster.codepath,[cluster.executionpath '/' modelname],modelname);
|
---|
179 | else
|
---|
180 | 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);
|
---|
181 | end
|
---|
182 | elseif isgprof,
|
---|
183 | fprintf(fid,'\n gprof %s/kriging.exe gmon.out > %s.performance',cluster.codepath,modelname);
|
---|
184 | else
|
---|
185 | %Add --gen-suppressions=all to get suppression lines
|
---|
186 | fprintf(fid,'LD_PRELOAD=%s \\\n',cluster.valgrindlib);
|
---|
187 | fprintf(fid,'mpiexec -np %i %s --leak-check=full --suppressions=%s %s/kriging.exe %s %s 2> %s.errlog >%s.outlog ',...
|
---|
188 | cluster.np,cluster.valgrind,cluster.valgrindsup,cluster.codepath,[cluster.executionpath '/' modelname],modelname,modelname,modelname);
|
---|
189 | end
|
---|
190 | if ~io_gather, %concatenate the output files:
|
---|
191 | fprintf(fid,'\ncat %s.outbin.* > %s.outbin',modelname,modelname);
|
---|
192 | end
|
---|
193 | fclose(fid);
|
---|
194 |
|
---|
195 | else % Windows
|
---|
196 |
|
---|
197 | fid=fopen([modelname '.bat'],'w');
|
---|
198 | fprintf(fid,'@echo off\n');
|
---|
199 | if cluster.interactive
|
---|
200 | fprintf(fid,'"%s/issm.exe" %s "%s" %s ',cluster.codepath,solution,[cluster.executionpath '/' modelname],modelname);
|
---|
201 | else
|
---|
202 | fprintf(fid,'"%s/issm.exe" %s "%s" %s 2> %s.errlog >%s.outlog',...
|
---|
203 | cluster.codepath,solution,[cluster.executionpath '/' modelname],modelname,modelname,modelname);
|
---|
204 | end
|
---|
205 | fclose(fid);
|
---|
206 | end
|
---|
207 |
|
---|
208 | %in interactive mode, create a run file, and errlog and outlog file
|
---|
209 | if cluster.interactive,
|
---|
210 | fid=fopen([modelname '.errlog'],'w'); fclose(fid);
|
---|
211 | fid=fopen([modelname '.outlog'],'w'); fclose(fid);
|
---|
212 | end
|
---|
213 | end
|
---|
214 | %}}}
|
---|
215 | function UploadQueueJob(cluster,modelname,dirname,filelist)% {{{
|
---|
216 | if ~ispc,
|
---|
217 |
|
---|
218 | %compress the files into one zip.
|
---|
219 | compressstring=['tar -zcf ' dirname '.tar.gz '];
|
---|
220 | for i=1:numel(filelist),
|
---|
221 | compressstring = [compressstring ' ' filelist{i}];
|
---|
222 | end
|
---|
223 | if cluster.interactive,
|
---|
224 | compressstring = [compressstring ' ' modelname '.errlog ' modelname '.outlog '];
|
---|
225 | end
|
---|
226 | system(compressstring);
|
---|
227 |
|
---|
228 | if cluster.verbose, disp('uploading input file and queueing script'); end
|
---|
229 | issmscpout(cluster.name,cluster.executionpath,cluster.login,cluster.port,{[dirname '.tar.gz']});
|
---|
230 | end
|
---|
231 | end %}}}
|
---|
232 | function LaunchQueueJob(cluster,modelname,dirname,filelist,restart,batch)% {{{
|
---|
233 |
|
---|
234 | %figure out what shell extension we will use:
|
---|
235 | if isempty(strfind(cluster.shell,'csh')),
|
---|
236 | shellext='sh';
|
---|
237 | else
|
---|
238 | shellext='csh';
|
---|
239 | end
|
---|
240 |
|
---|
241 | if cluster.verbose, disp('launching solution sequence on remote cluster'); end
|
---|
242 |
|
---|
243 | launchcommand=['cd ' cluster.executionpath ' && rm -rf *.lock && rm -rf ADOLC* && tar -zxf ' dirname '.tar.gz && rm -rf *.tar.gz'];
|
---|
244 | issmssh(cluster.name,cluster.login,cluster.port,launchcommand);
|
---|
245 |
|
---|
246 | end %}}}
|
---|
247 | function LaunchQueueJobIceOcean(cluster,modelname,dirname,filelist,restart,batch)% {{{
|
---|
248 |
|
---|
249 | %figure out what shell extension we will use:
|
---|
250 | if isempty(strfind(cluster.shell,'csh')),
|
---|
251 | shellext='sh';
|
---|
252 | else
|
---|
253 | shellext='csh';
|
---|
254 | end
|
---|
255 |
|
---|
256 | if cluster.verbose, disp('launching solution sequence on remote cluster'); end
|
---|
257 |
|
---|
258 | launchcommand=['cd ' cluster.executionpath ' && rm -rf *.lock && tar -zxf ' dirname '.tar.gz && rm -rf *.tar.gz'];
|
---|
259 | issmssh(cluster.name,cluster.login,cluster.port,launchcommand);
|
---|
260 |
|
---|
261 | end %}}}
|
---|
262 | function Download(cluster,dirname,filelist)% {{{
|
---|
263 |
|
---|
264 | if ispc(),
|
---|
265 | %do nothing
|
---|
266 | return;
|
---|
267 | end
|
---|
268 |
|
---|
269 | %copy files from cluster to current directory
|
---|
270 | issmscpin(cluster.name,cluster.login,cluster.port,cluster.executionpath,filelist);
|
---|
271 | end %}}}
|
---|
272 | end
|
---|
273 | end
|
---|