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 | classdef generic
|
---|
8 | properties (SetAccess=public)
|
---|
9 | % {{{
|
---|
10 | name='';
|
---|
11 | login='';
|
---|
12 | np=1;
|
---|
13 | port=0;
|
---|
14 | interactive=1;
|
---|
15 | codepath=[issmdir() '/bin'];
|
---|
16 | etcpath=[issmdir() '/etc'];
|
---|
17 | executionpath=[issmdir() '/execution'];
|
---|
18 | valgrind=[issmdir() '/externalpackages/valgrind/install/bin/valgrind'];
|
---|
19 | valgrindlib=[issmdir() '/externalpackages/valgrind/install/lib/libmpidebug.so'];
|
---|
20 | valgrindsup=[issmdir() '/externalpackages/valgrind/issm.supp'];
|
---|
21 | %}}}
|
---|
22 | end
|
---|
23 | methods
|
---|
24 | function cluster=generic(varargin) % {{{
|
---|
25 |
|
---|
26 | %use provided options to change fields
|
---|
27 | options=pairoptions(varargin{:});
|
---|
28 |
|
---|
29 | %get name
|
---|
30 | cluster.name=getfieldvalue(options,'name',oshostname());
|
---|
31 |
|
---|
32 | %initialize cluster using user settings if provided
|
---|
33 | if (exist([cluster.name '_settings'])==2), eval([cluster.name '_settings']); end
|
---|
34 |
|
---|
35 | %OK get other fields
|
---|
36 | cluster=AssignObjectFields(pairoptions(varargin{:}),cluster);
|
---|
37 | end
|
---|
38 | %}}}
|
---|
39 | function disp(cluster) % {{{
|
---|
40 | % display the object
|
---|
41 | disp(sprintf('class ''%s'' object ''%s'' = ',class(cluster),inputname(1)));
|
---|
42 | disp(sprintf(' name: %s',cluster.name));
|
---|
43 | disp(sprintf(' login: %s',cluster.login));
|
---|
44 | disp(sprintf(' np: %i',cluster.np));
|
---|
45 | disp(sprintf(' port: %i',cluster.port));
|
---|
46 | disp(sprintf(' codepath: %s',cluster.codepath));
|
---|
47 | disp(sprintf(' executionpath: %s',cluster.executionpath));
|
---|
48 | disp(sprintf(' etcpath: %s',cluster.executionpath));
|
---|
49 | disp(sprintf(' valgrind: %s',cluster.valgrind));
|
---|
50 | disp(sprintf(' valgrindlib: %s',cluster.valgrindlib));
|
---|
51 | disp(sprintf(' valgrindsup: %s',cluster.valgrindsup));
|
---|
52 | end
|
---|
53 | %}}}
|
---|
54 | function md = checkconsistency(cluster,md,solution,analyses) % {{{
|
---|
55 | if cluster.np<1
|
---|
56 | md = checkmessage(md,['number of processors should be at least 1']);
|
---|
57 | end
|
---|
58 | if isnan(cluster.np),
|
---|
59 | md = checkmessage(md,'number of processors should not be NaN!');
|
---|
60 | end
|
---|
61 | end
|
---|
62 | %}}}
|
---|
63 | function BuildQueueScript(cluster,dirname,modelname,solution,io_gather,isvalgrind,isgprof) % {{{
|
---|
64 |
|
---|
65 | %write queuing script
|
---|
66 | if ~ispc(),
|
---|
67 |
|
---|
68 | fid=fopen([modelname '.queue'],'w');
|
---|
69 | fprintf(fid,'#!/bin/sh\n');
|
---|
70 | if ~isvalgrind,
|
---|
71 | if cluster.interactive
|
---|
72 | if IssmConfig('_HAVE_MPI_'),
|
---|
73 | fprintf(fid,'mpiexec -np %i %s/issm.exe %s %s %s ',cluster.np,cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname);
|
---|
74 | else
|
---|
75 | fprintf(fid,'%s/issm.exe %s %s %s ',cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname);
|
---|
76 | end
|
---|
77 | else
|
---|
78 | if IssmConfig('_HAVE_MPI_'),
|
---|
79 | 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);
|
---|
80 | else
|
---|
81 | fprintf(fid,'%s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname,modelname,modelname);
|
---|
82 | end
|
---|
83 | end
|
---|
84 | elseif isgprof,
|
---|
85 | fprintf(fid,'\n gprof %s/issm.exe gmon.out > %s.performance',cluster.codepath,modelname);
|
---|
86 | else
|
---|
87 | %Add --gen-suppressions=all to get suppression lines
|
---|
88 | fprintf(fid,'LD_PRELOAD=%s \\\n',cluster.valgrindlib);
|
---|
89 | if ismac,
|
---|
90 | if IssmConfig('_HAVE_MPI_'),
|
---|
91 | fprintf(fid,'mpiexec -np %i %s --leak-check=full --dsymutil=yes --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',...
|
---|
92 | cluster.np,cluster.valgrind,cluster.valgrindsup,cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname], modelname,modelname,modelname);
|
---|
93 | else
|
---|
94 | fprintf(fid,'%s --leak-check=full --dsymutil=yes --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',...
|
---|
95 | cluster.valgrind,cluster.valgrindsup,cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname], modelname,modelname,modelname);
|
---|
96 | end
|
---|
97 | else
|
---|
98 | if IssmConfig('_HAVE_MPI_'),
|
---|
99 | fprintf(fid,'mpiexec -np %i %s --leak-check=full --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',...
|
---|
100 | cluster.np,cluster.valgrind,cluster.valgrindsup,cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname,modelname,modelname);
|
---|
101 | else
|
---|
102 | fprintf(fid,'%s --leak-check=full --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',...
|
---|
103 | cluster.valgrind,cluster.valgrindsup,cluster.codepath,EnumToString(solution),[cluster.executionpath '/' dirname],modelname,modelname,modelname);
|
---|
104 | end
|
---|
105 | end
|
---|
106 | end
|
---|
107 | if ~io_gather, %concatenate the output files:
|
---|
108 | fprintf(fid,'\ncat %s.outbin.* > %s.outbin',modelname,modelname);
|
---|
109 | end
|
---|
110 | fclose(fid);
|
---|
111 |
|
---|
112 | else % Windows
|
---|
113 |
|
---|
114 | fid=fopen([modelname '.bat'],'w');
|
---|
115 | fprintf(fid,'@echo off\n');
|
---|
116 |
|
---|
117 | if cluster.np>1,
|
---|
118 | fprintf(fid,'"C:\\Program Files\\MPICH2\\bin\\mpiexec.exe" -n %i "%s/issm.exe" %s ./ %s ',cluster.np,cluster.codepath,EnumToString(solution),modelname);
|
---|
119 | else
|
---|
120 | fprintf(fid,'"%s/issm.exe" %s ./ %s ',cluster.codepath,EnumToString(solution),modelname);
|
---|
121 | end
|
---|
122 | fclose(fid);
|
---|
123 | end
|
---|
124 |
|
---|
125 | %in interactive mode, create a run file, and errlog and outlog file
|
---|
126 | if cluster.interactive,
|
---|
127 | fid=fopen([modelname '.errlog'],'w'); fclose(fid);
|
---|
128 | fid=fopen([modelname '.outlog'],'w'); fclose(fid);
|
---|
129 | end
|
---|
130 | end
|
---|
131 | %}}}
|
---|
132 | function BuildKrigingQueueScript(cluster,modelname,solution,io_gather,isvalgrind,isgprof) % {{{
|
---|
133 |
|
---|
134 | %write queuing script
|
---|
135 | if ~ispc(),
|
---|
136 |
|
---|
137 | fid=fopen([modelname '.queue'],'w');
|
---|
138 | fprintf(fid,'#!/bin/sh\n');
|
---|
139 | if ~isvalgrind,
|
---|
140 | if cluster.interactive
|
---|
141 | fprintf(fid,'mpiexec -np %i %s/kriging.exe %s %s ',cluster.np,cluster.codepath,[cluster.executionpath '/' modelname],modelname);
|
---|
142 | else
|
---|
143 | 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);
|
---|
144 | end
|
---|
145 | elseif isgprof,
|
---|
146 | fprintf(fid,'\n gprof %s/kriging.exe gmon.out > %s.performance',cluster.codepath,modelname);
|
---|
147 | else
|
---|
148 | %Add --gen-suppressions=all to get suppression lines
|
---|
149 | fprintf(fid,'LD_PRELOAD=%s \\\n',cluster.valgrindlib);
|
---|
150 | fprintf(fid,'mpiexec -np %i %s --leak-check=full --suppressions=%s %s/kriging.exe %s %s 2> %s.errlog >%s.outlog ',...
|
---|
151 | cluster.np,cluster.valgrind,cluster.valgrindsup,cluster.codepath,[cluster.executionpath '/' modelname],modelname,modelname,modelname);
|
---|
152 | end
|
---|
153 | if ~io_gather, %concatenate the output files:
|
---|
154 | fprintf(fid,'\ncat %s.outbin.* > %s.outbin',modelname,modelname);
|
---|
155 | end
|
---|
156 | fclose(fid);
|
---|
157 |
|
---|
158 | else % Windows
|
---|
159 |
|
---|
160 | fid=fopen([modelname '.bat'],'w');
|
---|
161 | fprintf(fid,'@echo off\n');
|
---|
162 | if cluster.interactive
|
---|
163 | fprintf(fid,'"%s/issm.exe" %s "%s" %s ',cluster.codepath,EnumToString(solution),[cluster.executionpath '/' modelname],modelname);
|
---|
164 | else
|
---|
165 | fprintf(fid,'"%s/issm.exe" %s "%s" %s 2> %s.errlog >%s.outlog',...
|
---|
166 | cluster.codepath,EnumToString(solution),[cluster.executionpath '/' modelname],modelname,modelname,modelname);
|
---|
167 | end
|
---|
168 | fclose(fid);
|
---|
169 | end
|
---|
170 |
|
---|
171 | %in interactive mode, create a run file, and errlog and outlog file
|
---|
172 | if cluster.interactive,
|
---|
173 | fid=fopen([modelname '.errlog'],'w'); fclose(fid);
|
---|
174 | fid=fopen([modelname '.outlog'],'w'); fclose(fid);
|
---|
175 | end
|
---|
176 | end
|
---|
177 | %}}}
|
---|
178 | function LaunchQueueJob(cluster,modelname,dirname,filelist)% {{{
|
---|
179 |
|
---|
180 | if ~ispc,
|
---|
181 | %compress the files into one zip.
|
---|
182 | compressstring=['tar -zcf ' dirname '.tar.gz '];
|
---|
183 | for i=1:numel(filelist),
|
---|
184 | compressstring = [compressstring ' ' filelist{i}];
|
---|
185 | end
|
---|
186 | if cluster.interactive,
|
---|
187 | compressstring = [compressstring ' ' modelname '.errlog ' modelname '.outlog '];
|
---|
188 | end
|
---|
189 | system(compressstring);
|
---|
190 |
|
---|
191 | disp('uploading input file and queueing script');
|
---|
192 | issmscpout(cluster.name,cluster.executionpath,cluster.login,cluster.port,{[dirname '.tar.gz']});
|
---|
193 |
|
---|
194 | disp('launching solution sequence on remote cluster');
|
---|
195 | launchcommand=['source ' cluster.etcpath '/environment.sh && cd ' cluster.executionpath ' && rm -rf ./' dirname ' && mkdir ' dirname ...
|
---|
196 | ' && cd ' dirname ' && mv ../' dirname '.tar.gz ./ && tar -zxf ' dirname '.tar.gz && source ' modelname '.queue '];
|
---|
197 | issmssh(cluster.name,cluster.login,cluster.port,launchcommand);
|
---|
198 | else
|
---|
199 | system([modelname '.bat']);
|
---|
200 | end
|
---|
201 | end %}}}
|
---|
202 | function Download(cluster,dirname,filelist)% {{{
|
---|
203 |
|
---|
204 | if ispc(),
|
---|
205 | %do nothing
|
---|
206 | return;
|
---|
207 | end
|
---|
208 |
|
---|
209 | %copy files from cluster to current directory
|
---|
210 | directory=[cluster.executionpath '/' dirname '/'];
|
---|
211 | issmscpin(cluster.name,cluster.login,cluster.port,directory,filelist);
|
---|
212 | end %}}}
|
---|
213 | end
|
---|
214 | end
|
---|