-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstallMPICH.sh
executable file
·556 lines (479 loc) · 14.2 KB
/
installMPICH.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
#!/bin/sh
#
# (C) 2019 Andrey Tabakov <komdosh@yandex.ru>
# Script for download, unpack and build MPICH CH4 for developing purposes
##
# shellcheck disable=SC2039
################################
## Constants
################################
LOG_PREFIX="[InstallMPICH]:"
SCRIPT_SECONDS=0
ADDITIONAL_INSTALLATION_PATH_SUFFIX=""
MPICH_DIR_NAME="mpich"
INSTALLATION_PATH_PREFIX=$(pwd)"/$MPICH_DIR_NAME/compiled$ADDITIONAL_INSTALLATION_PATH_SUFFIX"
MPICH_PATH=""
SCRIPT_OSTYPE=""
MPICH_VERSION="3.3.2"
MPICH_NAME="mpich-$MPICH_VERSION"
MPICH_GITHUB_NAME="mpich"
LOG_FILE_PATH=$(pwd)"/installationLogs.txt"
CURRENT_MPICH_NAME=$MPICH_NAME
USAGE_EXAMPLES=" 1. Install MPICH with global critical sections
and avoid user prompt with default answers
sh installMPICH.sh -g -s
2. Install MPICH with per-vci trylock critical sections from github master branch
and avoid user prompt with default answers
sh installMPICH.sh -p trylock -s -b
3. Install MPICH with per-vci handoff critical sections from github 3.3.x branch with
source replace from ./dev directory
sh installMPICH.sh -p handoff -b 3.3.x -r"
HELP="
Usage: sh installMpich.sh [Build Option] [Ad Options]
Build MPICH option:
-g - global critical sections
-p [trylock, handoff] - per-vci critical section
-d - only download and unpack $CURRENT_MPICH_NAME from \"https://www.mpich.org/\"
Additional Options:
-s - skip manual input [auto launching of: remove previous build,
configure dirs, make && make install]
-r - replace sources from ./dev directory (sources must be in the same directory
path relative to ./dev as for MPICH)
-b [branch] - clone mpich sources from github pmodels/mpich
default branch is master \"https://github.com/pmodels/mpich\"
-i [yourPath] - additional installation path suffix to $INSTALLATION_PATH_PREFIX/{yourPath}/
-o - optimized installation build
-h - show this message
-l [logfile path] - MPICH configure and install logs will be print into this file
it is installationLogs.txt by default
Usage examples:
$USAGE_EXAMPLES
"
DEBUG_FLAGS="-g3 -gdwarf-2"
OSTYPE="$OSTYPE"
SCRIPT_OSTYPE="$OSTYPE"
################################
## Functions
################################
setupOSDeps() {
OSTYPE="$OSTYPE"
if test -z "$OSTYPE"; then
echo "Unknown operation system, script may not work properly"
fi
if test "$OSTYPE" == "linux-gnu"; then
SCRIPT_OSTYPE="linux-gnu"
INSTALL="apt-get"
else
local os
os=$(echo "$OSTYPE" | cut -c1-6)
if test "$os" == "darwin"; then
SCRIPT_OSTYPE="darwin"
INSTALL="brew"
else
echo "$LOG_PREFIX Unknown OS: $OSTYPE. Only GNU Linux or MacOS is allowed for INSTALL"
fi
fi
if test "$SCRIPT_OSTYPE" == "darwin"; then
if test "$CC_PATH" == ""; then
CC_PATH=/usr/local/bin/gcc-9
fi
if test "$CXX_PATH" == ""; then
CXX_PATH=/usr/local/bin/g++-9
fi
echo "$LOG_PREFIX You should install gcc and g++ by your own, and set CC_PATH and
CXX_PATH environment variable, now CC_PATH=$CC_PATH, CXX_PATH=$CXX_PATH"
export CC=$CC_PATH
export CXX=$CXX_PATH
fi
}
restoreMPICH() {
removeOldInstallation "$CURRENT_MPICH_NAME"
getMPICH
}
getMPICH() {
SECONDS=0
local tarExtension="tar.gz"
if test "$github" = false; then
if test ! -f "$MPICH_NAME.$tarExtension"; then
echo "$LOG_PREFIX Download mpich sources from http://www.mpich.org ..."
eval "wget http://www.mpich.org/static/downloads/$MPICH_VERSION/$MPICH_NAME.$tarExtension"
else
echo "$LOG_PREFIX Sources already downloaded"
fi
echo "$LOG_PREFIX Unpack sources to $MPICH_NAME"
eval "tar -xzf $MPICH_NAME.$tarExtension"
showElapsedTime "MPICH downloaded"
else
cloneMpichGithub
showElapsedTime "MPICH downloaded"
fi
}
cloneMpichGithub() {
if test ! -f "$MPICH_GITHUB_NAME/README.vin"; then
echo "$LOG_PREFIX Clone mpich sources from github ..."
eval "git clone git@github.com:pmodels/mpich.git"
else
echo "$LOG_PREFIX Repo mpich already downloaded"
fi
if test ! -f "$MPICH_GITHUB_NAME/src/hwloc/README"; then
eval "cd $MPICH_GITHUB_NAME/src"
echo "$LOG_PREFIX Clone hwloc sources from github ..."
eval "git clone git@github.com:pmodels/hwloc.git"
eval "cd ../../"
else
echo "$LOG_PREFIX Repo hwloc already downloaded"
fi
if test ! -f "$MPICH_GITHUB_NAME/src/izem/README.md"; then
eval "cd $MPICH_GITHUB_NAME/src"
echo "$LOG_PREFIX Clone izem sources from github ..."
eval "git clone git@github.com:pmodels/izem.git"
eval "cd ../../"
else
echo "$LOG_PREFIX Repo izem already downloaded"
fi
if test ! -f "$MPICH_GITHUB_NAME/src/mpid/ch4/netmod/ucx/ucx/README.md"; then
eval "cd $MPICH_GITHUB_NAME/src/mpid/ch4/netmod/ucx"
echo "$LOG_PREFIX Clone ucx sources from github ..."
eval "git clone git@github.com:pmodels/ucx.git"
eval "cd ../../../../../../"
else
echo "$LOG_PREFIX Repo ucx already downloaded"
fi
if test ! -f "$MPICH_GITHUB_NAME/src/mpid/ch4/netmod/ofi/libfabric/README"; then
eval "cd $MPICH_GITHUB_NAME/src/mpid/ch4/netmod/ofi"
echo "$LOG_PREFIX Clone libfabric sources from github ..."
eval "git clone git@github.com:pmodels/libfabric.git"
eval "cd ../../../../../../"
else
echo "$LOG_PREFIX Repo libfabric already downloaded"
fi
}
getMPICHSources() {
local reinstallMPICH=""
if test ! -d "$CURRENT_MPICH_NAME"; then
echo "$LOG_PREFIX There is no installed MPICH. Download and unpack it.."
getMPICH
else
if test "$github" = false; then
echo "$LOG_PREFIX MPICH already downloaded and unpacked"
else
SECONDS=0
cloneMpichGithub
showElapsedTime "MPICH downloaded"
fi
if test "$auto" = false; then
read -r -p "Do you want to delete current mpich directory, download and unpack it again? [y/N]: " reinstallMPICH
else
reinstallMPICH="$replaceSources"
fi
if [ "$reinstallMPICH" = "n" ] || [ "$reinstallMPICH" = "N" ]; then
return 0
fi
restoreMPICH
fi
if test "$replaceSources" = true; then
echo "$LOG_PREFIX Replace sources from dev directory"
eval "cd $CURRENT_MPICH_NAME"
eval "cp -a ../../dev/. ./"
eval "cd ../"
fi
}
createMPICHDir() {
if test ! -d "$MPICH_DIR_NAME"; then
echo "$LOG_PREFIX Create MPICH directory"
mkdir mpich
else
echo "$LOG_PREFIX MPICH directory already exists"
fi
eval "cd $MPICH_DIR_NAME"
}
changeOwnershipToUser() {
dir="$1"
DIR_OWNER=$(ls -ld "$dir" | awk '{print $3}')
if test "$USER" != "$DIR_OWNER"; then
echo "$LOG_PREFIX this directory aleready belong to $USER"
return 0
fi
if ! [ "$(id -u)" -eq 0 ]; then
echo "$LOG_PREFIX This script doesn't have enough rights
to write to $dir directory. You should make it available."
return 0
fi
SCRIPT_USER=""
if test -z "$SUDO_USER"; then
SCRIPT_USER="$USER"
else
SCRIPT_USER="$SUDO_USER"
fi
chown -R "$SCRIPT_USER" "$dir"
}
initMPICHConfigureOpts() {
if test "$github" = true; then
changed=$(git fetch)
if ! [ -f "$MPICH_GIHUB_NAME/configure" ] || [ -n "$changed" ]; then
echo "$LOG_PREFIX Generate configure for MPICH"
sh ./autogen.sh >> "$LOG_FILE_PATH" 2>1
fi
fi
local threadCS=""
local izemConfig="" #izem necessary only for per-vci CS
local ch4mt="" #multithread algorithm necessary only for per-vci CS
case $1 in
global)
MPICH_PATH=$INSTALLATION_PATH_PREFIX$ADDITIONAL_INSTALLATION_PATH_SUFFIX"/global"
threadCS="global"
;;
handoff | trylock)
MPICH_PATH=$INSTALLATION_PATH_PREFIX$ADDITIONAL_INSTALLATION_PATH_SUFFIX"/per-vci-"$1
if test "$github" = false; then
threadCS="per-vni" #new mpich will use per-vci, instead of per-vni option
else
threadCS="per-vci"
fi
izemConfig="--enable-izem=queue \
--with-zm-prefix=embedded"
ch4mt="--enable-ch4-mt=$1"
;;
esac
echo "$LOG_PREFIX Configure MPICH with $threadCS CS to $MPICH_PATH"
removeOldInstallation "$MPICH_PATH"
if test "$optimizedBuild" = true; then
CFlags="CFLAGS=-O3"
CXXFlags="CXXFLAGS=-O3"
performanceKeys="--enable-fast=O3,ndebug \
--disable-error-checking \
--without-timing \
--without-mpit-pvars \
--enable-g=none"
else
CFlags="CFLAGS=\"$DEBUG_FLAGS\""
CXXFlags="CXXFLAGS=\"$DEBUG_FLAGS\""
performanceKeys="--enable-fast=O0 \
--enable-timing=all \
--enable-mutex-timing \
--enable-g=all"
fi
if test "$SCRIPT_OSTYPE" == "linux-gnu"; then
LIBFABRIC="/usr/lib64"
elif test "$SCRIPT_OSTYPE" == "darwin"; then
LIBFABRIC="/usr/local/Cellar/libfabric/1.6.2"
fi
MPICH_CONFIGURE_OPTS="$CFlags \
$CXXFlags \
--silent \
--prefix=$MPICH_PATH \
--with-hwloc=$INSTALLATION_PATH_PREFIX/hwloc \
--with-device=ch4:ofi \
--with-libfabric=$LIBFABRIC \
--enable-threads=multiple \
--enable-thread-cs=$threadCS \
--disable-fortran \
$performanceKeys \
$izemConfig \
$ch4mt"
echo "$LOG_PREFIX Configure MPICH: $MPICH_CONFIGURE_OPTS"
}
makeAndInstall() {
SECONDS=0
echo "$LOG_PREFIX Make and install MPICH sources"
make clean >> "$LOG_FILE_PATH"
make -j 7 >> "$LOG_FILE_PATH"
make install >> "$LOG_FILE_PATH"
showElapsedTime "MPICH installed"
}
removeOldInstallation() {
if test ! -d "$1"; then
return 0
fi
local removeAndContinue=""
if test "$auto" = false; then
read -r -p "Do you want to remove this directory and continue installation? [y/N]: " removeAndContinue
else
removeAndContinue="y"
fi
if test "$removeAndContinue" != "y" && test "$removeAndContinue" != "Y"; then
return 0
fi
eval "rm -rf $1"
}
installation() {
echo "$LOG_PREFIX MPICH installation started..."
createMPICHDir
getMPICHSources
eval "cd $CURRENT_MPICH_NAME"
installationType="$1"
SECONDS=0
case $installationType in
global)
initMPICHConfigureOpts "global"
;;
handoff)
initMPICHConfigureOpts "handoff"
;;
trylock)
initMPICHConfigureOpts "trylock"
;;
downloadUnpack)
# no action
;;
*)
echo "$LOG_PREFIX Wrong installation function ask developer for fix it"
;;
esac
showElapsedTime "MPICH options configured"
case $installationType in
global | handoff | trylock)
SECONDS=0
eval "./configure $MPICH_CONFIGURE_OPTS" >> "$LOG_FILE_PATH"
showElapsedTime "MPICH configured"
if test "$auto" = false; then
read -r -p "Do you want to make and install? [y/N]: " makeInstall
else
makeInstall="y"
fi
if test "$auto" = true || test "$makeInstall" = "y" || test "$makeInstall" = "Y"; then
makeAndInstall
fi
;;
esac
changeOwnershipToUser "$MPICH_PATH"
echo "$LOG_PREFIX MPICH installation finished! MPICH directory: $MPICH_PATH"
echo "$LOG_PREFIX now set path to mpicc: $MPICH_PATH/bin/mpicc
mpiexec: $MPICH_PATH/bin/mpiexec"
echo "$LOG_PREFIX Script worked for $((SCRIPT_SECONDS / 60)) min and $((SCRIPT_SECONDS % 60)) sec"
}
installHwloc() {
SECONDS=0
if test -d "$INSTALLATION_PATH_PREFIX/hwloc"; then
return 0
fi
gitPath=$(command -v git)
if test "$gitPath" = ""; then
eval "$INSTALL install git"
fi
if test ! -d "hwloc"; then
git clone https://github.com/open-mpi/hwloc.git
fi
cd hwloc || exit 1
autoconfPath=$(command -v autoconf)
if test "$autoconfPath" = ""; then
eval "$INSTALL install autogen"
eval "$INSTALL install autoconf"
if test "$SCRIPT_OSTYPE" != "darwin"; then
eval "$INSTALL install xorg-dev"
fi
fi
eval "$INSTALL install libtool"
./autogen.sh >> "$LOG_FILE_PATH"
eval "./configure --prefix=$INSTALLATION_PATH_PREFIX/hwloc" >> "$LOG_FILE_PATH"
make >> "$LOG_FILE_PATH"
make install >> "$LOG_FILE_PATH"
cd ../
showElapsedTime "hwloc installed"
}
initDefaultOptions() {
#skip user manual input:
# - auto make and install
# - auto remove previous build directory
auto=false
#replace mpich source files from ./dev directory
replaceSources=false
#optimized build without debug info
optimizedBuild=false
#get sources from github repo
github=false
#github branch
branch="master"
setupOSDeps
}
showElapsedTime() {
message=$1
duration=$SECONDS
SCRIPT_SECONDS="$((duration + SCRIPT_SECONDS))"
echo "$LOG_PREFIX $message in $(($duration / 60)) min and $(($duration % 60)) sec"
}
################################
## Entry point
################################
if test $# = 0; then
echo "No args passed to programm, you should pass at least one:
$HELP"
exit 1
fi
initDefaultOptions
while getopts ":srp:b:i:ol:" opt; do
case $opt in
s) #skip user manual input
echo "$LOG_PREFIX Skip manual input"
auto=true
;;
r) #replace mpich source files from ./dev directory
echo "$LOG_PREFIX ./dev sources is used"
replaceSources=true
;;
b) #set mpich source to github
github=true
CURRENT_MPICH_NAME=$MPICH_GITHUB_NAME
if test -n "$OPTARG"; then
branch=${OPTARG}
fi
echo "$LOG_PREFIX Github branch set to $branch"
;;
p) #check per-vci
perVciType=${OPTARG}
if test "$perVciType" != "trylock" && test "$perVciType" != "handoff"; then
echo "$LOG_PREFIX Wrong per-vci type, trylock or handoff only!"
exit 1
fi
;;
o) #optimized installation build
optimizedBuild=true
;;
i)
ADDITIONAL_INSTALLATION_PATH_SUFFIX=${OPTARG}
echo "$LOG_PREFIX Additional installation path suffix is set to $ADDITIONAL_INSTALLATION_PATH_SUFFIX"
;;
l)
LOG_FILE_PATH="${OPTARG}"
if test "$LOG_FILE_PATH" != "/dev/null"; then
rm -rf "$LOG_FILE_PATH"
fi
echo "$LOG_PREFIX logfile path set to $LOG_FILE_PATH"
;;
\?) #end of line
#do nothing
;;
:) #empty or unknown arg
#do nothing
;;
esac
done
OPTIND=1
installHwloc
while getopts ":gdhp:" opt; do
case $opt in
g) #global critical section
echo "$LOG_PREFIX Use global critical section"
installation "global"
;;
p) #per-vci
perVciType=${OPTARG}
echo "$LOG_PREFIX per-vci type is $perVciType"
installation "$perVciType"
;;
d) #download and unpack only
echo "$LOG_PREFIX Download and unpacking mpich"
installation "downloadUnpack"
;;
h) #help message
echo " $HELP"
;;
\?) #end of line
exit 1
;;
:) #empty or unknown arg
#do nothing
;;
esac
done
exit 0