|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +PARTITION=sauer # teach coms sauer |
| 4 | +NCPUS=8 # cores per job |
| 5 | +NBATCH=500 # input per batch |
| 6 | +EXTENSION=mop # extension to pack |
| 7 | +OUTEXT=out # extension to unpack |
| 8 | + |
| 9 | +# Check ssh key is setup |
| 10 | +ssh_pri=`ssh-keygen -y -f ~/.ssh/id_rsa` |
| 11 | +ssh_pub=`cat ~/.ssh/id_rsa.pub` |
| 12 | +if [[ $ssh_pub != $ssh_pri* ]]; then |
| 13 | + |
| 14 | + echo |
| 15 | + echo "SSH key not setup. Please run 'ssh-keygen' in the terminal," |
| 16 | + echo "to setup a key-pair (ssh with no password), before running this" |
| 17 | + echo "script" |
| 18 | + echo |
| 19 | + |
| 20 | + exit 4 |
| 21 | +fi |
| 22 | + |
| 23 | +# note |
| 24 | +# #SBATCH -w, --nodelist=asusnode103 |
| 25 | + |
| 26 | +PWD=`pwd` |
| 27 | +JOB=${PWD##*/} |
| 28 | +SUBMIT=qsub.tmp |
| 29 | +host=$HOSTNAME |
| 30 | + |
| 31 | + |
| 32 | +files=`ls -f *$EXTENSION` |
| 33 | + |
| 34 | +# Remove input files which is already done |
| 35 | +out_files=`ls -f *.$OUTEXT 2> /dev/null` |
| 36 | + |
| 37 | +for x in $out_files; do |
| 38 | + inp=${x%.*}.$EXTENSION |
| 39 | + files=`echo $files | sed "s/$inp//"` |
| 40 | +done |
| 41 | + |
| 42 | +foo=( $files ) |
| 43 | +nfiles=`echo "$files" | wc -w` |
| 44 | + |
| 45 | +echo $files |
| 46 | +echo $nfiles |
| 47 | + |
| 48 | +counter=0 |
| 49 | +while [ $counter -lt $nfiles ]; do |
| 50 | + |
| 51 | + tarfile=batch_${counter}.tar.gz |
| 52 | + outfile=batch_${counter}_log.tar.gz |
| 53 | + |
| 54 | + tar -czf $tarfile ${foo[@]:$counter:$NBATCH} |
| 55 | + |
| 56 | + cjob=$JOB\_\_$counter |
| 57 | + |
| 58 | + cat > $SUBMIT <<!EOF |
| 59 | +#!/bin/bash |
| 60 | +#SBATCH --job-name=$cjob |
| 61 | +#SBATCH --nodes=1 |
| 62 | +#SBATCH --cpus-per-task=$NCPUS |
| 63 | +#SBATCH --ntasks=1 |
| 64 | +#SBATCH --error=$PWD/$cjob\_%j.stderr |
| 65 | +#SBATCH --output=$PWD/$cjob\_%j.stdout |
| 66 | +#SBATCH --time=100:00:00 |
| 67 | +#SBATCH --partition=$PARTITION |
| 68 | +#SBATCH --no-requeue |
| 69 | +
|
| 70 | +
|
| 71 | +start=\`date +%s\` |
| 72 | +
|
| 73 | +
|
| 74 | +nodename=\$HOSTNAME |
| 75 | +echo 0 "Running on \$nodename" |
| 76 | +echo 0 "un-tar input files" |
| 77 | +
|
| 78 | +
|
| 79 | +mkdir /scratch/\$SLURM_JOB_ID |
| 80 | +cd /scratch/\$SLURM_JOB_ID |
| 81 | +
|
| 82 | +
|
| 83 | +cp $PWD/$tarfile . |
| 84 | +tar -xzf $tarfile |
| 85 | +
|
| 86 | +# MOPAC |
| 87 | +
|
| 88 | +cp -r /opt/mopac . |
| 89 | +cp -r /opt/intel/composer_xe_2013.1.117/compiler/lib/intel64 . |
| 90 | +export LD_LIBRARY_PATH=/scratch/\$SLURM_JOB_ID/intel64:$LD_LIBRARY_PATH |
| 91 | +export MKL_NUM_THREADS=1 |
| 92 | +
|
| 93 | +run_calculation () { |
| 94 | +
|
| 95 | + input=\${1%.*} |
| 96 | + echo \$input |
| 97 | + /scratch/\$SLURM_JOB_ID/mopac/MOPAC2016.exe \$input > /dev/null 2> /dev/null |
| 98 | +
|
| 99 | +} |
| 100 | +
|
| 101 | +export -f run_calculation |
| 102 | +
|
| 103 | +# END MOPAC |
| 104 | +
|
| 105 | +
|
| 106 | +end=\`date +%s\` |
| 107 | +runtime=\$((end-start)) |
| 108 | +echo \$runtime "run calculation" |
| 109 | +
|
| 110 | +
|
| 111 | +ls -f *.$EXTENSION | parallel -j$NCPUS "run_calculation {}" |
| 112 | +
|
| 113 | +
|
| 114 | +end=\`date +%s\` |
| 115 | +runtime=\$((end-start)) |
| 116 | +echo \$runtime "tar output" |
| 117 | +
|
| 118 | +
|
| 119 | +tar -czf $outfile *.$OUTEXT |
| 120 | +cp $outfile $PWD |
| 121 | +
|
| 122 | +
|
| 123 | +end=\`date +%s\` |
| 124 | +runtime=\$((end-start)) |
| 125 | +echo \$runtime "untar in $PWD" |
| 126 | +
|
| 127 | +
|
| 128 | +ssh sunray "cd $PWD && tar xzf $outfile" |
| 129 | +
|
| 130 | +
|
| 131 | +end=\`date +%s\` |
| 132 | +runtime=\$((end-start)) |
| 133 | +echo \$runtime "done" |
| 134 | +
|
| 135 | +
|
| 136 | +convertsecs() { |
| 137 | + ((h=\${1}/3600)) |
| 138 | + ((m=(\${1}%3600)/60)) |
| 139 | + ((s=\${1}%60)) |
| 140 | + printf "%02d:%02d:%02d\n" \$h \$m \$s |
| 141 | +} |
| 142 | +
|
| 143 | +convertsecs \$runtime |
| 144 | +
|
| 145 | +!EOF |
| 146 | + |
| 147 | + # submit batch |
| 148 | + sbatch $SUBMIT |
| 149 | + |
| 150 | + # next |
| 151 | + let counter+=$NBATCH |
| 152 | + |
| 153 | +done |
| 154 | + |
| 155 | + |
| 156 | + |
0 commit comments