-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy.sh
executable file
·261 lines (241 loc) · 7.63 KB
/
deploy.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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
#!/bin/bash
# strict mode
set -euo pipefail
IFS=$'\n\t'
SCRIPT_NAME=$0
JACOBI_MPI_VERSION=$(curl -s -L https://raw.githubusercontent.com/bissim/Jacobi-MPI/master/VERSION)
JACOBI_MPI_REPOSITORY=https://github.com/bissim/Jacobi-MPI
JACOBI_MPI_BIN=jacobi-mpi.tar.gz
JACOBI_MPI_BIN_URL=${JACOBI_MPI_REPOSITORY}/releases/download/${JACOBI_MPI_VERSION}/${JACOBI_MPI_BIN}
OPENMPI_VERSION=4.0.3
OPENMPI_ARCHIVE=openmpi-${OPENMPI_VERSION}.tar.gz
OPENMPI_RPM_NAME=openmpi-${OPENMPI_VERSION}-1.src
OPENMPI_RPM=${OPENMPI_RPM_NAME}.rpm
OPENMPI_URL=https://download.open-mpi.org/release/open-mpi/v4.0/${OPENMPI_ARCHIVE}
OPENMPI_RPM_URL=https://download.open-mpi.org/release/open-mpi/v4.0/${OPENMPI_RPM}
IS_MASTER=0
CLUSTER_DIM=0
HOSTFILE="hostfile"
PEM_KEY=""
ROOT=""
USERNAME=""
PASSWORD=""
PROGRAM=""
PROGRAM_DIM=""
RESULTS_FILE=""
#
# evaluate script parameters
#
while [[ "${1-0}" =~ ^- && ! "${1-0}" == "--" ]]; do
case $1 in
( -k | --key )
shift;
PEM_KEY=$1
;;
( -R | --root )
shift;
ROOT=$1
;;
( -u | --username)
shift;
USERNAME=$1
;;
( -p | --password)
shift;
PASSWORD=$1
;;
( -n | --number-of-nodes )
shift;
CLUSTER_DIM=$1
;;
( -M | --master )
IS_MASTER=1
;;
( -P | --program)
shift;
PROGRAM=$1
;;
( -r | --results-file )
shift;
RESULTS_FILE=$1
;;
( -d | --dimension )
shift;
PROGRAM_DIM=$1
;;
( * )
echo "Invalid parameter specified!"
exit
;;
esac;
shift;
done
#
# distribute script to nodes ASAP
#
if (( $IS_MASTER == 1 )); then
echo -e "\nPropagating $SCRIPT_NAME to other nodes..."
for (( i=1; i<$CLUSTER_DIM; i++ )); do
# first, send the script
echo -e "\nCopying $SCRIPT_NAME on NODE_$i..."
sudo cp ./$SCRIPT_NAME /home/$USERNAME/
sudo -u $USERNAME scp -oStrictHostKeyChecking=no /home/$USERNAME/$SCRIPT_NAME $USERNAME@NODE_${i}:~
# then, execute it
echo -e "\nRunning $SCRIPT_NAME on NODE_$i..."
REMOTE_COMMAND="/home/$USERNAME/${SCRIPT_NAME} -R $ROOT -u $USERNAME -p $PASSWORD"
ssh -oStrictHostKeyChecking=no -i $PEM_KEY $ROOT@NODE_${i} "$REMOTE_COMMAND" &
done
fi
#
# update remote repositories
#
echo -e "\nUpdate repositories"
#sudo add-apt-repository universe
sudo apt update #&& sudo apt upgrade -y
#
# install build essential to build OpenMPI
#
echo -e "\nInstall dependencies"
sudo apt install build-essential -y
if [[ ! -e /usr/local/bin/mpiexec ]]; then
echo "OpenMPI 4 not installed, downloading and installing..."
#
# download and extract OpenMPI source code
#
wget "$OPENMPI_URL" -O ./$OPENMPI_ARCHIVE && tar -xzf ./$OPENMPI_ARCHIVE
#wget "$OPENMPI_RPM_URL" -O ./$OPENMPI_RPM
#
# configure, build and install OpenMPI
# note: this won't work on t2.micro instances!
#
# compile from binaries
cd ./openmpi-${OPENMPI_VERSION}/
./configure --prefix="/usr/local"
make -j && sudo make install && sudo ldconfig
cd ..
fi
# install from APT
#sudo apt install openmpi-bin libopenmpi-dev -y
#sudo cp ... /usr/include/mpi/
# install from RPT package
#sudo alien ${OPENMPI_RPM}
#sudo dpkg -i ${OPENMPI_RPM_NAME}.deb
#
# download and extract binaries
#
#echo -e "\nDownload $JACOBI_MPI_BIN archive"
#wget "${JACOBI_MPI_BIN_URL}" -O ./$JACOBI_MPI_BIN && tar -xzf ./$JACOBI_MPI_BIN
#sudo cp ./bin/$PROGRAM /home/$USERNAME/$PROGRAM
#
# MASTER has more things to do then
#
if (( $IS_MASTER == 1 )); then
#
# install LLVM repository
#
LLVM_APT_SOURCE=llvm.list
if [[ ! -e /etc/apt/sources.list.d/$LLVM_APT_SOURCE ]]; then
echo -e "\nSet LLVM repositories"
touch $LLVM_APT_SOURCE
echo "# i386 not available" > $LLVM_APT_SOURCE
echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic main" >> $LLVM_APT_SOURCE
echo "deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic main" >> $LLVM_APT_SOURCE
echo "# 9" >> $LLVM_APT_SOURCE
echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main" >> $LLVM_APT_SOURCE
echo "deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-9 main" >> $LLVM_APT_SOURCE
echo "# 10" >> $LLVM_APT_SOURCE
echo "deb http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main" >> $LLVM_APT_SOURCE
echo "deb-src http://apt.llvm.org/bionic/ llvm-toolchain-bionic-10 main" >> $LLVM_APT_SOURCE
sudo mv $LLVM_APT_SOURCE /etc/apt/sources.list.d/
sudo chmod 644 /etc/apt/sources.list.d/$LLVM_APT_SOURCE
sudo chown root:root /etc/apt/sources.list.d/$LLVM_APT_SOURCE
wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
fi
#
# install Clang
#
echo -e "\nInstall Clang"
sudo apt clean
sudo apt update
sudo apt install clang -y
#
# clone and compile project
#
if [[ -e ./Jacobi-MPI/ ]]; then
rm -rf ./Jacobi-MPI/
fi
git clone "$JACOBI_MPI_REPOSITORY.git"
cd Jacobi-MPI/
echo -e "\nBuilding Jacobi MPI, version $(cat ./VERSION)"
mkdir bin
make
cd ..
mv ./Jacobi-MPI/bin/$PROGRAM .
#
# download and extract binaries
#
#echo -e "\nDownload $JACOBI_MPI_BIN archive"
#wget "${JACOBI_MPI_BIN_URL}" -O ./$JACOBI_MPI_BIN && tar -xzf ./$JACOBI_MPI_BIN
sudo cp ./$PROGRAM /home/$USERNAME/$PROGRAM
sudo chown $USERNAME:root /home/$USERNAME/$PROGRAM
sudo chmod 777 /home/$USERNAME/$PROGRAM
#
# distribute parallel binaries to all nodes
#
echo -e "\nDistributing $PROGRAM to all cluster nodes..."
for (( i=1; i<$CLUSTER_DIM; i++ )); do
sudo -u $USERNAME scp -oStrictHostKeyChecking=no /home/$USERNAME/$PROGRAM $USERNAME@NODE_${i}:~
done
#
# generate the hostfile
#
echo -e "\nGenerating hostfile for $CLUSTER_DIM nodes..."
#if [[ -e $HOSTFILE ]]; then
# > $HOSTFILE
#fi
#echo "MASTER" > $HOSTFILE
#for (( i=1; i<$CLUSTER_DIM; i++ )); do
# echo "NODE_$i" >> $HOSTFILE # these won't do
#done
#sudo mv $HOSTFILE /home/$USERNAME/$HOSTFILE
. ip_private_list.array
#for (( i=1; i<=${#ip_private_list[@]}; i++ ))
#do
# ## erase current hostfile if already exists
# if [[ -e $HOSTFILE"_$i" ]]
# then
# > $HOSTFILE"_$i"
# fi
# for private_ip in "${ip_private_list[@]:0:$i}"
# do
# echo $private_ip >> $HOSTFILE"_$i"
# done
# sudo mv $HOSTFILE"_$i" /home/$USERNAME/$HOSTFILE"_$i"
#done
## erase current hostfile if already exists
if [[ -e $HOSTFILE ]]; then
> $HOSTFILE
fi
for private_ip in ${ip_private_list[@]}; do
echo $private_ip >> $HOSTFILE
done
sudo cp $HOSTFILE /home/$USERNAME/$HOSTFILE
#
# copy user keys to send and run scripts remotely
#
echo -e "\nCopying $USERNAME key to communicate with other nodes..."
sudo cp /home/pcpc/.ssh/id_rsa .ssh/
sudo cp /home/pcpc/.ssh/id_rsa.pub .ssh/
sudo chown $ROOT:root .ssh/id_rsa .ssh/id_rsa.pub
#
# wait for nodes preparation running in background
#
wait
echo -e "\nCluster is ready to run $PROGRAM in parallel with MPI!"
#
# at last, run MPI program (actually, not here!)
#
#echo -e "\nRunning $PROGRAM..."
#NPROC=$(nproc)*CLUSTER_DIM
#sudo -u $USERNAME mpiexec -np $NPROC --hostfile /home/$USERNAME/$HOSTFILE"_$CLUSTER_DIM" /home/$USERNAME/$PROGRAM $PROGRAM_DIM /home/$USERNAME/$RESULTS_FILE
fi