Skip to content

Commit

Permalink
Merge pull request #37 from CohenBerkeleyLab/mpicmd
Browse files Browse the repository at this point in the history
Pull "mpicmd" branch
  • Loading branch information
behr-github authored Aug 4, 2017
2 parents e0a3f4b + e6135b2 commit 17852ce
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 10 deletions.
35 changes: 32 additions & 3 deletions autowrfchem_main
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ while [ $# -gt 0 ]; do
echo "$myname: utility to automate the compilation and running of WRF-Chem"
echo " Modes of operation: "
echo ""
echo " ***************************** CONFIGURATION: *****************************"
echo ""
echo " ./$myname config : will require user input to generate"
echo " the necessary configuration files (so don't run this as"
echo " part of a batch job). It will also set a global namelist"
Expand All @@ -51,20 +53,23 @@ while [ $# -gt 0 ]; do
echo " time period."
echo ""
echo ""
echo " ***************************** COMPILATION: *****************************"
echo ""
echo " ./$myname compile : will execute the compilation of all"
echo " the components of WRF-Chem and it's input preparation,"
echo " including WRF-Chem, WPS, convert_emiss, emiss_v0x.F,"
echo " megan_bio_emiss, and mozbc. It will skip compiling if"
echo " it finds an existing .exe file."
echo ""
echo ""
echo " ./$myname clean : will remove all compiled files for a clean"
echo " compile."
echo ""
echo " ./$myname clean input : will clean up the input files instead."
echo " It does not clean the code."
echo ""
echo ""
echo " ***************************** INPUT PREPARATION: *****************************"
echo ""
echo " ./$myname prepinpt : will prepare meteorology, NEI emissions,"
echo " MEGAN emissions, and MOZBC initial and boundary conditions."
echo ""
Expand Down Expand Up @@ -100,17 +105,28 @@ while [ $# -gt 0 ]; do
echo " in WRFV3/run."
echo ""
echo ""
echo " ***************************** RUNNING WRF: *****************************"
echo ""
echo " ./$myname run : will run WRF-Chem. This will first check"
echo " that the WRF namelist.input file matches what was configured"
echo " by ./$myname config. If running WRF-Chem in parallel, must pass"
echo " the number of tasks to start (x) as --ntasks=x. If running in"
echo " serial, must pass the flag --nompi instead"
echo " the number of tasks to start (x) as --ntasks=x or use --alt-mpi-cmd"
echo " (see below). If running in serial, must pass the flag --nompi instead"
echo ""
echo " ./$myname run --alt-mpi-cmd : Use the command specified in the environmental"
echo " variable AWC_MPICMD to run WRF rather than mpirun -np \$ntasks. This must"
echo " be EXACTLY the command you would execute in the WRFV3/run directory to"
echo " start WRF. E.g. if you would use 'mpiexec -n 64 wrf.exe', then AWC_MPICMD"
echo " must be that whole command."
echo ""
echo " ./$myname run rst : will try to find the last wrfrst file within the"
echo " time period in the namelist in WRFV3/run and start from there."
echo " If it cannot find a wrfrst file, it will abort."
echo ""
echo " ./$myname run rst --allow-no-file : if no restart files in the proper"
echo " time period found, this will start from the beginning instead of"
echo " aborting."
echo ""
echo " ./$myname run --run-for=x : only run for x, where x is a time period in days,"
echo " hours, minutes, and seconds. Works with rst, in fact, is primarily intended"
echo " to work with rst so that you can break a long run up into smaller chunks."
Expand All @@ -119,6 +135,13 @@ while [ $# -gt 0 ]; do
echo " Example: ./$myname run rst --run-for=28d will run for 28 days from the last"
echo " restart file."
echo ""
echo " ./$myname run --dry-run : do everything normally done for $myname run"
echo " except start WRF; instead, it will print out the command it would use"
echo " This can be used with any of the previous flags to check how $myname"
echo " would modify the namelist, try to execute WRF, etc."
echo ""
echo ""
echo " ***************************** NOTES *****************************"
echo ""
echo " Exit codes for the compile and prepinpt steps will indicate which step"
echo " failed using the numeric value as a binary flag. For compile:"
Expand Down Expand Up @@ -196,6 +219,9 @@ while [ $# -gt 0 ]; do
--ntasks=*)
runargs="$runargs $1"
;;
--alt-mpi-cmd)
runargs="$runargs $1"
;;
--nompi)
runargs="$runargs $1"
;;
Expand All @@ -208,6 +234,9 @@ while [ $# -gt 0 ]; do
--run-for*)
runargs="$runargs $1"
;;
-D|--dry-run)
runargs="$runargs --dry-run"
;;
*)
echo "$1 is not a recognized option"
exit 1
Expand Down
37 changes: 30 additions & 7 deletions runwrf
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,11 @@ pydate="$mydir/Tools/datecompare.py"
# See if this was called with the "override" flag
override=false
usempi=true
useenvcmd=false
metonly=false
rst=false
errnorst=true
dryrun=false
while [ $# -gt 0 ]; do
case $1 in
override|--override)
Expand All @@ -30,6 +32,11 @@ while [ $# -gt 0 ]; do
--ntasks*)
i=`expr index "$1" "="`
ntasks=${1:i}
usempi=true
;;
--alt-mpi-cmd)
useenvcmd=true
usempi=true
;;
--nompi)
usempi=false
Expand All @@ -44,14 +51,19 @@ while [ $# -gt 0 ]; do
i=`expr index $1 "="`
runfor=${1:i}
;;
--dry-run)
dryrun=true
;;
esac
shift
done


# INPUT CHECKING
if $usempi; then
if $usempi && ! $useenvcmd; then
if [ -z "$ntasks" ]; then
echo "Must pass a number of tasks to start with --ntasks= if running WRF in parallel"
echo "or use the --mpicmd= option to specify an alternate command to execute WRF."
echo "(give option --nompi to run using syntax ./wrf.exe)"
exit 1
fi
Expand Down Expand Up @@ -133,14 +145,25 @@ elif [[ ! -z $runfor ]]; then
python $pyprog tempmod $runtimearg
fi

# Format the run command
if $useenvcmd; then
if [[ -z $AWC_MPICMD ]]; then
echo "Error trying to use --alt-mpi-cmd: Environmental variable AWC_MPICMD not set"
exit 1
fi
runcmd="$AWC_MPICMD"
elif $usempi; then
runcmd="mpirun -np $ntasks wrf.exe"
else
runcmd="./wrf.exe >& runwrf.log"
fi

# Actually run WRF!
if $usempi; then
errorfile="rsl.error.0000"
mpirun -np $ntasks wrf.exe
wrfexit=$?
if $dryrun; then
echo "$runcmd in $(pwd)"
wrfexit=0
else
errorfile="runwrf.log"
./wrf.exe >& runwrf.log
$runcmd
wrfexit=$?
fi

Expand Down

0 comments on commit 17852ce

Please sign in to comment.