source: issm/trunk/test/NightlyRun/runme.m@ 18301

Last change on this file since 18301 was 18301, checked in by Mathieu Morlighem, 11 years ago

merged trunk-jpl and trunk for revision 18299

  • Property svn:executable set to *
File size: 9.8 KB
Line 
1function varargout=runme(varargin)
2%RUNME - test deck for ISSM nightly runs
3%
4% In a test deck directory (tests/Vertification/NightlyRun for example)
5% The following command will launch all the existing tests:
6% >> runme
7% To run the tests 101 and 102:
8% >> runme('id',[101 102])
9% etc...
10%
11% Available options:
12% 'id' followed by the list of ids requested
13% 'exclude' ids to be excluded from the test
14% 'benchmark' 'all' (all of them)
15% 'nightly' (nightly run)
16% 'ismip' : validation of ismip-hom tests
17% 'eismint': validation of eismint tests
18% 'thermal': validation of thermal tests
19% 'mesh' : validation of mesh tests
20% 'adolc' : validation of adolc tests
21% 'gia' : validation of gia tests
22% 'qmu' : validation of dakota tests
23% ...
24% 'procedure' 'check' : run the test (default)
25% 'update': update the archive
26% 'valgrind': check for memory leaks (default value of md.debug.valgrind needs to be changed manually)
27% 'stoponerror' 1 or 0
28%
29% Usage:
30% runme(varargin);
31%
32% Examples:
33% runme;
34% runme('exclude',101);
35% runme('id',102,'procedure','update');
36
37%Get ISSM_DIR variable
38ISSM_DIR=issmdir();
39
40%Check inputs
41% {{{
42if nargout>1
43 help runme
44 error('runme error message: bad usage');
45end
46
47%recover options
48options=pairoptions(varargin{:});
49% }}}
50
51%Process options
52%GET benchmark {{{
53benchmark=getfieldvalue(options,'benchmark','nightly');
54if ~ismember(benchmark,{'all','nightly','ismip','eismint','thermal','mesh','validation','tranforcing','adolc','gia','qmu'})
55 disp('runme warning: benchmark not supported, defaulting to test ''nightly''')
56 benchmark='nightly';
57end
58% }}}
59%GET procedure {{{
60procedure=getfieldvalue(options,'procedure','check');
61if ~ismember(procedure,{'check','update','valgrind'})
62 disp('runme warning: procedure not supported, defaulting to test ''check''')
63 procedure='check';
64end
65% }}}
66%GET output {{{
67output=getfieldvalue(options,'output','none');
68if ~ismember(output,{'nightly','none'})
69 disp('runme warning: output not supported, defaulting to test ''none''')
70 output='none';
71end
72% }}}
73%GET RANK and NUMPROCS for multithreaded runs {{{
74rank=getfieldvalue(options,'rank',1);
75numprocs=getfieldvalue(options,'numprocs',1);
76if (numprocs<rank), numprocs=1; end
77% }}}
78%GET ids {{{
79flist=dir;%use dir, as it seems to act OS independent
80list_ids=[];
81for i=1:numel(flist),
82 if ( strncmp(flist(i).name,'test',4) &... %File name must start with 'test'
83 strncmp(fliplr(flist(i).name),fliplr('.m'),2)&... %File name must end by '.m'
84 ~strcmp(flist(i).name,'test.m')) %File name must be different than 'test.m'
85 id=str2num(flist(i).name(5:end-2));
86 if isempty(id),
87 disp(['WARNING: ignore file ' flist(i).name ]);
88 else
89 list_ids(end+1)=eval(flist(i).name(5:end-2)); %Keep test id only (skip 'test' and '.m')
90 end
91 end
92end
93[i1,i2]=parallelrange(rank,numprocs,length(list_ids)); %Get tests for this cpu only
94list_ids=list_ids(i1:i2);
95
96test_ids=getfieldvalue(options,'id',list_ids);
97test_ids=intersect(test_ids,list_ids);
98% }}}
99%GET exclude {{{
100exclude_ids=getfieldvalue(options,'exclude',[]);
101exclude_ids=[exclude_ids];
102pos=find(ismember(test_ids,exclude_ids));
103test_ids(pos)=[];
104% }}}
105%Process Ids according to benchmarks{{{
106if strcmpi(benchmark,'nightly'),
107 test_ids=intersect(test_ids,[1:999]);
108elseif strcmpi(benchmark,'validation'),
109 test_ids=intersect(test_ids,[1001:1999]);
110elseif strcmpi(benchmark,'ismip'),
111 test_ids=intersect(test_ids,[1101:1199]);
112elseif strcmpi(benchmark,'eismint'),
113 test_ids=intersect(test_ids,[1201:1299]);
114elseif strcmpi(benchmark,'thermal'),
115 test_ids=intersect(test_ids,[1301:1399]);
116elseif strcmpi(benchmark,'mesh'),
117 test_ids=intersect(test_ids,[1401:1499]);
118elseif strcmpi(benchmark,'tranforcing'),
119 test_ids=intersect(test_ids,[1501:1502]);
120elseif strcmpi(benchmark,'referential'),
121 test_ids=intersect(test_ids,[1601:1602]);
122elseif strcmpi(benchmark,'gia'),
123 test_ids=intersect(test_ids,[2001:2100]);
124elseif strcmpi(benchmark,'adolc'),
125 test_ids=intersect(test_ids,[3001:3200]);
126elseif strcmpi(benchmark,'qmu'),
127 test_ids=intersect(test_ids,[218 234 235 412:414 417 418 420]);
128end
129% }}}
130
131%Loop over tests and launch sequence
132root=pwd;
133for id=test_ids,
134 try,
135
136 %Execute test
137 eval(['cd ' root ]);
138 id_string=IdToName(id);
139 disp(sprintf('%s%i%s','----------------starting:',id,'-----------------------'));
140 eval(['test' num2str(id)]);
141
142 %UPDATE ARCHIVE?
143 archive_name=['Archive' num2str(id) ];
144 if strcmpi(procedure,'update'),
145 delete(['../Archives/' archive_name '.nc'])
146 for k=1:length(field_names),
147 field=field_values{k};
148 % matlab writes the dimensions reversed and matrices transposed into netcdf, so compensate for that
149 nccreate(['../Archives/' archive_name '.nc'],[archive_name '_field' num2str(k)],...
150 'Dimensions',{[archive_name '_field' num2str(k) '_2'] size(field,2) [archive_name '_field' num2str(k) '_1'] size(field,1)},...
151 'Format','classic');
152 ncwrite(['../Archives/' archive_name '.nc'],[archive_name '_field' num2str(k)],transpose(field));
153 end
154 disp(sprintf(['File ./../Archives/' archive_name '.nc saved\n']));
155
156 %CHECK for memory leaks?
157 elseif strcmpi(procedure,'valgrind'),
158 fields = fieldnames(md.results);
159 for i=1:numel(fields)
160 if ~isfield(md.results.(fields{i}),'errlog'),
161 disp(['Skipping ' fields{i}]);
162 continue;
163 else
164 disp(['Extracting results of ' fields{i}]);
165 end
166 results = md.results.(fields{i});
167 errlog = cellstr(results(1).errlog);
168
169 %Check leaks
170 lines = strfind(errlog,'definitely lost:');
171 lines = find(~cellfun(@isempty,lines));
172 leaks = 0;
173 for j=1:numel(lines)
174 Line = errlog(lines(j));
175 Numbers = sscanf(Line{1},'==%i== definitely lost: %s bytes in %i blocks',[1 Inf]);
176 leaks = leaks + str2num(strrep(char(Numbers(2:end-1)),',',''));
177 end
178 %Check conditional jumps
179 lines = strfind(errlog,'Conditional jump or move depends on uninitialised value');
180 lines = find(~cellfun(@isempty,lines));
181 jumps = numel(lines);
182 %Check invalid read/write
183 lines = strfind(errlog,'Invalid');
184 lines = find(~cellfun(@isempty,lines));
185 inval = numel(lines);
186 if leaks==0,
187 disp(sprintf(['SUCCESS difference: 0 < 0 test id: %i test name: %s field: valgrind mem. leaks'],id,id_string));
188 else
189 disp(sprintf(['ERROR difference: %i > 0 test id: %i test name: %s field: valgrind mem. leaks'],leaks,id,id_string));
190 disp('STOP');
191 return;
192 end
193 if jumps==0,
194 disp(sprintf(['SUCCESS difference: 0 < 0 test id: %i test name: %s field: valgrind cond. jumps'],id,id_string));
195 else
196 disp(sprintf(['ERROR difference: %i > 0 test id: %i test name: %s field: valgrind cond. jumps'],jumps,id,id_string));
197 disp('STOP');
198 return;
199 end
200 if inval==0,
201 disp(sprintf(['SUCCESS difference: 0 < 0 test id: %i test name: %s field: valgrind invalid read/write'],id,id_string));
202 else
203 disp(sprintf(['ERROR difference: %i > 0 test id: %i test name: %s field: valgrind invalid read/write'],inval,id,id_string));
204 disp('STOP');
205 return;
206 end
207 end
208
209 %ELSE: CHECK TEST
210 else,
211 for k=1:length(field_names),
212
213 try,
214 %Get field and tolerance
215 field=field_values{k};
216 fieldname=field_names{k};
217 tolerance=field_tolerances{k};
218
219 %compare to archive
220 % matlab reads the dimensions reversed and matrices transposed from netcdf, so compensate for that
221 archive=transpose(ncread(['../Archives/' archive_name '.nc'],[archive_name '_field' num2str(k)]));
222 error_diff=full(max(abs(archive(:)-field(:)))/(max(abs(archive))+eps));
223
224 %disp test result
225 if (error_diff>tolerance);
226 disp(sprintf(['ERROR difference: %-7.2g > %7.2g test id: %i test name: %s field: %s'],...
227 error_diff,tolerance,id,id_string,fieldname));
228 if(getfieldvalue(options,'stoponerror',0)), disp('STOP'); return; end
229 else
230 disp(sprintf(['SUCCESS difference: %-7.2g < %7.2g test id: %i test name: %s field: %s'],...
231 error_diff,tolerance,id,id_string,fieldname));
232 end
233
234 catch me2
235
236 %something went wrong, print failure message:
237 message=getReport(me2);
238 fprintf('%s',message);
239 if strcmpi(output,'nightly')
240 fid=fopen([ISSM_DIR '/nightlylog/matlaberror.log'], 'at');
241 fprintf(fid,'%s',message);
242 fprintf(fid,'\n------------------------------------------------------------------\n');
243 fclose(fid);
244 disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,fieldname));
245 else
246 disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,fieldname));
247 fprintf('%s',message);
248 if(getfieldvalue(options,'stoponerror',0)), disp('STOP'); return; end
249 end
250 continue;
251 end
252 end
253 end
254
255 disp(sprintf('%s%i%s','----------------finished:',id,'-----------------------'));
256
257 catch me,
258
259 %something went wrong, print failure message:
260 message=getReport(me);
261 fprintf('%s',message);
262 if strcmpi(output,'nightly')
263 fid=fopen([ISSM_DIR '/nightlylog/matlaberror.log'], 'at');
264 fprintf(fid,'%s',message);
265 fprintf(fid,'\n------------------------------------------------------------------\n');
266 fclose(fid);
267 disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,'N/A'));
268 else
269 disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,'N/A'));
270 rethrow(me);
271 if(getfieldvalue(options,'stoponerror',0)), disp('STOP'); return; end
272 end
273 disp(sprintf('%s%i%s','----------------finished:',id,'-----------------------'));
274 end
275end
Note: See TracBrowser for help on using the repository browser.