Changeset 780


Ignore:
Timestamp:
06/04/09 16:36:32 (16 years ago)
Author:
Eric.Larour
Message:

Merge qmuparallel and qmuserial

Location:
issm/trunk/src/m/solutions/dakota
Files:
1 added
1 edited
3 copied

Legend:

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

    r762 r780  
    1 function outoptions=process_solve_options(options)
    2 %DEFAULT_SOLVE_OPTIONS - set up default options for solve phase
     1function outoptions=process_qmu_options(options)
     2%PROCESS_QMU_OPTIONS - set up default options for qmu phase
    33%
    44%   Usage:
    5 %      options=process_solve_options(options)
     5%      options=process_qmu_options(options)
    66%
    7 %   See also: SOLVE,RECOVER_SOLVE_OPTIONS
     7%   See also: QMU,RECOVER_QMU_OPTIONS
    88
    99%analysis_type: check on this option, error out otherwise
     
    1616end
    1717if ~found,
    18         error('recover_solve_options error message: no ''analysis_type'' was provided');
     18        error('recover_qmu_options error message: no ''analysis_type'' was provided');
    1919end
    2020
    21 %package: is there one? check to ''cielo''
     21%package: is there one? default to ''cielo''
    2222found=0;
    2323for i=1:size(options,1),
     
    2828end
    2929if ~found,
    30         disp('recover_solve_options info message: no ''package'' was provided, defaulting to ''cielo''');
     30        disp('recover_qmu_options info message: no ''package'' was provided, defaulting to ''cielo''');
    3131        options(end+1,:)={'package' 'cielo'};
    3232        package='cielo';
     
    3434
    3535if ~ischar(package),
    36         error(['process_solve_options error message: package ' package ' not supported yet']);
     36        error(['process_qmu_options error message: package ' package ' not supported yet']);
    3737end
    3838
     
    4949                sub_analysis_type='none';
    5050        else
    51                 disp('recover_solve_options info message: no ''sub_analysis_type'' was provided, defaulting to ''steady''');
     51                disp('recover_qmu_options info message: no ''sub_analysis_type'' was provided, defaulting to ''steady''');
    5252                sub_analysis_type='steady';
    5353        end
     
    6363                strcmpi(analysis_type,'mesh2grid') |  ...
    6464                strcmpi(analysis_type,'transient') ),
    65         error(['process_solve_options error message: analysis_type ' analysis_type ' not supported yet!']);
     65        error(['process_qmu_options error message: analysis_type ' analysis_type ' not supported yet!']);
    6666end
    6767if ~(strcmpi(sub_analysis_type,'none') |  ...
     
    7171                strcmpi(sub_analysis_type,'') |  ...
    7272                strcmpi(sub_analysis_type,'transient') ),
    73         error(['process_solve_options error message: sub_analysis_type ' sub_analysis_type ' not supported yet!']);
     73        error(['process_qmu_options error message: sub_analysis_type ' sub_analysis_type ' not supported yet!']);
    7474end
    7575if ~(strcmpi(package,'cielo') |  ...
    7676                strcmpi(package,'ice') |  ...
    7777                strcmpi(package,'macayeal') ),
    78         error(['process_solve_options error message: package ' package ' not supported yet!']);
     78        error(['process_qmu_options error message: package ' package ' not supported yet!']);
     79end
     80
     81
     82
     83
     84%  process qmu arguments
     85
     86%first, the defaults
     87qmudir ='qmu';% qmudir =['qmu_' datestr(now,'yyyymmdd_HHMMSS')];
     88qmufile='qmu';%  qmufile can not be changed unless cielo_ice_script.sh is also changed
     89ivar   =1;
     90iresp  =1;
     91imethod=1;
     92iparams=1;
     93runmpi =false;
     94
     95for i=1:size(options,1),
     96        switch options{i,1},
     97        case 'qmudir'
     98                qmudir=options{i,2};
     99        case 'qmufile'
     100                qmufile=options{i,2};
     101        case 'ivar'
     102                ivar=options{i,2};
     103        case 'iresp'
     104                iresp=options{i,2};
     105        case 'imethod'
     106                imethod=options{i,2};
     107        case 'iparams'
     108                iparams=options{i,2};
     109        case 'overwrite'
     110                outoptions.overwrite=options{i,2};
     111        case 'outfiles'
     112                outoptions.outfiles=options{i,2};
     113        case 'rstfile'
     114                outoptions.rstfile=options{i,2};
     115        case 'rundakota'
     116                outoptions.rundakota=options{i,2};
     117        case 'runmpi'
     118                runmpi=options{i,2};
     119        otherwise
     120                %nothing
     121        end
    79122end
    80123
     
    83126outoptions.package=package;
    84127outoptions.sub_analysis_type=sub_analysis_type;
     128outoptions.qmudir=qmudir;
     129outoptions.qmufile=qmufile;
     130outoptions.ivar=ivar;
     131outoptions.iresp=iresp;
     132outoptions.imethod=imethod;
     133outoptions.iparams=iparams;
     134outoptions.runmpi=runmpi;
     135
  • issm/trunk/src/m/solutions/dakota/qmu.m

    r672 r780  
    3737
    3838%recover options
    39 options=recover_solve_options(md,varargin{:});
     39options=recover_qmu_options(md,varargin{:});
    4040
    4141%add default options
    42 options=process_solve_options(options);
     42options=process_qmu_options(options);
    4343
    4444%recover some fields
     
    5656displaystring(md.debug,'\n%s\n','launching solution sequence');
    5757
    58 %Ok, are we running serially or in parallel?
    59 if ~strcmpi(md.cluster,'none'),
    60         %ok, we are running parallel.
    61         md=qmuparallel(md,varargin{:});
     58
     59%first create temporary directory in which we will work
     60if exist(options.qmudir,'dir')
     61    if ~isfield(options,'overwrite')
     62        options.overwrite=input(['Overwrite existing ''' options.qmudir ''' directory? Y/N [N]: '], 's');
     63    end
     64    if strncmpi(options.overwrite,'y',1)
     65        system(['rm -rf ' options.qmudir]);
     66%    else
     67%        error('Existing ''%s'' directory not overwritten.',qmudir);
     68    end
     69end
     70mkdir(options.qmudir)
     71cd(options.qmudir)
     72
     73%some data needs to be copied in qmudir when not running in library mode
     74if ~md.dakotaplugin,
     75        system('cp $ISSM_DIR/startup.m .');
     76
     77        %save our model in qmu so that it can be repeatedly used by Dakota.
     78        save('Qmu.model','md')
     79end
     80
     81%when running in library mode, the in file needs to be called md.name.qmu.in
     82if md.dakotaplugin,
     83        options.qmufile=[md.name ];
     84end
     85
     86%create m and in files for dakota
     87if (~isfield(md.qmu_params(options.iparams),'direct') || ...
     88    ~md.qmu_params(options.iparams).direct) && ...
     89   (~isfield(md.qmu_params(options.iparams),'analysis_driver') || ...
     90    isempty(md.qmu_params(options.iparams).analysis_driver))
     91    md.qmu_params(options.iparams).analysis_driver=[ISSM_DIR '/src/m/solutions/dakota/cielo_ice_script.sh'];
     92end
     93
     94%create m and in files for dakota
     95dakota_in_data(md.qmu_method(options.imethod),md.variables(options.ivar),md.responses(options.iresp),md.qmu_params(options.iparams),options.qmufile,package,md);
     96
     97
     98%in library mode, we only need the dakota in file
     99if md.dakotaplugin,
     100        system(['rm -rf ' md.name '.m']);
     101end
     102
     103%Dakota can be run in library mode in parallel, or using the
     104%standard Dakota (scripted or direct) interface. Those two
     105%modes of running are very different, and call for different
     106%solution sequences. We branch here.
     107
     108if md.dakotaplugin,
     109
     110        %Check we are running in parallel.
     111        if strcmpi(md.cluster,'none'),
     112                error('qmu error message: cannot run in library mode serially! set dakotaplugin to 0');
     113        end
     114
     115        %Get cluster.rc location
     116        cluster_rc_location=which('cluster.rc');
     117
     118        %let solution sequences know that we are running in qmu mode
     119        md.qmu_analysis=1;
     120
     121        %Figure out parameters for this particular cluster
     122        [codepath,executionpath]=ClusterParameters(md.cluster,cluster_rc_location);
     123
     124        %Marshall model data into a binary file.
     125        marshall(md);
     126
     127        %add qmu fields to binary file
     128        qmumarshall(md,md.variables(options.ivar),md.responses(options.iresp));
     129
     130        %Now, we need to build the queuing script, used by the cluster to launch the job.
     131        BuildQueueingScript(md,executionpath,codepath);
     132
     133        %Now, launch the queueing script
     134        LaunchQueueJob(md,executionpath);
     135
     136        %Do we return, or just wait for results?
     137        if md.waitonlock,
     138                %we wait for the done file
     139                waitonlock([executionpath '/' md.name '.lock']);
     140                %load results
     141                md=loadresultsfromcluster(md);
     142        else
     143                return;
     144        end
     145       
    62146else
    63         %we are running serially.
    64         md=qmuserial(md,varargin{:});
    65 end
     147%  check for existence of results.out files to use
     148        if exist('results.out.1','file') || exist('results.out.zip','file')
     149                if ~isfield(options,'outfiles')
     150                        options.outfiles=input(['Use existing ''results.out'' files? Y/N [N]: '], 's');
     151                end
     152                if ~strncmpi(options.outfiles,'y',1)
     153                        system('rm -f results.out.[1-9]*');
     154                else
     155                        if exist('results.out.zip','file') && ~exist('results.out.1','file')
     156                                display('Inflating ''results.out.zip'' file.');
     157                                system('unzip -q results.out.zip');
     158                        end
     159                end
     160        end
     161
     162        %  check for existence of dakota.rst file to use
     163        rstflag='';
     164        if (~isfield(options,'outfiles') || ~strncmpi(options.outfiles,'y',1)) && ...
     165                exist('dakota.rst','file')
     166                if ~isfield(options,'rstfile')
     167                        options.rstfiles=input(['Use existing ''dakota.rst'' file? Y/N [N]: '], 's');
     168                end
     169                if strncmpi(options.rstfiles,'y',1)
     170                        system('rm -f results.out.[1-9]*');
     171                        system('dakota_restart_util print dakota.rst | grep completed');
     172                        rstflag=' -read_restart dakota.rst';
     173                end
     174        end
     175
     176        %call dakota
     177        if ~isfield(options,'rundakota')
     178                options.rundakota=input(['Run Dakota analysis ''' qmufile '''? Y/N [N]: '], 's');
     179        end
     180        if ~strncmpi(options.rundakota,'y',1)
     181                cd ..
     182                return
     183        end
     184
     185        if ~options.runmpi
     186                system(['dakota -i ' qmufile '.in -o ' qmufile '.out -e ' qmufile '.err' rstflag]);
     187        else
     188        %  use 'mpd --ncpus=8 &' to initialize mpi and 'mpdringtest' to verify.
     189        %  exporting MPIRUN_NPROCS sets mpi in dakota.
     190        %    system('mpd --ncpus=8 &');
     191        %    system('mpdringtest');
     192                system(['export MPIRUN_NPROCS=8;mpirun -np 4 dakota -i ' qmufile '.in -o ' qmufile '.out -e ' qmufile '.err' rstflag]);
     193        end
     194
     195end
     196
     197
     198
     199%Now load the results from dakota output files.
     200qmuoutput(md,options.qmufile,options.qmudir);
     201
     202%Get out of qmu directory
     203cd ..
     204
  • issm/trunk/src/m/solutions/dakota/qmuserial.m

    r586 r780  
    1414iparams=1;
    1515runmpi =false;
     16
    1617
    1718%  process any extra input arguments
  • issm/trunk/src/m/solutions/dakota/recover_qmu_options.m

    r672 r780  
    1 function options=recover_solve_options(md,varargin)
    2 %RECOVER_SOLVE_OPTIONS - recover solution options
     1function options=recover_qmu_options(md,varargin)
     2%RECOVER_SOLVE_OPTIONS - recover solution options for qmu runs.
    33%
    44%   Usage:
    5 %      options=recover_solve_options(md,varargin);
     5%      options=recover_qmu_options(md,varargin);
    66%
    77%   See also: SOLVE
     
    1212%make sure length(varargin) is even, ie options come in pairs.
    1313if mod(length(varargin),2),
    14         error('recover_solve_options error message: an even number of options is necessary');
     14        error('recover_qmu_options error message: an even number of options is necessary');
    1515end
    1616
Note: See TracChangeset for help on using the changeset viewer.