Skip to content

Commit

Permalink
Merge pull request #64 from ESMCI/jgfouca/fixes_etc
Browse files Browse the repository at this point in the history
Various fixes, cleanups to get recent PR to work on melvin.
  • Loading branch information
jedwards4b committed Feb 17, 2016
2 parents b934eeb + bd5c766 commit e754a30
Show file tree
Hide file tree
Showing 7 changed files with 108 additions and 643 deletions.
1 change: 1 addition & 0 deletions cime_config/acme/machines/config_machines.xml
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@
<cmd_path lang="sh">module</cmd_path>
<modules>
<command name="purge"/>
<command name="load">python/2.7.9</command>
<command name="load">gcc/5.1.0/openmpi/1.8.7</command>
<command name="load">cmake/2.8.12</command>
<command name="load">netcdf/4.3.2/gcc/5.1.0/openmpi/1.8.7</command>
Expand Down
185 changes: 39 additions & 146 deletions cime_config/acme/machines/template.case.run
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#! /usr/bin/env perl
#! /usr/bin/env perl
#------------------------------------------------------------------------------
# Batch system directives
#------------------------------------------------------------------------------
Expand Down Expand Up @@ -44,13 +44,13 @@ my $logger;
#------------------------------------------------------------------------------
{{ pedocumentation }}
# -------------------------------------------------------------------------
# global data needed by the script, stuff like the max number of threads,
# global data needed by the script, stuff like the max number of threads,
# -------------------------------------------------------------------------
my $banner = "*" x 65;
my %config;
my $case;
my $compiler;
my $machine;
my $machine;
my $machroot;
my $mpilib;
my $scriptsroot;
Expand All @@ -64,7 +64,6 @@ sub main
getOptions();
for(my $cycle=0;$cycle<$config{DATA_ASSIMILATION_CYCLES};$cycle++){
doPreRunChecks();
checkInputData();
runModel();
postRun();
DoDataAssimilation($config{RUNDIR},$config{CASEROOT},$config{DATA_ASSIMILATION},
Expand All @@ -89,11 +88,11 @@ sub getOptions()
my $level = Log::Log4perl::Level::to_priority($opts{loglevel});
Log::Log4perl->easy_init({level=>$level,
layout=>'%m%n'});

$logger = Log::Log4perl::get_logger();


# First, get the configuration from xml .
# First, get the configuration from xml .
%config = SetupTools::getAllResolved();
$case = $config{'CASE'};
$caseroot = $config{'CASEROOT'};
Expand All @@ -109,10 +108,10 @@ sub getOptions()
}
else
{
`./xmlchange -noecho -loglevel $opts{loglevel} RUN_WITH_SUBMIT=TRUE`;
`./xmlchange --noecho RUN_WITH_SUBMIT=TRUE`;
$config{RUN_WITH_SUBMIT}='TRUE';
}

}

# -------------------------------------------------------------------------
Expand All @@ -122,8 +121,8 @@ sub doPreRunChecks()
{
# Change to the case root
chdir($config{'CASEROOT'});
# Update the configuration from xml .

# Update the configuration from xml .
%config = SetupTools::getAllResolved();
$case = $config{'CASE'};
$caseroot = $config{'CASEROOT'};
Expand All @@ -132,24 +131,24 @@ sub doPreRunChecks()
$machroot = $config{'MACHDIR'};
$mpilib = $config{'MPILIB'};

# Now, check for locked files.
# Now, check for locked files.
Run::RunChecks->checkLockedFiles();
# Now, load the module environment...
# ModuleLoader for module-based systems.
my $moduleloader = new Module::ModuleLoader(machine => $config{'MACH'},

# Now, load the module environment...
# ModuleLoader for module-based systems.

my $moduleloader = new Module::ModuleLoader(machine => $config{'MACH'},
compiler => $config{'COMPILER'},
mpilib => $config{'MPILIB'},
debug => $config{'DEBUG'},
mpilib => $config{'MPILIB'},
debug => $config{'DEBUG'},
caseroot => $config{'CASEROOT'},
cimeroot => $config{'CIMEROOT'},
model => $config{'MODEL'});

$moduleloader->moduleInit();
$moduleloader->findModulesForCase();
$moduleloader->loadModules();

my $mpilib = `./xmlquery -value MPILIB`;
if($mpilib =~ /mpi-serial/)
{
Expand All @@ -160,27 +159,27 @@ sub doPreRunChecks()
$ENV{'MP_MPILIB'} = $mpilib;
}
$config{'MPILIB'} = $mpilib;

$logger->debug( "build complete? $config{'BUILD_COMPLETE'}");
if($config{'BUILD_COMPLETE'} ne 'TRUE')
{
$logger->logdie("BUILD_COMPLETE is not true\nPlease rebuild the model interactively");
}

$ENV{'LBQUERY'} = "TRUE";
if( ! defined $config{'BATCHSUBMIT'} || length $config{'BATCHSUBMIT'} == 0)
{
$ENV{'LBQUERY'} = "FALSE";
$ENV{'BATCHQUERY'} = "undefined";
}

elsif ( $config{'BATCHSUBMIT'} eq 'UNSET')
{
$ENV{'LBSUBMIT'} = "FALSE";
$ENV{'BATCHSUBMIT'} = "undefined";
}
## Create the timing directories, optionally cleaning them if needed.

## Create the timing directories, optionally cleaning them if needed.
if(! -d $config{'RUNDIR'})
{
mkpath($config{'RUNDIR'}) or die "could not crate $config{'RUNDIR'}, exiting\n";
Expand All @@ -191,29 +190,29 @@ sub doPreRunChecks()
}
# Now make the timing and timing/checkpoints directories..
mkpath("$config{'RUNDIR'}/timing/checkpoints");

# Now set up the LID and sdate? strings
$LID = strftime("%y%m%d-%H%M%S", localtime);
my $sdate = strftime("%Y-%m-%d %H:%M:%S", localtime);
$ENV{'LID'} = $LID;
$ENV{'sdate'} = $sdate;

open my $CS, ">>", "./CaseStatus" or die "Could not open CaseStatus file for writing!";
print $CS "run started $sdate\n";
close $CS;

$logger->info( "-------------------------------------------------------------------------");
$logger->info(" BUILDNML SCRIPT STARTING");
$logger->info(" - To prestage restarts, untar a restart.tar file into $config{'RUNDIR'}");

# Run preview namelists.. should turn this into a module at some point..
system("./preview_namelists -loglevel $opts{loglevel} ");

if($?)
{
$logger->logdie("ERROR from preview namelist - EXITING");
}

$logger->info( " BUILDNML SCRIPT HAS FINISHED SUCCESSFULLY");
$logger->info( "-------------------------------------------------------------------------");
$logger->info( " PRESTAGE SCRIPT STARTING");
Expand All @@ -222,119 +221,13 @@ sub doPreRunChecks()

}

# -------------------------------------------------------------------------
# we've done the preview namelists check, now we'll check on the inputdata..
# -------------------------------------------------------------------------
sub checkInputData()
{
chdir($config{'CASEROOT'}) or $logger->logdie ("cannot change directory to $config{'CASEROOT'}, $!");
if(! -d $config{'DIN_LOC_ROOT'})
{
$logger->logdie( "ERROR, the input data directory $config{'DIN_LOC_ROOT'} cannot be found!");
}

open(F,"./check_input_data -inputdata $config{'DIN_LOC_ROOT'} -check -loglevel $opts{loglevel} |" );
my @inputdatacheck = <F>;
close(F);
my @unknown = grep { /unknown/ } @inputdatacheck;
my @missing = grep { /missing/ } @inputdatacheck;

if(@unknown)
{
#my $unknownmsg = <<MSG;
my $out= "Any files with \"status unknown\" below were not found in the\n";
$out.="expected location, and are not from the input data repository.\n";
$out.="This is informational only.\n";
$logger->warn($out);
system("./check_input_data -inputdata $config{'DIN_LOC_ROOT'} -check -loglevel $opts{loglevel} ");
}

if(@missing)
{
$logger->info( "Attempting to download missing data:");
system("./check_input_data -inputdata $config{'DIN_LOC_ROOT'} -export -loglevel $opts{loglevel}");
}

open(F,"./check_input_data -inputdata $config{'DIN_LOC_ROOT'} -check -loglevel $opts{loglevel} |" );
my @potmissing = <F>;
close(F);
@missing = grep { /missing/ } @potmissing;
if(@missing)
{
my $out = "The following files were not found, they are required\n";
$out .= map { print $_ } @potmissing;
$out .= "Invoke the following command to obtain them:\n";
$out .= " ./check_input_data -inputdata $config{'DIN_LOC_ROOT'} -export ";
$logger->logdie($out);
}

# Prestage our reference case if required..
if( ($config{'GET_REFCASE'} eq 'TRUE') && ($config{'RUN_TYPE'} ne 'startup') && ($config{'CONTINUE_RUN'} eq 'FALSE'))
{
my $refdir = "$config{'RUN_REFCASE'}/$config{'RUN_REFDATE'}";
my $fullrefdirpath = "$config{'DIN_LOC_ROOT'}/ccsm4_init/$refdir";
if(! -d $fullrefdirpath)
{
my $out = "$banner\n";
$out .= "ccsm_prestage ERROR: $refdir is not on local disk!\n";
$out .= "Obtain this data from the svn input data repository\n";
$out .= "> mkdir -p $refdir\n";
$out .= "> cd $refdir\n";
$out .= "> cd ..\n";
$out .= "> svn export --force https://svn-ccsm-inputdata.cgd.ucar.edu/trunk/inputdata/$refdir\n";
$out .= "or set GET_REFCASE to FALSE in env_run.xml\n";
$out .= "and prestage the restart data to $config{'RUNDIR'} manually\n";
$out .= "$banner\n";
$logger->logdie($out);
}

$logger->info(" - Prestaging REFCASE ($refdir) to $config{'RUNDIR'}");

# prestage the reference case's files.
mkpath $config{'RUNDIR'} if (! -d $config{'RUNDIR'});
my @refcasefiles = glob("$fullrefdirpath/*$config{'RUN_REFCASE'}*");
foreach my $rcfile(@refcasefiles)
{
my $rcbasename = basename($rcfile);
if(! -f "$config{'RUNDIR'}/$rcbasename")
{
symlink($rcfile, "$config{'RUNDIR'}/$rcbasename") or $logger->warn ("could not symlink $rcfile to $config{'RUNDIR'}/$rcbasename, $!");
}
}

# find the *rpointer* files, copy them to the rundir.
my @rpointerfiles = glob("$fullrefdirpath/*rpointer*");
foreach my $rpointerfile(@rpointerfiles)
{
copy($rpointerfile, $config{'RUNDIR'});
}

chdir($config{'RUNDIR'});

my @cam2_list = glob("*.cam2.*");
foreach my $cam2file(@cam2_list)
{
my $camfile = $cam2file;
$camfile =~ s/cam2/cam/g;
symlink($cam2file, $camfile);
}

my @allrundirfiles = glob("$config{'RUNDIR'}/*");
foreach my $runfile(@allrundirfiles)
{
chmod 0755, $runfile;
}
$logger->info( "prestaging has finished successfully!");
}
}

# -------------------------------------------------------------------------
# Run the model system
# -------------------------------------------------------------------------
sub runModel()
{
chdir $config{'RUNDIR'};

system("sleep 10");
my $localtime = localtime;
# Set OMP_NUM_THREADS
Expand Down Expand Up @@ -364,7 +257,7 @@ sub disposeLog
}
}

}
}



Expand All @@ -375,8 +268,8 @@ sub disposeLog
# -------------------------------------------------------------------------
sub postRun()
{
# Go back to the caseroot, pull in the configuration in case a user changed
# of the variables
# Go back to the caseroot, pull in the configuration in case a user changed
# of the variables
chdir $config{'CASEROOT'};
%config = SetupTools::getAllResolved();
my $rundir = $config{RUNDIR};
Expand All @@ -388,15 +281,15 @@ sub postRun()
my $logfile = "$rundir/cesm.log.$LID";
my $cpllogfile = "$rundir/cpl.log.$LID";

if( -z $logfile)
if( -z $logfile)
{
$logger->error( "Model did not complete, no cesm.log file present");
}

if(! -e $cpllogfile)
{
my $msg = "Model did not complete 1 - no cpl.log file, $cpllogfile, corresponding to most recent model log: $logfile";

appendCaseStatus($msg);
$logger->logdie($msg);
}
Expand Down Expand Up @@ -491,11 +384,11 @@ sub resubmitCheck()
my $resubmitcommand = "$submitscript -resubmit -scriptname case.";

if(defined $config{TESTCASE} && $config{TESTCASE} eq "ERR"){
$resubmitcommand .= "test";
$resubmitcommand .= "test";
}else{
$resubmitcommand .= "run";
$resubmitcommand .= "run";
}
$logger->debug( "running resubmit check $resubmitcommand");
$logger->debug( "running resubmit check $resubmitcommand");
system($resubmitcommand);
if($?){ $logger->warn ("could not run CESM submit script, $! $?");}
chdir $cwd;
Expand Down
Loading

0 comments on commit e754a30

Please sign in to comment.