Skip to content

Instantly share code, notes, and snippets.

@jklymak
Last active January 12, 2021 00:46
Show Gist options
  • Save jklymak/2875a65efc574037e574e5621afbe158 to your computer and use it in GitHub Desktop.
Save jklymak/2875a65efc574037e574e5621afbe158 to your computer and use it in GitHub Desktop.

Chaining multiple MITgcm jobs

These were done for AbHillInter, on the machine koehr.

runAll.sh

#!/bin/sh -l
todo=Iso1kmlowU10Amp305f141B059Wall

one=$(qsub -N $todo -v "start=0, stop=259300, dt=50" runModelRestarts.sh)
two=$(qsub -N $todo -v "start=259200, stop=518500, dt=50"  -W depend=afterok:$one runModelRestarts.sh)
three=$(qsub -N $todo -v "start=518400, stop=777700, dt=50" -W depend=afterok:$two runModelRestarts.sh)
four=$(qsub -N $todo -v "start=777600, stop=907300, dt=50" -W depend=afterok:$three runModelRestarts.sh)

runModelRestarts.sh

#!/bin/sh -l
#PBS -m be
#PBS -M [email protected]
#PBS -l select=1:ncpus=48:mpiprocs=48
#PBS -l walltime=02:40:00
#PBS -q background
#PBS -A ONRDC35552400
#PBS -j oe
#PBS -N ${JOBNAME}

# run from runAll.sh  start and stop come from -v arguments.

module swap mpt compiler/intelmpi

cd $PBS_O_WORKDIR

PARENT=AbHillInter
top=${PBS_JOBNAME}
results=${WORKDIR}/${PARENT}/
outdir=$results$top

cd $outdir/input
pwd
ls -al ../build/mitgcmuv

python moddata.py --startTime=$start --endTime=$stop --deltaT=$dt

printf "Starting: $outdir\n"
mpirun -np 48 ../build/mitgcmuv > mit.out

moddata.py

import sys
import getopt

from tempfile import mkstemp
from shutil import move
from os import fdopen, remove

def replace_data(fname, param, value):
    fh, abs_path = mkstemp()
    print(abs_path)
    with fdopen(fh,'w') as new_file:
        with open(fname) as old_file:
            for line in old_file:
                if param+'=' in line:
                    new_file.write(' '+param+'='+value+',\n')
                else:
                    new_file.write(line)

    # Remove original file
    remove(fname)
    # Move new file
    move(abs_path, fname)

fname = './data'

# Get full command-line arguments
full_cmd_arguments = sys.argv

# Keep all but the first
argument_list = full_cmd_arguments[1:]

short_options = "se"
long_options = ["startTime=", "endTime=", "deltaT="]
arguments, values = getopt.getopt(argument_list, short_options, long_options)
for arg in arguments:
    replace_data(fname, arg[0][2:], arg[1])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment