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