| 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/ daily 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 | % ...
|
|---|
| 23 | % 'procedure' 'check' : run the test (default)
|
|---|
| 24 | % 'update': update the archive
|
|---|
| 25 | %
|
|---|
| 26 | % Usage:
|
|---|
| 27 | % runme(varargin);
|
|---|
| 28 | %
|
|---|
| 29 | % Examples:
|
|---|
| 30 | % runme;
|
|---|
| 31 | % runme('exclude',101);
|
|---|
| 32 | % runme('id',102,'procedure','update');
|
|---|
| 33 |
|
|---|
| 34 | %Get ISSM_DIR variable
|
|---|
| 35 | ISSM_DIR=issmdir();
|
|---|
| 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'})
|
|---|
| 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'})
|
|---|
| 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','daily','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:3020]);
|
|---|
| 123 | end
|
|---|
| 124 | % }}}
|
|---|
| 125 |
|
|---|
| 126 | %Loop over tests and launch sequence
|
|---|
| 127 | root=pwd;
|
|---|
| 128 | for id=test_ids,
|
|---|
| 129 | try,
|
|---|
| 130 |
|
|---|
| 131 | %Execute test
|
|---|
| 132 | eval(['cd ' root ]);
|
|---|
| 133 | id_string=IdToName(id);
|
|---|
| 134 | eval(['test' num2str(id)]);
|
|---|
| 135 |
|
|---|
| 136 | %UPDATE ARCHIVE?
|
|---|
| 137 | archive_name=['Archive' num2str(id) ];
|
|---|
| 138 | if strcmpi(procedure,'update'),
|
|---|
| 139 | delete(['../Archives/' archive_name '.nc'])
|
|---|
| 140 | for k=1:length(field_names),
|
|---|
| 141 | field=field_values{k};
|
|---|
| 142 | % matlab writes the dimensions reversed and matrices transposed into netcdf, so compensate for that
|
|---|
| 143 | nccreate(['../Archives/' archive_name '.nc'],[archive_name '_field' num2str(k)],...
|
|---|
| 144 | 'Dimensions',{[archive_name '_field' num2str(k) '_2'] size(field,2) [archive_name '_field' num2str(k) '_1'] size(field,1)},...
|
|---|
| 145 | 'Format','classic');
|
|---|
| 146 | ncwrite(['../Archives/' archive_name '.nc'],[archive_name '_field' num2str(k)],transpose(field));
|
|---|
| 147 | end
|
|---|
| 148 | disp(sprintf(['File ./../Archives/' archive_name '.nc saved\n']));
|
|---|
| 149 |
|
|---|
| 150 | %ELSE: CHECK TEST
|
|---|
| 151 | else,
|
|---|
| 152 | for k=1:length(field_names),
|
|---|
| 153 |
|
|---|
| 154 | try,
|
|---|
| 155 | %Get field and tolerance
|
|---|
| 156 | field=field_values{k};
|
|---|
| 157 | fieldname=field_names{k};
|
|---|
| 158 | tolerance=field_tolerances{k};
|
|---|
| 159 |
|
|---|
| 160 | %compare to archive
|
|---|
| 161 | % matlab reads the dimensions reversed and matrices transposed from netcdf, so compensate for that
|
|---|
| 162 | archive=transpose(ncread(['../Archives/' archive_name '.nc'],[archive_name '_field' num2str(k)]));
|
|---|
| 163 | error_diff=full(max(abs(archive(:)-field(:)))/(max(abs(archive))+eps));
|
|---|
| 164 |
|
|---|
| 165 | %disp test result
|
|---|
| 166 | if (error_diff>tolerance);
|
|---|
| 167 | disp(sprintf(['ERROR difference: %-7.2g > %7.2g test id: %i test name: %s field: %s'],...
|
|---|
| 168 | error_diff,tolerance,id,id_string,fieldname));
|
|---|
| 169 | else
|
|---|
| 170 | disp(sprintf(['SUCCESS difference: %-7.2g < %7.2g test id: %i test name: %s field: %s'],...
|
|---|
| 171 | error_diff,tolerance,id,id_string,fieldname));
|
|---|
| 172 | end
|
|---|
| 173 |
|
|---|
| 174 | catch me2
|
|---|
| 175 |
|
|---|
| 176 | %something went wrong, print failure message:
|
|---|
| 177 | directory=strsplit(pwd,'/');
|
|---|
| 178 | message=getReport(me2);
|
|---|
| 179 | if strcmpi(output,'nightly')
|
|---|
| 180 | fid=fopen([ISSM_DIR '/nightlylog/matlaberror.log'], 'at');
|
|---|
| 181 | fprintf(fid,'%s',message);
|
|---|
| 182 | fprintf(fid,'\n------------------------------------------------------------------\n');
|
|---|
| 183 | fclose(fid);
|
|---|
| 184 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,fieldname));
|
|---|
| 185 | elseif strcmpi(output,'daily');
|
|---|
| 186 | fid=fopen([ISSM_DIR '/dailylog/matlaberror.log'], 'at');
|
|---|
| 187 | fprintf(fid,'%s',message);
|
|---|
| 188 | fprintf(fid,'\n------------------------------------------------------------------\n');
|
|---|
| 189 | fclose(fid);
|
|---|
| 190 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,fieldname));
|
|---|
| 191 | else
|
|---|
| 192 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,fieldname));
|
|---|
| 193 | rethrow(me2);
|
|---|
| 194 | end
|
|---|
| 195 | end
|
|---|
| 196 | end
|
|---|
| 197 | end
|
|---|
| 198 |
|
|---|
| 199 | catch me,
|
|---|
| 200 |
|
|---|
| 201 | %something went wrong, print failure message:
|
|---|
| 202 | directory=strsplit(pwd,'/');
|
|---|
| 203 | message=getReport(me);
|
|---|
| 204 | if strcmpi(output,'nightly')
|
|---|
| 205 | fid=fopen([ISSM_DIR '/nightlylog/matlaberror.log'], 'at');
|
|---|
| 206 | fprintf(fid,'%s',message);
|
|---|
| 207 | fprintf(fid,'\n------------------------------------------------------------------\n');
|
|---|
| 208 | fclose(fid);
|
|---|
| 209 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,'N/A'));
|
|---|
| 210 | elseif strcmpi(output,'daily');
|
|---|
| 211 | fid=fopen([ISSM_DIR '/dailylog/matlaberror.log'], 'at');
|
|---|
| 212 | fprintf(fid,'%s',message);
|
|---|
| 213 | fprintf(fid,'\n------------------------------------------------------------------\n');
|
|---|
| 214 | fclose(fid);
|
|---|
| 215 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,'N/A'));
|
|---|
| 216 | else
|
|---|
| 217 | disp(sprintf(['FAILURE difference: N/A test id: %i test name: %s field: %s'],id,id_string,'N/A'));
|
|---|
| 218 | rethrow(me);
|
|---|
| 219 | end
|
|---|
| 220 | end
|
|---|
| 221 | end
|
|---|