Sbatch
Submit sbatch script with dependency
Using this script, we were submitting a CP2K job continuously until it finishes successfully.
Additionally, since there will be situations when CP2K might not write the entire wavefunction before exiting a job (since the 2 hrs wall time could be over just at the time of wavefunction writing), we check for the presence of a backup wavefunction file. If it exists, then we check for the sizes of both the backup and original wfn files. If the file sizes do not match, then we copy the backup file as the original file and continue the run.
#!/bin/bash
#SBATCH --ntasks=64
#SBATCH --cpus-per-task=1
#SBATCH --mem-per-cpu=4G
#SBATCH -o my_output_%j
#SBATCH --job-name=MgO_Mg4L_MgO
#SBATCH -p short
#SBATCH --time=2:00:00
module load cp2k
# resubmit this same script, to only start after the current one ends
sbatch -d afternotok:$SLURM_JOB_ID submit.sbatch
FILE=./Mg_Batter-RESTART.wfn.bak-1
if [ -f "$FILE" ]; then
var0=$(stat -c%s Mg_Batter-RESTART.wfn)
var1=$(stat -c%s Mg_Batter-RESTART.wfn.bak-1)
if [[ "$var0" -lt "$var1" ]]; then
cp Mg_Batter-RESTART.wfn.bak-1 Mg_Batter-RESTART.wfn
fi
fi
mpirun -np 64 cp2k.popt -i pfas.inp -o pfas.out