-
Notifications
You must be signed in to change notification settings - Fork 5
/
openmpi_build.sh
executable file
·354 lines (328 loc) · 13.3 KB
/
openmpi_build.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
#!/bin/bash
#
###################################################################################
# Copyright (c) 2009, Los Alamos National Security, LLC All rights reserved.
# Copyright 2009. Los Alamos National Security, LLC. This software was produced
# under U.S. Government contract DE-AC52-06NA25396 for Los Alamos National
# Laboratory (LANL), which is operated by Los Alamos National Security, LLC for
# the U.S. Department of Energy. The U.S. Government has rights to use,
# reproduce, and distribute this software. NEITHER THE GOVERNMENT NOR LOS
# ALAMOS NATIONAL SECURITY, LLC MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR
# ASSUMES ANY LIABILITY FOR THE USE OF THIS SOFTWARE. If software is
# modified to produce derivative works, such modified software should be
# clearly marked, so as not to confuse it with the version available from
# LANL.
#
# Additionally, redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following conditions are
# met:
#
# Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
#
# Neither the name of Los Alamos National Security, LLC, Los Alamos National
# Laboratory, LANL, the U.S. Government, nor the names of its contributors may be
# used to endorse or promote products derived from this software without specific
# prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY LOS ALAMOS NATIONAL SECURITY, LLC AND CONTRIBUTORS
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
# THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
# ARE DISCLAIMED. IN NO EVENT SHALL LOS ALAMOS NATIONAL SECURITY, LLC OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
# EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
# OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
# IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
# OF SUCH DAMAGE.
###################################################################################
#
#
# This script will extract openmpi source from a tarball, patch it against
# plfs, and compile it. It expects appropriate flags for building against
# PLFS to be in the environment variables RS_PLFS_LDFLAGS and RS_PLFS_CFLAGS.
# Tarball to use
tarball="$1"
# Where to extract tarball
srcdir="$2"
# Where to put installation
openmpi_instdir="$3"
# Where the plfs source directory is located
plfs_srcdir="$4"
# What platform file to use as a template
platform_file="$5"
if [ "$tarball" == "" ] || [ "$srcdir" == "" ] ||
[ "$openmpi_instdir" == "" ] || [ "$plfs_srcdir" == "" ] ||
[ "$platform_file" == "" ]; then
echo "Error: missing one or more command line parameters."
echo ""
echo "Usage:"
echo "$0 TB SRC OINST PSRC PINST PFILE"
echo -e "\tTB is the tarball to extract openmpi from."
echo -e "\tSRC is the directory to extract TB into."
echo -e "\tOINST is the installation directory for openmpi."
echo -e "\tPSRC is the PLFS source directory."
echo -e "\tPFILE is the platform file that will be used as a template when building open mpi."
exit 1
fi
# I assume that the top-level directory in the openmpi tarball is the same as
# the tarball's name without ".tar.bz2". I also assume that the tarball is
# named as follows: openmpi-<version>.tar.bz2 where version contains only
# digits and decimal points like this: 1.6.0 or 1.5, etc.
# Get the basename of the openmpi tarball, then figure out what name
# the directory will be when unarchived.
openmpi_name=`basename $tarball | sed 's/\.tar.*$//'`
# Figure out the version of openmpi from openmpi_name
version=${openmpi_name#openmpi-}
# Function to check the exit status of the last command
function check_exit {
if [[ $1 == 0 ]]; then
echo "$2 succeeded."
else
echo "Error: $2 failed."
exit 1
fi
}
# Function to find a patch file in the plfs source tree that is suitable for a
# given version of Open MPI. It will modify the variable PATCH_FILE so that the
# result can be easily used by the calling process. This function prints out
# messages as it works, so capturing its stdout isn't enough to get the patch
# file.
#
# Since a single patch file can cover several versions of Open MPI
# (signified by the use of an x in the version string in the patch file name),
# we have to figure out which patch file can be used with the given version of
# Open MPI.
#
# Usage:
# find_patchfile VER
#
# Input:
# - VER: version of Open MPI that we are working with.
#
# Return values:
# - 0: Suitable patch file found successfully
# - 1: Suitable patch file not found
#
# Output:
# - various status messages to stdout
# - PATCH_FILE: this variable will possibly contain, after executing this
# function, a path to a suitable patch file. The path will be relative to the
# plfs source directory. This variable should be set before calling this
# function and then can be used after this function returns. It is not
# initialized by this function and will not modify it if a suitable patch is
# not found.
function find_patchfile {
ver=$1
patches_dir="patches/openmpi"
i=0
# Check for a ompi-<version>-plfs-prep.patch file. Then, iterate up the
# periods in the version string to see if a patch that works for more than
# one version is found. For example, if the version string is 4.5.6, look
# for 4.5.6.patch, 4.5.x.patch, and 4.x.patch
# First, put the digits in the version variable into an array so that each
# digit can be treated separately. Each digit will be a token.
old_IFS=$IFS
IFS="."
ver_toks=( $ver )
IFS=$old_IFS
# Get the number of digits
num_toks=${#ver_toks[*]}
# There are num_toks - 1 possible strings to construct from the version
# number. Loop over them.
while [ $i -lt $num_toks ]; do
string=""
j=0
# Construct a version string from ver_toks
while [ $j -lt $(($num_toks - $i)) ]; do
string="${string}${ver_toks[$j]}"
j=$(($j + 1))
if [ ! $j -eq $(($num_toks - $i)) ]; then
string="${string}."
fi
done
# If i is 0, then all of the tokens are in string. Don't add a .x
# place holder for this case. For all other values of i, there is at least
# one token missing, so a .x needs to be appended.
if [ ! $i -eq 0 ]; then
string="${string}.x"
fi
tfile="${patches_dir}/ompi-${string}-plfs-prep.patch"
echo -n "Checking for $tfile..."
if [ -e "$tfile" ]; then
echo "found"
PATCH_FILE=$tfile
break
else
echo "not found"
fi
i=$(($i + 1))
done
# If a suitable patch file hasn't been found, check down the version
# string for either a 0 or an x. For example, if the version
# string is 6.1, look for 6.1.0.patch and 6.1.x.patch. Keeping going
# down levels until files don't exist with more .0 in the string. For
# exmaple, if the version string is 6.1 and 6.1.[0|x].patch doesn't exist,
# but ls on 6.1.0*.patch returns filenames, check for 6.1.0.0.patch and
# 6.1.0.x.patch. Keep going until tacking on another .0 to the version
# fails to find any files via ls.
if [ "$PATCH_FILE" == "" ]; then
cver=$ver
while [ 1 ]; do
# Check for $cver.0.patch and $cver.x.patch
for tfile in ${patches_dir}/ompi-${cver}.0-plfs-prep.patch \
${patches_dir}/ompi-${cver}.x-plfs-prep.patch; do
echo -n "Checking for $tfile..."
if [ -e "$tfile" ]; then
echo "found"
PATCH_FILE=$tfile
break
else
echo "not found"
fi
done
# If we didn't find it, check to see if
# ad-patches/openmpi/*cver.0* exists. If so, reset cver and try again.
# If not, break out of the while loop.
if [ "$PATCH_FILE" == "" ]; then
ls -1 ${patches_dir} | grep ${cver}.0 2>&1 >> /dev/null
if [[ $? == 0 ]]; then
cver="${cver}.0"
else
break
fi
else
# A patch file was found in the last for loop. Break out of the
# while loop.
break
fi
done
fi
# Check to see if we found a patch file
if [ "$PATCH_FILE" != "" ]; then
echo "Using $PATCH_FILE"
else
echo "Suitable patch file not found."
return 1
fi
return 0
}
# Figure out the PLFS build flags that we need to use when building Open MPI
flags=`tests/utils/rs_plfs_buildflags_get.py`
if [[ $? != 0 ]]; then
echo "Problem getting PLFS build flags"
exit 1
fi
rs_plfs_cflags=`echo "$flags" | head -n 1`
rs_plfs_ldflags=`echo "$flags" | tail -n 1`
# Go to the plfs source directory
echo "Entering $plfs_srcdir/mpi_adio"
if [ ! -d "$plfs_srcdir/mpi_adio" ]; then
echo "Error: $plfs_srcdir/mpi_adio does not exist."
exit 1
fi
cd "$plfs_srcdir/mpi_adio"
# Run the make_plfs_patch script to generate ompi-plfs.patch. Capture the
# output to figure out what the name of the generated patch file is.
echo "Running ./scripts/make_plfs_patch"
./scripts/make_ad_plfs_patch | tee ./.mk_plfs_ptch_output_file
ad_plfs_patch_file=`tail -n 1 ./.mk_plfs_ptch_output_file | awk '{print $NF}'`
rm -f ./.mk_plfs_ptch_output_file
# Check that the patch file exists and is not size zero.
if [ ! -f "$ad_plfs_patch_file" ] || [ ! -s "$ad_plfs_patch_file" ]; then
echo "Problem generating patch file."
exit 1
fi
# We need to figure out what prep.patch file to use for this version of Open
# MPI. The find_patchfile function will do this. It will modify the following
# variable, PATCH_FILE, to be the file that we need.
PATCH_FILE=""
find_patchfile $version
if [[ $? != 0 ]]; then
exit 1
fi
# If we're here, all the needed patch stuff is found, so we can get started
# building openmpi
# Remove the old install directory
if [ -d "$openmpi_instdir" ]; then
echo "Removing old install directory $openmpi_instdir"
rm -rf "$openmpi_instdir"
if [ -d "$openmpi_instdir" ]; then
echo "Error: Unable to remove old installation directory $openmpi_instdir."
exit 1
fi
fi
echo "Entering $srcdir"
if [ ! -d "$srcdir" ]; then
echo "Error: $srcdir does not exist"
exit 1
fi
cd "$srcdir"
# Remove old openmpi source
if [ -d "$openmpi_name" ]; then
echo "Removing old openmpi source directory $openmpi_name"
rm -r "${srcdir}/${openmpi_name}"
if [ -d "$openmpi_name" ]; then
echo "Error: Unable to remove old source directory ${srcdir}/${openmpi_name}"
fi
fi
# Untar the archive
echo "Untarring the $tarball archive"
tar xjf $tarball
check_exit $? "Untar openmpi tarball"
# Change directory to the open mpi source directory
echo "Entering ${srcdir}/${openmpi_name}"
if [ ! -d "${srcdir}/${openmpi_name}" ]; then
echo "Error: ${srcdir}/${openmpi_name} directory not found"
exit 1
fi
cd ${srcdir}/${openmpi_name}
# Patch Open MPI
echo "Patching Open MPI..."
patch -p1 < ${plfs_srcdir}/mpi_adio/${PATCH_FILE}
check_exit $? "Using ${plfs_srcdir}/${PATCH_FILE}"
patch -p1 < ${ad_plfs_patch_file}
check_exit $? "Using ${ad_plfs_patch_file}"
# Run autogen
# There's actually two autogen scripts: autogen.sh and autogen.pl. The perl
# version is newer and replaced autogen.sh, but autogen.sh as a link to
# autogen.pl was created to keep some backwards compatibility. In the release
# tarballs, the link becomes an actual file so autogen.sh is an exact copy of
# autogen.pl Someday, autogen.sh will be removed altogether. So, we have to
# deal with three scenarios: only autogen.sh available (<=1.6 series); both
# autogen.sh and autogen.pl available (1.7 and 1.8 series); and only
# autogen.pl available (future).
if [ -x ./autogen.sh ]; then
echo "Running ./autogen.sh"
./autogen.sh
else
echo "Running ./autogen.pl"
./autogen.pl
fi
check_exit $? "Autogen process"
# Get the platform file from the plfs source directory, substituting the right
# paths for the regression environment.
echo "Generating platform file for openmpi compilation"
#catline="cat ${platform_file} > ./platform_file"
sedline="sed 's|REPLACE_PLFS_LDFLAGS|${rs_plfs_ldflags}|g;s|REPLACE_PLFS_CFLAGS|${rs_plfs_cflags}|g' \
${platform_file} > ./platform_file"
eval $sedline
check_exit $? "Generating platform file for openmpi"
# Run configure
echo "Running configure script with --prefix=$openmpi_instdir"
./configure --prefix=$openmpi_instdir --with-platform=./platform_file --disable-silent-rules
check_exit $? "Configure process"
# Run make
echo "Running make"
make -j 32
check_exit $? "Make process"
# Run make install
echo "Running make install"
make install
check_exit $? "Make install process"
echo "Building and installing openmpi completed."