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

Last change on this file since 11527 was 11527, checked in by Mathieu Morlighem, 13 years ago

merged trunk-jpl and trunk for revision 11526

File size: 7.2 KB
Line 
1%GENERIC cluster class definition
2%
3% Usage:
4% cluster=generic('name','astrid',);
5% cluster=generic('name','astrid','np',3);
6% cluster=generic('name',oshostname(),'np',3,'login','username');
7
8classdef generic
9 properties (SetAccess=public)
10 % {{{1
11 name='';
12 login='';
13 np=1;
14 port=0;
15 interactive=1;
16 codepath=[issmtier() '/bin'];
17 executionpath=[issmtier() '/execution'];
18 valgrind=[issmtier() '/externalpackages/valgrind/install/bin/valgrind'];
19 valgrindlib=[issmtier() '/externalpackages/valgrind/install/lib/libmpidebug.so'];
20 valgrindsup=[issmtier() '/externalpackages/valgrind/issm.supp'];
21 %}}}
22 end
23 methods
24 function cluster=generic(varargin) % {{{1
25
26 %use provided options to change fields
27 options=pairoptions(varargin{:});
28
29 %get name
30 if ~exist(options,'name'), error('option ''name'' has not been provided'); end
31 cluster.name=getfieldvalue(options,'name');
32
33 %initialize cluster using user settings if provided
34 if (exist([cluster.name '_settings'])==2), eval([cluster.name '_settings']); end
35
36 %OK get other fields
37 for i=1:size(options.list,1),
38 fieldname=options.list{i,1};
39 fieldvalue=options.list{i,2};
40 if ismember(fieldname,properties('generic')),
41 cluster.(fieldname)=fieldvalue;
42 else
43 disp(['''' fieldname ''' is not a property of cluster generic']);
44 end
45 end
46 end
47 %}}}
48 function disp(cluster) % {{{1
49 % display the object
50 disp(sprintf('class ''%s'' object ''%s'' = ',class(cluster),inputname(1)));
51 disp(sprintf(' name: %s',cluster.name));
52 disp(sprintf(' login: %s',cluster.login));
53 disp(sprintf(' np: %i',cluster.np));
54 disp(sprintf(' port: %i',cluster.port));
55 disp(sprintf(' codepath: %s',cluster.codepath));
56 disp(sprintf(' executionpath: %s',cluster.executionpath));
57 disp(sprintf(' valgrind: %s',cluster.valgrind));
58 disp(sprintf(' valgrindlib: %s',cluster.valgrindlib));
59 disp(sprintf(' valgrindsup: %s',cluster.valgrindsup));
60 end
61 %}}}
62 function checkconsistency(cluster,md,solution,analyses) % {{{1
63 if cluster.np<1
64 checkmessage(['number of processors should be at least 1']);
65 end
66 if isnan(cluster.np),
67 checkessage('number of processors should not be NaN!');
68 end
69 end
70 %}}}
71 function BuildQueueScript(cluster,md) % {{{1
72
73 %retrieve parameters
74 modelname=md.miscellaneous.name;
75 solution=md.private.solution;
76 isvalgrind=md.debug.valgrind;
77 isgprof=md.debug.gprof;
78
79 %open file for writing:
80 if ~ispc,
81 fid=fopen([modelname '.queue'],'w');
82 else
83 fid=fopen([modelname '.bat'],'w');
84 end
85
86 %write instructions for launching a job on the cluster
87 if ~ispc,
88 fprintf(fid,'#!/bin/sh\n');
89 else
90 fprintf(fid,'@echo off\n');
91 end
92
93 if ~isvalgrind,
94 if cluster.interactive
95 if ~ispc,
96 fprintf(fid,'mpiexec -np %i %s/issm.exe %s %s %s ',cluster.np,cluster.codepath,EnumToString(solution),cluster.executionpath,modelname);
97 else
98 fprintf(fid,'"%s/issm.exe" %s "%s" %s ',cluster.codepath,EnumToString(solution),cluster.executionpath,modelname);
99 end
100 else
101 if ~ispc,
102 fprintf(fid,'mpiexec -np %i %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',cluster.np,cluster.codepath,EnumToString(solution),cluster.executionpath,modelname,modelname,modelname);
103 else
104 fprintf(fid,'"%s/issm.exe" %s "%s" %s 2> %s.errlog >%s.outlog ',cluster.codepath,EnumToString(solution),cluster.executionpath,modelname,modelname,modelname);
105 end
106 end
107 else
108 if ~ispc,
109 %Add --gen-suppressions=all to get suppression lines
110 fprintf(fid,'LD_PRELOAD=%s \\\n',cluster.valgrindlib);
111 fprintf(fid,'mpiexec -np %i %s --leak-check=full --suppressions=%s %s/issm.exe %s %s %s 2> %s.errlog >%s.outlog ',...
112 cluster.np,cluster.valgrind,cluster.valgrindsup, cluster.codepath,EnumToString(solution),cluster.executionpath,modelname,modelname,modelname);
113 else
114 error('valgrind not supported on windows platforms');
115 end
116 end
117
118 if isgprof,
119 if ~ispc,
120 fprintf(fid,'\n gprof %s/issm.exe gmon.out > %s.performance',cluster.codepath,modelname);
121 else
122 error('gprof not supported on windows platforms');
123 end
124
125 end
126
127 if ~md.settings.io_gather,
128 if ~ispc,
129 %concatenate the output files:
130 fprintf(fid,'\ncat %s.outbin.* > %s.outbin',modelname,modelname);
131 else
132 error('iogather not supported on windows platforms');
133 end
134
135 end
136
137 %close file:
138 fclose(fid);
139
140 %in interactive mode, create a run file, and errlog and outlog file
141 if cluster.interactive,
142 fid=fopen([modelname '.errlog'],'w'); fclose(fid);
143 fid=fopen([modelname '.outlog'],'w'); fclose(fid);
144 end
145
146
147 end
148 %}}}
149 function LaunchQueueJob(cluster,md,options)% {{{1
150
151 if ~ispc,
152 %lauch command, to be executed via ssh
153 launchcommand=['cd ' cluster.executionpath ' && rm -rf ./' md.private.runtimename ' && mkdir ' md.private.runtimename ...
154 ' && cd ' md.private.runtimename ' && mv ../' md.private.runtimename '.tar.gz ./ && tar -zxf ' md.private.runtimename '.tar.gz && source ' md.miscellaneous.name '.queue '];
155
156 if ~strcmpi(options.batch,'yes'),
157
158 %compress the files into one zip.
159 compressstring=['tar -zcf ' md.private.runtimename '.tar.gz ' md.miscellaneous.name '.bin ' md.miscellaneous.name '.queue ' md.miscellaneous.name '.petsc '];
160 if md.qmu.isdakota,
161 compressstring=[compressstring md.miscellaneous.name '.qmu.in'];
162 end
163 if cluster.interactive,
164 compressstring=[compressstring ' ' md.miscellaneous.name '.errlog ' md.miscellaneous.name '.outlog '];
165 end
166 system(compressstring);
167
168 disp('uploading input file and queueing script');
169 issmscpout(cluster.name,cluster.executionpath,cluster.login,cluster.port,{[md.private.runtimename '.tar.gz']});
170
171 disp('launching solution sequence on remote cluster');
172 issmssh(cluster.name,cluster.login,cluster.port,launchcommand);
173 else
174 disp('batch mode requested: not launching job interactively');
175 disp('launch solution sequence on remote cluster by hand');
176 end
177 else
178 %launch right here, do not compress or archive.
179 system([md.miscellaneous.name '.bat']);
180 end
181
182 end %}}}
183 function Download(cluster,md)% {{{1
184
185 if ~ispc,
186 %some check
187 if isempty(md.private.runtimename),
188 error('supply runtime name for results to be loaded!');
189 end
190
191 %Figure out the directory where all the files are in:
192 directory=[cluster.executionpath '/' md.private.runtimename '/'];
193
194 %What packages are we picking up from remote cluster
195 packages={[md.miscellaneous.name '.outlog'],[md.miscellaneous.name '.errlog']};
196 if md.qmu.isdakota,
197 packages{end+1}=[md.miscellaneous.name '.qmu.err'];
198 packages{end+1}=[md.miscellaneous.name '.qmu.out'];
199 if isfield(md.qmu.params,'tabular_graphics_data'),
200 if md.qmu.params.tabular_graphics_data==true,
201 packages{end+1}='dakota_tabular.dat';
202 end
203 end
204 else
205 packages{end+1}=[md.miscellaneous.name '.outbin'];
206 end
207
208 %copy files from cluster to present directory
209 issmscpin(cluster.name, cluster.login, cluster.port, directory, packages);
210 else
211 %do nothing!
212 end
213 end %}}}
214 end
215end
Note: See TracBrowser for help on using the repository browser.