[4950] | 1 | function 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 |
|
---|
[5050] | 37 | %Check inputs
|
---|
[13395] | 38 | % {{{
|
---|
[4950] | 39 | if nargout>1
|
---|
| 40 | help runme
|
---|
| 41 | error('runme error message: bad usage');
|
---|
| 42 | end
|
---|
| 43 |
|
---|
[5050] | 44 | %recover options
|
---|
| 45 | options=pairoptions(varargin{:});
|
---|
| 46 | % }}}
|
---|
| 47 |
|
---|
| 48 | %Process options
|
---|
[13395] | 49 | %GET benchmark {{{
|
---|
[5050] | 50 | benchmark=getfieldvalue(options,'benchmark','nightly');
|
---|
[18301] | 51 | if ~ismember(benchmark,{'all','nightly','ismip','eismint','thermal','mesh','validation','tranforcing','adolc','gia','qmu'})
|
---|
[11527] | 52 | disp('runme warning: benchmark not supported, defaulting to test ''nightly''')
|
---|
[12707] | 53 | benchmark='nightly';
|
---|
[5050] | 54 | end
|
---|
| 55 | % }}}
|
---|
[13395] | 56 | %GET procedure {{{
|
---|
[4950] | 57 | procedure=getfieldvalue(options,'procedure','check');
|
---|
[16137] | 58 | if ~ismember(procedure,{'check','update','valgrind'})
|
---|
[4950] | 59 | disp('runme warning: procedure not supported, defaulting to test ''check''')
|
---|
| 60 | procedure='check';
|
---|
| 61 | end
|
---|
[5050] | 62 | % }}}
|
---|
[13395] | 63 | %GET output {{{
|
---|
[5084] | 64 | output=getfieldvalue(options,'output','none');
|
---|
[17806] | 65 | if ~ismember(output,{'nightly','none'})
|
---|
[5084] | 66 | disp('runme warning: output not supported, defaulting to test ''none''')
|
---|
| 67 | output='none';
|
---|
| 68 | end
|
---|
| 69 | % }}}
|
---|
[13975] | 70 | %GET RANK and NUMPROCS for multithreaded runs {{{
|
---|
[4999] | 71 | rank=getfieldvalue(options,'rank',1);
|
---|
| 72 | numprocs=getfieldvalue(options,'numprocs',1);
|
---|
| 73 | if (numprocs<rank), numprocs=1; end
|
---|
[5050] | 74 | % }}}
|
---|
[13395] | 75 | %GET ids {{{
|
---|
| 76 | flist=dir;%use dir, as it seems to act OS independent
|
---|
[4950] | 77 | list_ids=[];
|
---|
[13395] | 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'
|
---|
[14310] | 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
|
---|
[4950] | 88 | end
|
---|
| 89 | end
|
---|
[4999] | 90 | [i1,i2]=parallelrange(rank,numprocs,length(list_ids)); %Get tests for this cpu only
|
---|
| 91 | list_ids=list_ids(i1:i2);
|
---|
| 92 |
|
---|
[4950] | 93 | test_ids=getfieldvalue(options,'id',list_ids);
|
---|
| 94 | test_ids=intersect(test_ids,list_ids);
|
---|
[5050] | 95 | % }}}
|
---|
[13395] | 96 | %GET exclude {{{
|
---|
[5085] | 97 | exclude_ids=getfieldvalue(options,'exclude',[]);
|
---|
[7071] | 98 | exclude_ids=[exclude_ids];
|
---|
[5085] | 99 | pos=find(ismember(test_ids,exclude_ids));
|
---|
| 100 | test_ids(pos)=[];
|
---|
| 101 | % }}}
|
---|
[13395] | 102 | %Process Ids according to benchmarks{{{
|
---|
[5050] | 103 | if strcmpi(benchmark,'nightly'),
|
---|
| 104 | test_ids=intersect(test_ids,[1:999]);
|
---|
[14067] | 105 | elseif strcmpi(benchmark,'validation'),
|
---|
| 106 | test_ids=intersect(test_ids,[1001:1999]);
|
---|
[5272] | 107 | elseif strcmpi(benchmark,'ismip'),
|
---|
[5271] | 108 | test_ids=intersect(test_ids,[1101:1199]);
|
---|
[5272] | 109 | elseif strcmpi(benchmark,'eismint'),
|
---|
[5271] | 110 | test_ids=intersect(test_ids,[1201:1299]);
|
---|
[5272] | 111 | elseif strcmpi(benchmark,'thermal'),
|
---|
[5271] | 112 | test_ids=intersect(test_ids,[1301:1399]);
|
---|
[5272] | 113 | elseif strcmpi(benchmark,'mesh'),
|
---|
[5271] | 114 | test_ids=intersect(test_ids,[1401:1499]);
|
---|
[14067] | 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]);
|
---|
[15396] | 119 | elseif strcmpi(benchmark,'gia'),
|
---|
| 120 | test_ids=intersect(test_ids,[2001:2100]);
|
---|
[13395] | 121 | elseif strcmpi(benchmark,'adolc'),
|
---|
[16560] | 122 | test_ids=intersect(test_ids,[3001:3200]);
|
---|
[18301] | 123 | elseif strcmpi(benchmark,'qmu'),
|
---|
| 124 | test_ids=intersect(test_ids,[218 234 235 412:414 417 418 420]);
|
---|
[5050] | 125 | end
|
---|
| 126 | % }}}
|
---|
[4950] | 127 |
|
---|
| 128 | %Loop over tests and launch sequence
|
---|
[5501] | 129 | root=pwd;
|
---|
[4950] | 130 | for id=test_ids,
|
---|
[19105] | 131 | disp(sprintf('%s%i%s','----------------starting:',id,'-----------------------'));
|
---|
[4950] | 132 | try,
|
---|
| 133 | %Execute test
|
---|
[5501] | 134 | eval(['cd ' root ]);
|
---|
[19105] | 135 | id_string='N/A';
|
---|
[5501] | 136 | id_string=IdToName(id);
|
---|
[4950] | 137 | eval(['test' num2str(id)]);
|
---|
| 138 |
|
---|
| 139 | %UPDATE ARCHIVE?
|
---|
| 140 | archive_name=['Archive' num2str(id) ];
|
---|
| 141 | if strcmpi(procedure,'update'),
|
---|
[13395] | 142 | delete(['../Archives/' archive_name '.nc'])
|
---|
[4950] | 143 | for k=1:length(field_names),
|
---|
| 144 | field=field_values{k};
|
---|
[13395] | 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));
|
---|
[4950] | 150 | end
|
---|
[13395] | 151 | disp(sprintf(['File ./../Archives/' archive_name '.nc saved\n']));
|
---|
[4950] | 152 |
|
---|
[16137] | 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 |
|
---|
[12707] | 206 | %ELSE: CHECK TEST
|
---|
[4950] | 207 | else,
|
---|
| 208 | for k=1:length(field_names),
|
---|
| 209 |
|
---|
[4999] | 210 | try,
|
---|
| 211 | %Get field and tolerance
|
---|
| 212 | field=field_values{k};
|
---|
| 213 | fieldname=field_names{k};
|
---|
| 214 | tolerance=field_tolerances{k};
|
---|
[4950] | 215 |
|
---|
[4999] | 216 | %compare to archive
|
---|
[13395] | 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)]));
|
---|
[11027] | 219 | error_diff=full(max(abs(archive(:)-field(:)))/(max(abs(archive))+eps));
|
---|
[4950] | 220 |
|
---|
[4999] | 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'],...
|
---|
[5501] | 224 | error_diff,tolerance,id,id_string,fieldname));
|
---|
[17806] | 225 | if(getfieldvalue(options,'stoponerror',0)), disp('STOP'); return; end
|
---|
[4999] | 226 | else
|
---|
| 227 | disp(sprintf(['SUCCESS difference: %-7.2g < %7.2g test id: %i test name: %s field: %s'],...
|
---|
[5501] | 228 | error_diff,tolerance,id,id_string,fieldname));
|
---|
[4999] | 229 | end
|
---|
| 230 |
|
---|
| 231 | catch me2
|
---|
| 232 |
|
---|
| 233 | %something went wrong, print failure message:
|
---|
[5104] | 234 | message=getReport(me2);
|
---|
[17806] | 235 | fprintf('%s',message);
|
---|
[5084] | 236 | if strcmpi(output,'nightly')
|
---|
[19105] | 237 | fid=fopen([issmdir() '/nightlylog/matlaberror.log'], 'at');
|
---|
[5084] | 238 | fprintf(fid,'%s',message);
|
---|
| 239 | fprintf(fid,'\n------------------------------------------------------------------\n');
|
---|
| 240 | fclose(fid);
|
---|
[5501] | 241 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,fieldname));
|
---|
[5104] | 242 | else
|
---|
[11995] | 243 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,fieldname));
|
---|
[17806] | 244 | fprintf('%s',message);
|
---|
| 245 | if(getfieldvalue(options,'stoponerror',0)), disp('STOP'); return; end
|
---|
[5084] | 246 | end
|
---|
[17806] | 247 | continue;
|
---|
[4950] | 248 | end
|
---|
| 249 | end
|
---|
| 250 | end
|
---|
| 251 | catch me,
|
---|
| 252 |
|
---|
| 253 | %something went wrong, print failure message:
|
---|
[5104] | 254 | message=getReport(me);
|
---|
[17806] | 255 | fprintf('%s',message);
|
---|
[5084] | 256 | if strcmpi(output,'nightly')
|
---|
[19105] | 257 | fid=fopen([issmdir() '/nightlylog/matlaberror.log'], 'at');
|
---|
[5084] | 258 | fprintf(fid,'%s',message);
|
---|
| 259 | fprintf(fid,'\n------------------------------------------------------------------\n');
|
---|
| 260 | fclose(fid);
|
---|
[5501] | 261 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,'N/A'));
|
---|
[5104] | 262 | else
|
---|
[11995] | 263 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,'N/A'));
|
---|
[5104] | 264 | rethrow(me);
|
---|
[17806] | 265 | if(getfieldvalue(options,'stoponerror',0)), disp('STOP'); return; end
|
---|
[5084] | 266 | end
|
---|
[4950] | 267 | end
|
---|
[19105] | 268 | disp(sprintf('%s%i%s','----------------finished:',id,'-----------------------'));
|
---|
[4950] | 269 | end
|
---|