Changeset 450


Ignore:
Timestamp:
05/15/09 14:16:13 (16 years ago)
Author:
jschierm
Message:

Completion of error handling, implementation of restart methods, and partial implementation of mpi.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • issm/trunk/src/m/solutions/dakota/qmu.m

    r356 r450  
    77% qmudir =['qmu_' datestr(now,'yyyymmdd_HHMMSS')];
    88qmudir ='qmu';
    9 %  qmufile can not be changed unless cielo_ice_script.sh is
     9%  qmufile can not be changed unless cielo_ice_script.sh is also changed
    1010qmufile='qmu';
    1111ivar   =1;
     
    1313imethod=1;
    1414iparams=1;
     15runmpi =false;
    1516
    1617%  process any extra input arguments
     
    3031        case 'iparams'
    3132            iparams=varargin{i+1};
     33        case 'overwrite'
     34            overwrite=varargin{i+1};
     35        case 'outfiles'
     36            outfiles =varargin{i+1};
     37        case 'rstfile'
     38            rstfile  =varargin{i+1};
     39        case 'rundakota'
     40            rundakota=varargin{i+1};
     41        case 'runmpi'
     42            runmpi =varargin{i+1};
     43            disp(sprintf('runmpi=%d',runmpi));
    3244    end
    3345end
     
    3547%first create temporary directory in which we will work
    3648if exist(qmudir,'dir')
    37     overwrite=input(['Overwrite existing ''' qmudir ''' directory? Y/N [N]: '], 's');
     49    if ~exist('overwrite','var')
     50        overwrite=input(['Overwrite existing ''' qmudir ''' directory? Y/N [N]: '], 's');
     51    end
    3852    if strncmpi(overwrite,'y',1)
    3953        system(['rm -rf ' qmudir]);
    40     else
    41         error('Existing ''%s'' directory not overwritten.',qmudir);
     54%    else
     55%        error('Existing ''%s'' directory not overwritten.',qmudir);
    4256    end
    4357end
     
    5670    md.qmu_params(iparams).analysis_driver=[ISSM_DIR '/src/m/solutions/dakota/cielo_ice_script.sh'];
    5771end
     72dakota_in_data(md.qmu_method(imethod),md.variables(ivar),md.responses(iresp),md.qmu_params(iparams),qmufile,package,md);
    5873
    59 dakota_in_data(md.qmu_method(imethod),md.variables(ivar),md.responses(iresp),md.qmu_params(iparams),qmufile,package,md);
    60 rundak=input(['Run Dakota analysis ''' qmufile '''? Y/N [N]: '], 's');
    61 if ~strncmpi(rundak,'y',1)
     74%  check for existence of results.out files to use
     75if exist('results.out.1','file') || exist('results.out.zip','file')
     76    if ~exist('outfiles','var')
     77        outfiles=input(['Use existing ''results.out'' files? Y/N [N]: '], 's');
     78    end
     79    if ~strncmpi(outfiles,'y',1)
     80        system('rm -f results.out.[1-9]*');
     81    else
     82        if exist('results.out.zip','file') && ~exist('results.out.1','file')
     83            display('Inflating ''results.out.zip'' file.');
     84            system('unzip -q results.out.zip');
     85        end
     86    end
     87end
     88
     89%  check for existence of dakota.rst file to use
     90rstflag='';
     91if (~exist('outfiles','var') || ~strncmpi(outfiles,'y',1)) && ...
     92    exist('dakota.rst','file')
     93    if ~exist('rstfile','var')
     94        rstfiles=input(['Use existing ''dakota.rst'' file? Y/N [N]: '], 's');
     95    end
     96    if strncmpi(rstfiles,'y',1)
     97        system('rm -f results.out.[1-9]*');
     98        system('dakota_restart_util print dakota.rst | grep completed');
     99        rstflag=' -read_restart dakota.rst';
     100    end
     101end
     102
     103%call dakota
     104if ~exist('rundakota','var')
     105    rundakota=input(['Run Dakota analysis ''' qmufile '''? Y/N [N]: '], 's');
     106end
     107if ~strncmpi(rundakota,'y',1)
    62108    cd ..
    63109    return
    64110end
    65111
    66 %call dakota
    67 system(['dakota -i ' qmufile '.in -o ' qmufile '.out -e ' qmufile '.err']);
    68 % system(['export MPIRUN_NPROCS=8;mpirun -np 4 dakota -i ' qmufile '.in -o ' qmufile '.out -e ' qmufile '.err']);
     112if ~runmpi
     113    system(['dakota -i ' qmufile '.in -o ' qmufile '.out -e ' qmufile '.err' rstflag]);
     114else
     115%  use 'mpd --ncpus=8 &' to initialize mpi and 'mpdringtest' to verify.
     116%  exporting MPIRUN_NPROCS sets mpi in dakota.
     117%    system('mpd --ncpus=8 &');
     118%    system('mpdringtest');
     119    system(['export MPIRUN_NPROCS=8;mpirun -np 4 dakota -i ' qmufile '.in -o ' qmufile '.out -e ' qmufile '.err' rstflag]);
     120end
     121
     122%  check to see if dakota returned errors in the err file
     123fide=fopen([qmufile '.err'],'r');
     124fline=fgetl(fide);
     125if ischar(fline)
     126    while ischar(fline)
     127        disp(sprintf('%s',fline));
     128        fline=fgetl(fide);
     129    end
     130    status=fclose(fide);
     131    cd ../
     132    error(['Dakota returned error in ''' qmufile '.err'' file.  ''' qmudir ''' directory retained.'])
     133end
     134status=fclose(fide);
    69135
    70136%parse inputs and results from dakota
     
    93159%end
    94160
     161%  move all the individual function evalutations into zip files
    95162system('zip -mq params.in.zip params.in.[1-9]*');
    96163system('zip -mq results.out.zip results.out.[1-9]*');
Note: See TracChangeset for help on using the changeset viewer.