-
Notifications
You must be signed in to change notification settings - Fork 1
/
gmx-k8s
executable file
·120 lines (98 loc) · 2.13 KB
/
gmx-k8s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/bin/bash
#XXX
IMAGE=ljocha/gromacs:2021-2
name=$(LC_CTYPE=C tr -cd '[:digit:][:lower:]' </dev/urandom | head -c 9)
yaml=/tmp/gmx-$name.yaml
run=gmx-$name.sh
mpi=1
input=
oGPU=1
gpumem=8
prog=gmx
while getopts n:i:g:m:v:w:N:p: opt; do case "$opt" in
n) mpi=$OPTARG;;
i) input="$OPTARG";;
g) oGPU="$OPTARG";;
m) gpumem="$OPTARG";;
v) WORK_VOLUME="$OPTARG";;
w) WORKDIR_RELATIVE="$OPTARG";;
N) K8S_NS="$OPTARG";;
p) prog="$OPTARG";;
?) exit 1;;
esac
done
shift $(($OPTIND - 1))
[ -n "$K8S_NS" ] && ns="-n $K8S_NS"
args=''
for a in "$@"; do
args="$args '$a'"
done
cat - >$run <<EOF
#!/bin/bash
echo "$input" | tr , '\012' | mpirun -np $mpi $prog $args >gmx-$name.out 2>gmx-$name.err
echo \$? >gmx-$name.ret.\$\$
mv gmx-$name.ret.\$\$ gmx-$name.ret
EOF
chmod +x $run
CPU=1
GPU=0
if [ "$1" = mdrun -o $(basename $0) = mdrun ]; then
GPU=$oGPU
omp=1
for a in "$@"; do
[ $omp = y ] && omp=$a
[ $a = -ntomp ] && omp=y
done
CPU=$(($omp * $mpi))
fi
MEM=$((4 * $CPU))Gi
cat - >$yaml <<EOF
apiVersion: batch/v1
kind: Job
metadata:
name: gmx-$name
spec:
ttlSecondsAfterFinished: 20
template:
spec:
securityContext:
runAsUser: 1001
runAsGroup: 1002
fsGroup: 1002
fsGroupChangePolicy: "OnRootMismatch"
containers:
- name: gmx
image: $IMAGE
resources:
requests:
cpu: $CPU
memory: $MEM
limits:
cpu: $CPU
memory: $MEM
nvidia.com/gpu: $GPU
cerit.io/gpu-mem: $gpumem
volumeMounts:
- mountPath: /work
name: work-volume
workingDir: /work/${WORKDIR_RELATIVE}
command: [ "./$run" ]
restartPolicy: Never
volumes:
- name: work-volume
persistentVolumeClaim:
claimName: ${WORK_VOLUME:=test-volume}
EOF
#cat $yaml
kubectl apply $ns -f $yaml
while [ ! -f gmx-$name.ret ]; do
ls . >/dev/null
sleep 2
done
kubectl logs job.batch/gmx-$name $ns
cat gmx-$name.out
cat gmx-$name.err >&2
ret=$(cat gmx-$name.ret)
kubectl delete job.batch/gmx-$name $ns
# rm $yaml gmx-$name.ret gmx-$name.out gmx-$name.err
exit $ret