1 | function 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
|
---|
38 | ISSM_DIR=issmdir();
|
---|
39 |
|
---|
40 | %Check inputs
|
---|
41 | % {{{
|
---|
42 | if nargout>1
|
---|
43 | help runme
|
---|
44 | error('runme error message: bad usage');
|
---|
45 | end
|
---|
46 |
|
---|
47 | %recover options
|
---|
48 | options=pairoptions(varargin{:});
|
---|
49 | % }}}
|
---|
50 |
|
---|
51 | %Process options
|
---|
52 | %GET benchmark {{{
|
---|
53 | benchmark=getfieldvalue(options,'benchmark','nightly');
|
---|
54 | if ~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';
|
---|
57 | end
|
---|
58 | % }}}
|
---|
59 | %GET procedure {{{
|
---|
60 | procedure=getfieldvalue(options,'procedure','check');
|
---|
61 | if ~ismember(procedure,{'check','update','valgrind'})
|
---|
62 | disp('runme warning: procedure not supported, defaulting to test ''check''')
|
---|
63 | procedure='check';
|
---|
64 | end
|
---|
65 | % }}}
|
---|
66 | %GET output {{{
|
---|
67 | output=getfieldvalue(options,'output','none');
|
---|
68 | if ~ismember(output,{'nightly','none'})
|
---|
69 | disp('runme warning: output not supported, defaulting to test ''none''')
|
---|
70 | output='none';
|
---|
71 | end
|
---|
72 | % }}}
|
---|
73 | %GET RANK and NUMPROCS for multithreaded runs {{{
|
---|
74 | rank=getfieldvalue(options,'rank',1);
|
---|
75 | numprocs=getfieldvalue(options,'numprocs',1);
|
---|
76 | if (numprocs<rank), numprocs=1; end
|
---|
77 | % }}}
|
---|
78 | %GET ids {{{
|
---|
79 | flist=dir;%use dir, as it seems to act OS independent
|
---|
80 | list_ids=[];
|
---|
81 | for 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
|
---|
92 | end
|
---|
93 | [i1,i2]=parallelrange(rank,numprocs,length(list_ids)); %Get tests for this cpu only
|
---|
94 | list_ids=list_ids(i1:i2);
|
---|
95 |
|
---|
96 | test_ids=getfieldvalue(options,'id',list_ids);
|
---|
97 | test_ids=intersect(test_ids,list_ids);
|
---|
98 | % }}}
|
---|
99 | %GET exclude {{{
|
---|
100 | exclude_ids=getfieldvalue(options,'exclude',[]);
|
---|
101 | exclude_ids=[exclude_ids];
|
---|
102 | pos=find(ismember(test_ids,exclude_ids));
|
---|
103 | test_ids(pos)=[];
|
---|
104 | % }}}
|
---|
105 | %Process Ids according to benchmarks{{{
|
---|
106 | if strcmpi(benchmark,'nightly'),
|
---|
107 | test_ids=intersect(test_ids,[1:999]);
|
---|
108 | elseif strcmpi(benchmark,'validation'),
|
---|
109 | test_ids=intersect(test_ids,[1001:1999]);
|
---|
110 | elseif strcmpi(benchmark,'ismip'),
|
---|
111 | test_ids=intersect(test_ids,[1101:1199]);
|
---|
112 | elseif strcmpi(benchmark,'eismint'),
|
---|
113 | test_ids=intersect(test_ids,[1201:1299]);
|
---|
114 | elseif strcmpi(benchmark,'thermal'),
|
---|
115 | test_ids=intersect(test_ids,[1301:1399]);
|
---|
116 | elseif strcmpi(benchmark,'mesh'),
|
---|
117 | test_ids=intersect(test_ids,[1401:1499]);
|
---|
118 | elseif strcmpi(benchmark,'tranforcing'),
|
---|
119 | test_ids=intersect(test_ids,[1501:1502]);
|
---|
120 | elseif strcmpi(benchmark,'referential'),
|
---|
121 | test_ids=intersect(test_ids,[1601:1602]);
|
---|
122 | elseif strcmpi(benchmark,'gia'),
|
---|
123 | test_ids=intersect(test_ids,[2001:2100]);
|
---|
124 | elseif strcmpi(benchmark,'adolc'),
|
---|
125 | test_ids=intersect(test_ids,[3001:3200]);
|
---|
126 | elseif strcmpi(benchmark,'qmu'),
|
---|
127 | test_ids=intersect(test_ids,[218 234 235 412:414 417 418 420]);
|
---|
128 | end
|
---|
129 | % }}}
|
---|
130 |
|
---|
131 | %Loop over tests and launch sequence
|
---|
132 | root=pwd;
|
---|
133 | for 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
|
---|
275 | end
|
---|