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
RevLine 
[4950]1function varargout=runme(varargin)
2%RUNME - test deck for ISSM nightly runs
3%
[5085]4% In a test deck directory (tests/Vertification/NightlyRun for example)
5% The following command will launch all the existing tests:
[4950]6% >> runme
[5085]7% To run the tests 101 and 102:
8% >> runme('id',[101 102])
[4950]9% etc...
10%
11% Available options:
[5085]12% 'id' followed by the list of ids requested
13% 'exclude' ids to be excluded from the test
[15396]14% 'benchmark' 'all' (all of them)
[17806]15% 'nightly' (nightly run)
[5271]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
[13395]20% 'adolc' : validation of adolc tests
[15396]21% 'gia' : validation of gia tests
[18301]22% 'qmu' : validation of dakota tests
[5085]23% ...
[16137]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)
[17806]27% 'stoponerror' 1 or 0
[4950]28%
29% Usage:
[15396]30% runme(varargin);
[4950]31%
32% Examples:
33% runme;
[5085]34% runme('exclude',101);
[15396]35% runme('id',102,'procedure','update');
[4950]36
[12332]37%Get ISSM_DIR variable
38ISSM_DIR=issmdir();
[4950]39
[5050]40%Check inputs
[13395]41% {{{
[4950]42if nargout>1
43 help runme
44 error('runme error message: bad usage');
45end
46
[5050]47%recover options
48options=pairoptions(varargin{:});
49% }}}
50
51%Process options
[13395]52%GET benchmark {{{
[5050]53benchmark=getfieldvalue(options,'benchmark','nightly');
[18301]54if ~ismember(benchmark,{'all','nightly','ismip','eismint','thermal','mesh','validation','tranforcing','adolc','gia','qmu'})
[11527]55 disp('runme warning: benchmark not supported, defaulting to test ''nightly''')
[12707]56 benchmark='nightly';
[5050]57end
58% }}}
[13395]59%GET procedure {{{
[4950]60procedure=getfieldvalue(options,'procedure','check');
[16137]61if ~ismember(procedure,{'check','update','valgrind'})
[4950]62 disp('runme warning: procedure not supported, defaulting to test ''check''')
63 procedure='check';
64end
[5050]65% }}}
[13395]66%GET output {{{
[5084]67output=getfieldvalue(options,'output','none');
[17806]68if ~ismember(output,{'nightly','none'})
[5084]69 disp('runme warning: output not supported, defaulting to test ''none''')
70 output='none';
71end
72% }}}
[13975]73%GET RANK and NUMPROCS for multithreaded runs {{{
[4999]74rank=getfieldvalue(options,'rank',1);
75numprocs=getfieldvalue(options,'numprocs',1);
76if (numprocs<rank), numprocs=1; end
[5050]77% }}}
[13395]78%GET ids {{{
79flist=dir;%use dir, as it seems to act OS independent
[4950]80list_ids=[];
[13395]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'
[14310]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
[4950]91 end
92end
[4999]93[i1,i2]=parallelrange(rank,numprocs,length(list_ids)); %Get tests for this cpu only
94list_ids=list_ids(i1:i2);
95
[4950]96test_ids=getfieldvalue(options,'id',list_ids);
97test_ids=intersect(test_ids,list_ids);
[5050]98% }}}
[13395]99%GET exclude {{{
[5085]100exclude_ids=getfieldvalue(options,'exclude',[]);
[7071]101exclude_ids=[exclude_ids];
[5085]102pos=find(ismember(test_ids,exclude_ids));
103test_ids(pos)=[];
104% }}}
[13395]105%Process Ids according to benchmarks{{{
[5050]106if strcmpi(benchmark,'nightly'),
107 test_ids=intersect(test_ids,[1:999]);
[14067]108elseif strcmpi(benchmark,'validation'),
109 test_ids=intersect(test_ids,[1001:1999]);
[5272]110elseif strcmpi(benchmark,'ismip'),
[5271]111 test_ids=intersect(test_ids,[1101:1199]);
[5272]112elseif strcmpi(benchmark,'eismint'),
[5271]113 test_ids=intersect(test_ids,[1201:1299]);
[5272]114elseif strcmpi(benchmark,'thermal'),
[5271]115 test_ids=intersect(test_ids,[1301:1399]);
[5272]116elseif strcmpi(benchmark,'mesh'),
[5271]117 test_ids=intersect(test_ids,[1401:1499]);
[14067]118elseif strcmpi(benchmark,'tranforcing'),
119 test_ids=intersect(test_ids,[1501:1502]);
120elseif strcmpi(benchmark,'referential'),
121 test_ids=intersect(test_ids,[1601:1602]);
[15396]122elseif strcmpi(benchmark,'gia'),
123 test_ids=intersect(test_ids,[2001:2100]);
[13395]124elseif strcmpi(benchmark,'adolc'),
[16560]125 test_ids=intersect(test_ids,[3001:3200]);
[18301]126elseif strcmpi(benchmark,'qmu'),
127 test_ids=intersect(test_ids,[218 234 235 412:414 417 418 420]);
[5050]128end
129% }}}
[4950]130
131%Loop over tests and launch sequence
[5501]132root=pwd;
[4950]133for id=test_ids,
134 try,
135
136 %Execute test
[5501]137 eval(['cd ' root ]);
138 id_string=IdToName(id);
[17806]139 disp(sprintf('%s%i%s','----------------starting:',id,'-----------------------'));
[4950]140 eval(['test' num2str(id)]);
141
142 %UPDATE ARCHIVE?
143 archive_name=['Archive' num2str(id) ];
144 if strcmpi(procedure,'update'),
[13395]145 delete(['../Archives/' archive_name '.nc'])
[4950]146 for k=1:length(field_names),
147 field=field_values{k};
[13395]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));
[4950]153 end
[13395]154 disp(sprintf(['File ./../Archives/' archive_name '.nc saved\n']));
[4950]155
[16137]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
[12707]209 %ELSE: CHECK TEST
[4950]210 else,
211 for k=1:length(field_names),
212
[4999]213 try,
214 %Get field and tolerance
215 field=field_values{k};
216 fieldname=field_names{k};
217 tolerance=field_tolerances{k};
[4950]218
[4999]219 %compare to archive
[13395]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)]));
[11027]222 error_diff=full(max(abs(archive(:)-field(:)))/(max(abs(archive))+eps));
[4950]223
[4999]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'],...
[5501]227 error_diff,tolerance,id,id_string,fieldname));
[17806]228 if(getfieldvalue(options,'stoponerror',0)), disp('STOP'); return; end
[4999]229 else
230 disp(sprintf(['SUCCESS difference: %-7.2g < %7.2g test id: %i test name: %s field: %s'],...
[5501]231 error_diff,tolerance,id,id_string,fieldname));
[4999]232 end
233
234 catch me2
235
236 %something went wrong, print failure message:
[5104]237 message=getReport(me2);
[17806]238 fprintf('%s',message);
[5084]239 if strcmpi(output,'nightly')
[12332]240 fid=fopen([ISSM_DIR '/nightlylog/matlaberror.log'], 'at');
[5084]241 fprintf(fid,'%s',message);
242 fprintf(fid,'\n------------------------------------------------------------------\n');
243 fclose(fid);
[5501]244 disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,fieldname));
[5104]245 else
[11995]246 disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,fieldname));
[17806]247 fprintf('%s',message);
248 if(getfieldvalue(options,'stoponerror',0)), disp('STOP'); return; end
[5084]249 end
[17806]250 continue;
[4950]251 end
252 end
253 end
[17806]254
255 disp(sprintf('%s%i%s','----------------finished:',id,'-----------------------'));
[4950]256
257 catch me,
258
259 %something went wrong, print failure message:
[5104]260 message=getReport(me);
[17806]261 fprintf('%s',message);
[5084]262 if strcmpi(output,'nightly')
[12332]263 fid=fopen([ISSM_DIR '/nightlylog/matlaberror.log'], 'at');
[5084]264 fprintf(fid,'%s',message);
265 fprintf(fid,'\n------------------------------------------------------------------\n');
266 fclose(fid);
[5501]267 disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,'N/A'));
[5104]268 else
[11995]269 disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,'N/A'));
[5104]270 rethrow(me);
[17806]271 if(getfieldvalue(options,'stoponerror',0)), disp('STOP'); return; end
[5084]272 end
[17806]273 disp(sprintf('%s%i%s','----------------finished:',id,'-----------------------'));
[4950]274 end
275end
Note: See TracBrowser for help on using the repository browser.