-
Notifications
You must be signed in to change notification settings - Fork 0
/
job-env.sh
executable file
·71 lines (58 loc) · 1.96 KB
/
job-env.sh
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
#!/bin/bash
# This file either loads or creates an appropriate conda environment
NARGS="$#"
case $NARGS in
(0)
# Sets a default value for the environment name if not present
MY_NAME="mpi_and_thread"
;;
(1)
MY_NAME="$1"
;;
(*)
(>&2 echo "Error: did not expect more than one argument.")
(>&2 echo " (Got $@)")
exit 1
;;
esac
# Loads necessary ACCRE packages
# formerly: setpkgs -a anaconda3
module purge
module load Anaconda2
# Checks if environment name is valid and, if so, exports name
if [[ "$MY_NAME" =~ ^[0-9A-Za-z_]+$ ]]; then
export MY_CONDA_ENV=$MY_NAME ;
else
(>&2 echo "Invalid name $MY_NAME$")
exit 1
fi
# If the conda environment exists, then activates the environment
# else creates the new conda environment with the Makefile
if $(conda env list | grep -q $MY_CONDA_ENV); then
echo "Found existing conda environment $MY_CONDA_ENV"
source activate $MY_CONDA_ENV
else
echo "Creating conda environment $MY_CONDA_ENV";
#make env
source activate $MY_CONDA_ENV
make install
make test
fi
## Set additional environment variables
# PROFILE should point to a network drive, otherwise, the JSON created
# by ipcontroller needs to be copies to each host.
# The path provided here is stored in $HOME/.ipython/profile_/
export PROFILE=job_${SLURM_JOB_ID}_$(hostname)
echo "Creating profile ${PROFILE}"
ipython profile create ${PROFILE}
# Creates roles for each task to be run in parallel
LAST_PROC=$(( $SLURM_NTASKS - 1 )) # id of the last process
cluster_conf=$"# This file has been generated by $0\n"
cluster_conf+=$"0 ./cluster-roles.sh controller\n"
cluster_conf+=$"1-$LAST_PROC ./cluster-roles.sh engine"
echo -e $cluster_conf > cluster.conf
# Creates output filename including timestamp
OUTFILE=pi_estimate$(date +%Y%m%d_%H%M%S).txt
echo Using output file $OUTFILE
#export APP="python echo.py --profile ${PROFILE} -n 1e12 -o $OUTFILE"
export APP="jupyter notebook --ip='*' --port=9999 --no-browser &"