-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_tarballs_noMPI_downloadBLAS.jl
451 lines (392 loc) · 17 KB
/
build_tarballs_noMPI_downloadBLAS.jl
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
using BinaryBuilder
using Base.BinaryPlatforms
using Pkg
const YGGDRASIL_DIR = "../.."
include(joinpath(YGGDRASIL_DIR, "platforms", "mpi.jl"))
name = "PETSc"
version = v"3.20.0"
petsc_version = v"3.20.0"
MUMPS_COMPAT_VERSION = "5.6.2"
SUITESPARSE_COMPAT_VERSION = "7.2.1"
SUPERLUDIST_COMPAT_VERSION = "8.2.1"
HDF5_COMPAT_VERSION="1.14.2"
TRIANGLE_COMPAT_VERSION="1.6.2"
TETGEN_COMPAT_VERSION="1.5.3"
SCALAPACK32_COMPAT_VERSION="2.2.1"
METIS_COMPAT_VERSION="5.1.2"
SCOTCH_COMPAT_VERSION="7.0.4"
PARMETIS_COMPAT_VERSION="4.0.6"
OpenMPI_version="4.1.6, 5.0" # adding 4.1.6 to ensure that 32bit builds still work
MPItrampoline_version="5.2.1"
# Collection of sources required to build PETSc. Avoid using the git repository, it will
# require building SOWING which fails in all non-linux platforms.
sources = [
ArchiveSource("https://web.cels.anl.gov/projects/petsc/download/release-snapshots/petsc-$(petsc_version).tar.gz",
"c152ccb12cb2353369d27a65470d4044a0c67e0b69814368249976f5bb232bd4"),
DirectorySource("./bundled"),
]
# Bash recipe for building across all platforms
script = raw"""
cd $WORKSPACE/srcdir/petsc*
#atomic_patch -p1 $WORKSPACE/srcdir/patches/petsc_name_mangle.patch
if [[ "${target}" == *-mingw* ]]; then
MPI_LIBS="${libdir}/msmpi.${dlext}"
else
if grep -q MPICH_NAME $prefix/include/mpi.h; then
MPI_FFLAGS=
MPI_LIBS="[${libdir}/libmpifort.${dlext},${libdir}/libmpi.${dlext}]"
elif grep -q MPItrampoline $prefix/include/mpi.h; then
MPI_FFLAGS="-fcray-pointer"
MPI_LIBS="[${libdir}/libmpitrampoline.${dlext}]"
elif grep -q OMPI_MAJOR_VERSION $prefix/include/mpi.h; then
MPI_FFLAGS=
MPI_LIBS="[${libdir}/libmpi_usempif08.${dlext},${libdir}/libmpi_usempi_ignore_tkr.${dlext},${libdir}/libmpi_mpifh.${dlext},${libdir}/libmpi.${dlext}]"
else
MPI_FFLAGS=
MPI_LIBS=
fi
fi
#atomic_patch -p1 $WORKSPACE/srcdir/patches/mingw-version.patch
atomic_patch -p1 $WORKSPACE/srcdir/patches/mpi-constants.patch
atomic_patch -p1 $WORKSPACE/srcdir/patches/sosuffix.patch
mkdir $libdir/petsc
build_petsc()
{
# Compile a debug version?
DEBUG_FLAG=0
PETSC_CONFIG="${1}_${2}_${3}"
if [[ "${4}" == "deb" ]]; then
PETSC_CONFIG="${1}_${2}_${3}_deb"
DEBUG_FLAG=1
fi
if [[ "${3}" == "Int64" ]]; then
USE_INT64=1
else
USE_INT64=0
fi
# A SuperLU_DIST build is (now) available on most systems, but only works for double precision
USE_SUPERLU_DIST=0
SUPERLU_DIST_LIB=""
SUPERLU_DIST_INCLUDE=""
if [ -f "${libdir}/libsuperlu_dist_Int64.${dlext}" ] && [ "${1}" == "double" ]; then
USE_SUPERLU_DIST=1
SUPERLU_DIST_LIB="--with-superlu_dist-lib=${libdir}/libsuperlu_dist_${3}.${dlext}"
#SUPERLU_DIST_LIB="--with-superlu_dist-lib=${libdir}/libsuperlu_dist_Int32.${dlext}"
SUPERLU_DIST_INCLUDE="--with-superlu_dist-include=${includedir}"
# on linux, it doesn't find some of these libs, so lets copy them to
cp ${libdir}/metis/metis_Int32_Real64/lib/* ${libdir}
cp ${libdir}/metis/metis_Int64_Real32/lib/* ${libdir}
fi
USE_SUITESPARSE=0
if [ "${1}" == "double" ]; then
USE_SUITESPARSE=1
fi
Machine_name=$(uname -m)
if [ "${3}" == "Int64" ]; then
case "${Machine_name}" in
"armv7l")
USE_SUITESPARSE=0
;;
"armv6l")
USE_SUITESPARSE=0
;;
"i686")
USE_SUITESPARSE=0
;;
esac
fi
# See if we can install MUMPS
USE_MUMPS=0
if [ -f "${libdir}/libdmumpspar.${dlext}" ] && [ "${1}" == "double" ] && [ "${2}" == "real" ]; then
USE_MUMPS=1
MUMPS_LIB="--with-mumps-lib=${libdir}/libdmumpspar.${dlext} --with-scalapack-lib=${libdir}/libscalapack32.${dlext}"
MUMPS_INCLUDE="--with-mumps-include=${includedir} --with-scalapack-include=${includedir}"
else
MUMPS_LIB=""
MUMPS_INCLUDE=""
fi
LIBFLAGS="-L${libdir}"
if [[ "${target}" == *-mingw* ]]; then
LIBFLAGS="-L${libdir} -lssp -lmsmpi"
fi
# BLAS/LAPACK
if [[ "${target}" == *-mingw* ]]; then
BLAS_NAME=blastrampoline-5
else
BLAS_NAME=blastrampoline
fi
if [[ "${target}" == aarch64-apple-* ]]; then
LIBFLAGS="-L${libdir}"
# Linking requires the function `__divdc3`, which is implemented in
# `libclang_rt.osx.a` from LLVM compiler-rt.
CLINK_FLAGS="-L${libdir}/darwin -lclang_rt.osx"
else
CLINK_FLAGS=""
fi
#BLAS_LAPACK_LIB="${libdir}/lib${BLAS_NAME}.${dlext}"
BLAS_LAPACK_LIB="${libdir}/libopenblas.${dlext}"
if [ ${DEBUG_FLAG} == 1 ]; then
_COPTFLAGS='-O0 -g'
_CXXOPTFLAGS='-O0 -g'
_FOPTFLAGS='-O0'
else
_COPTFLAGS='-O3 -g'
_CXXOPTFLAGS='-O3 -g'
_FOPTFLAGS='-O3'
fi
# See if we can install HDF5
USE_HDF5=0
if [ -f "${libdir}/libhdf5.${dlext}" ]; then
USE_HDF5=1
fi
# Triangle:
USE_TRIANGLE=0
if [ -f "${libdir}/libtriangle.${dlext}" ]; then
USE_TRIANGLE=1
TRIANGLE_LIB="--with-triangle-lib=${libdir}/libtriangle.${dlext}"
TRIANGLE_INCLUDE="--with-triangle-include=${includedir}"
# Triangle_jll does not ship triangle.h, so we do (note that we use a PETSc-specific version of this)
cp ../headers/triangle.h $includedir
else
TRIANGLE_LIB=""
TRIANGLE_INCLUDE=""
fi
# See if we can install TetGen
USE_TETGEN=0
if [ -f "${libdir}/libtet.${dlext}" ]; then
USE_TETGEN=1
TETGEN_LIB="--with-ctetgen-lib=${libdir}/libtet.${dlext}"
TETGEN_INCLUDE="--with-ctetgen-include=${includedir}"
cp ../headers/ctetgen.h $includedir
else
TETGEN_LIB=""
TETGEN_INCLUDE=""
fi
echo "1="${1}
echo "2="${2}
echo "3="${3}
echo "4="${4}
echo "USE_INT64"=$USE_INT64
echo "Machine_name="$Machine_name
echo "LIBFLAGS="$LIBFLAGS
echo "target="$target
echo "DEBUG="${DEBUG_FLAG}
echo "COPTFLAGS="${_COPTFLAGS}
echo "BLAS_LAPACK_LIB="$BLAS_LAPACK_LIB
echo "prefix="${libdir}/petsc/${PETSC_CONFIG}
echo "USE_SUPERLU_DIST="$USE_SUPERLU_DIST
echo "USE_SUITESPARSE="$USE_SUITESPARSE
echo "USE_MUMPS="$USE_MUMPS
echo "USE_HDF5="$USE_HDF5
echo "USE_TRIANGLE="$USE_TRIANGLE
echo "USE_TETGEN="$USE_TETGEN
mkdir $libdir/petsc/${PETSC_CONFIG}
# ${TETGEN_LIB} \
# ${TETGEN_INCLUDE} \
#--with-suitesparse=${USE_SUITESPARSE} \
#./configure --prefix=${libdir}/petsc/${PETSC_CONFIG} \
# --CC=${CC} \
# --FC=${FC} \
# --CXX=${CXX} \
# --COPTFLAGS=${_COPTFLAGS} \
# --CXXOPTFLAGS=${_CXXOPTFLAGS} \
# --FOPTFLAGS=${_FOPTFLAGS} \
# --with-blaslapack-lib=${BLAS_LAPACK_LIB} \
# --CFLAGS='-fno-stack-protector ' \
# --FFLAGS="${MPI_FFLAGS}" \
# --LDFLAGS="${LIBFLAGS}" \
# --CC_LINKER_FLAGS="${CLINK_FLAGS}" \
# --with-64-bit-indices=${USE_INT64} \
# --with-debugging=${DEBUG_FLAG} \
# --with-batch \
# --with-mpi-lib="${MPI_LIBS}" \
# --known-mpi-int64_t=0 \
# --with-mpi-include="${includedir}" \
# --with-sowing=0 \
# --with-precision=${1} \
# --with-scalar-type=${2} \
# --with-pthread=0 \
# --PETSC_ARCH=${target}_${PETSC_CONFIG} \
# --with-superlu_dist=${USE_SUPERLU_DIST} \
# ${SUPERLU_DIST_LIB} \
# ${SUPERLU_DIST_INCLUDE} \
# --with-mumps=${USE_MUMPS} \
# ${MUMPS_LIB} \
# ${MUMPS_INCLUDE} \
# --with-hdf5=${USE_HDF5} \
# --with-triangle=${USE_TRIANGLE} \
# --SOSUFFIX=${PETSC_CONFIG} \
# --with-shared-libraries=1 \
# --with-clean=1
#
./configure --prefix=${libdir}/petsc/${PETSC_CONFIG} \
--CC=${CC} \
--FC=${FC} \
--CXX=${CXX} \
--COPTFLAGS=${_COPTFLAGS} \
--CXXOPTFLAGS=${_CXXOPTFLAGS} \
--FOPTFLAGS=${_FOPTFLAGS} \
--download-fblaslapack=1 \
--CFLAGS='-fno-stack-protector ' \
--FFLAGS="${MPI_FFLAGS}" \
--with-64-bit-indices=${USE_INT64} \
--with-debugging=${DEBUG_FLAG} \
--with-batch \
--with-mpi=0 \
--with-precision=${1} \
--with-scalar-type=${2} \
--PETSC_ARCH=${target}_${PETSC_CONFIG} \
--SOSUFFIX=${PETSC_CONFIG} \
--with-shared-libraries=1 \
--with-clean=1
if [[ "${target}" == *-mingw* ]]; then
export CPPFLAGS="-Dpetsc_EXPORTS"
elif [[ "${target}" == powerpc64le-* ]]; then
export CFLAGS="-fPIC"
export FFLAGS="-fPIC"
fi
make -j${nproc} \
CPPFLAGS="${CPPFLAGS}" \
CFLAGS="${CFLAGS}" \
FFLAGS="${FFLAGS}"
make install
# Remove PETSc.pc because petsc.pc also exists, causing conflicts on case insensitive file-systems.
rm ${libdir}/petsc/${PETSC_CONFIG}/lib/pkgconfig/PETSc.pc
# sed -i -e "s/-lpetsc/-lpetsc_${PETSC_CONFIG}/g" "$libdir/petsc/${PETSC_CONFIG}/lib/pkgconfig/petsc.pc"
# cp $libdir/petsc/${PETSC_CONFIG}/lib/pkgconfig/petsc.pc ${prefix}/lib/pkgconfig/petsc_${PETSC_CONFIG}.pc
if [ "${1}" == "double" ] && [ "${2}" == "real" ] && [ "${3}" == "Int64" ] && [ "${4}" == "opt" ]; then
# Compile two examples (to allow testing the installation).
# This can later be run with:
# julia> run(`$(PETSc_jll.ex42()) -stokes_ksp_monitor -log_view` )
workdir=${libdir}/petsc/${PETSC_CONFIG}/share/petsc/examples/src/ksp/ksp/tutorials/
make --directory=${workdir} PETSC_DIR=${libdir}/petsc/${PETSC_CONFIG} PETSC_ARCH=${target}_${PETSC_CONFIG} ex42
file=${workdir}/ex42
if [[ "${target}" == *-mingw* ]]; then
if [[ -f "$file" ]]; then
mv $file ${file}${exeext}
fi
fi
install -Dvm 755 ${workdir}/ex42${exeext} "${bindir}/ex42${exeext}"
# This is a staggered grid Stokes example, as discussed in https://joss.theoj.org/papers/10.21105/joss.04531
# This can later be run with:
# julia> run(`$(PETSc_jll.ex4()) -ksp_monitor -log_view` )
workdir=${libdir}/petsc/${PETSC_CONFIG}/share/petsc/examples/src/dm/impls/stag/tutorials/
make --directory=$workdir PETSC_DIR=${libdir}/petsc/${PETSC_CONFIG} PETSC_ARCH=${target}_${PETSC_CONFIG} ex4
file=${workdir}/ex4
if [[ "${target}" == *-mingw* ]]; then
if [[ -f "$file" ]]; then
mv $file ${file}${exeext}
fi
fi
install -Dvm 755 ${workdir}/ex4${exeext} "${bindir}/ex4${exeext}"
# This is a DMPLEX 2D/3D finite element Stokes example, as discussed https://petsc.org/main/tutorials/physics/guide_to_stokes/
workdir=${libdir}/petsc/${PETSC_CONFIG}/share/petsc/examples/src/snes/tutorials/
make --directory=$workdir PETSC_DIR=${libdir}/petsc/${PETSC_CONFIG} PETSC_ARCH=${target}_${PETSC_CONFIG} ex62
file=${workdir}/ex62
if [[ "${target}" == *-mingw* ]]; then
if [[ -f "$file" ]]; then
mv $file ${file}${exeext}
fi
fi
install -Dvm 755 ${workdir}/ex62${exeext} "${bindir}/ex62${exeext}"
# this is the example that PETSc uses to test the correct installation
workdir=${libdir}/petsc/${PETSC_CONFIG}/share/petsc/examples/src/snes/tutorials/
make --directory=$workdir PETSC_DIR=${libdir}/petsc/${PETSC_CONFIG} PETSC_ARCH=${target}_${PETSC_CONFIG} ex19
file=${workdir}/ex19
if [[ "${target}" == *-mingw* ]]; then
if [[ -f "$file" ]]; then
mv $file ${file}${exeext}
fi
fi
install -Dvm 755 ${workdir}/ex19${exeext} "${bindir}/ex19${exeext}"
fi
if [ "${1}" == "double" ] && [ "${2}" == "real" ] && [ "${3}" == "Int64" ] && [ "${4}" == "deb" ]; then
# this is the example that PETSc uses to test the correct installation
# We compile it witn debug flags (helpful to catch issues)
workdir=${libdir}/petsc/${PETSC_CONFIG}/share/petsc/examples/src/snes/tutorials/
make --directory=$workdir PETSC_DIR=${libdir}/petsc/${PETSC_CONFIG} PETSC_ARCH=${target}_${PETSC_CONFIG} ex19
file=${workdir}/ex19
if [[ "${target}" == *-mingw* ]]; then
if [[ -f "$file" ]]; then
mv $file ${file}${exeext}
fi
fi
mv ${file}${exeext} ${file}_int64_deb${exeext}
install -Dvm 755 ${workdir}/ex19_int64_deb${exeext} "${bindir}/ex19_int64_deb${exeext}"
fi
# we don't particularly care about the examples
rm -r ${libdir}/petsc/${PETSC_CONFIG}/share/petsc/examples
}
build_petsc double real Int64 opt
build_petsc double real Int64 deb # compile at least one debug version
#build_petsc double real Int32 opt
#build_petsc single real Int32 opt
#build_petsc double complex Int32 opt
#build_petsc single complex Int32 opt
#build_petsc single real Int64 opt
#build_petsc double complex Int64 opt
#build_petsc single complex Int64 opt
"""
augment_platform_block = """
using Base.BinaryPlatforms
$(MPI.augment)
augment_platform!(platform::Platform) = augment_mpi!(platform)
"""
# We attempt to build for all defined platforms
platforms = expand_gfortran_versions(supported_platforms(exclude=[Platform("i686", "windows"),
Platform("i686","linux"; libc="musl"),
Platform("aarch64","linux"; libc="musl")]))
platforms, platform_dependencies = MPI.augment_platforms(platforms;
MPItrampoline_compat=MPItrampoline_version,
OpenMPI_compat=OpenMPI_version)
# Avoid platforms where the MPI implementation isn't supported
# OpenMPI
platforms = filter(p -> !(p["mpi"] == "openmpi" && arch(p) == "armv6l" && libc(p) == "glibc"), platforms)
# MPItrampoline
platforms = filter(p -> !(p["mpi"] == "mpitrampoline" && libc(p) == "musl"), platforms)
platforms = filter(p -> !(p["mpi"] == "mpitrampoline" && Sys.isfreebsd(p)), platforms)
products = [
ExecutableProduct("ex4", :ex4)
ExecutableProduct("ex42", :ex42)
ExecutableProduct("ex62", :ex62)
ExecutableProduct("ex19", :ex19)
ExecutableProduct("ex19_int64_deb", :ex19_int64_deb)
# Current default build, equivalent to Float64_Real_Int32
LibraryProduct("libpetsc_double_real_Int64", :libpetsc, "\$libdir/petsc/double_real_Int64/lib")
LibraryProduct("libpetsc_double_real_Int64", :libpetsc_Float64_Real_Int64, "\$libdir/petsc/double_real_Int64/lib")
LibraryProduct("libpetsc_double_real_Int64_deb", :libpetsc_Float64_Real_Int64_deb, "\$libdir/petsc/double_real_Int64_deb/lib")
#LibraryProduct("libpetsc_double_real_Int32", :libpetsc_Float64_Real_Int32, "\$libdir/petsc/double_real_Int32/lib")
#LibraryProduct("libpetsc_single_real_Int32", :libpetsc_Float32_Real_Int32, "\$libdir/petsc/single_real_Int32/lib")
#LibraryProduct("libpetsc_double_complex_Int32", :libpetsc_Float64_Complex_Int32, "\$libdir/petsc/double_complex_Int32/lib")
#LibraryProduct("libpetsc_single_complex_Int32", :libpetsc_Float32_Complex_Int32, "\$libdir/petsc/single_complex_Int32/lib")
#LibraryProduct("libpetsc_single_real_Int64", :libpetsc_Float32_Real_Int64, "\$libdir/petsc/single_real_Int64/lib")
#LibraryProduct("libpetsc_double_complex_Int64", :libpetsc_Float64_Complex_Int64, "\$libdir/petsc/double_complex_Int64/lib")
#LibraryProduct("libpetsc_single_complex_Int64", :libpetsc_Float32_Complex_Int64, "\$libdir/petsc/single_complex_Int64/lib")
]
dependencies = [
#Dependency("OpenBLAS32_jll"),
Dependency("CompilerSupportLibraries_jll"),
#Dependency("SuperLU_DIST_jll"; compat=SUPERLUDIST_COMPAT_VERSION),
#Dependency(PackageSpec(; name = "SuperLU_DIST_jll", uuid = "9a1356b0-3c82-5da3-b77c-7c198e8bd7ab", url = "https://github.com/boriskaus/SuperLU_DIST_jll.jl")),
#Dependency("SuiteSparse_jll"; compat=SUITESPARSE_COMPAT_VERSION),
#Dependency("MUMPS_jll"; compat=MUMPS_COMPAT_VERSION),
#Dependency("HDF5_jll"; compat=HDF5_COMPAT_VERSION),
#Dependency("Triangle_jll"; compat=TRIANGLE_COMPAT_VERSION),
#Dependency("TetGen_jll"; compat=TETGEN_COMPAT_VERSION),
#Dependency("libblastrampoline_jll"),
BuildDependency("LLVMCompilerRT_jll"; platforms=[Platform("aarch64", "macos")]),
#Dependency("SCALAPACK32_jll"),
#Dependency("METIS_jll"),
#Dependency("SCOTCH_jll"),
#Dependency("PARMETIS_jll"),
]
append!(dependencies, platform_dependencies)
# Don't look for `mpiwrapper.so` when BinaryBuilder examines and
# `dlopen`s the shared libraries. (MPItrampoline will skip its
# automatic initialization.)
ENV["MPITRAMPOLINE_DELAY_INIT"] = "1"
# Build the tarballs.
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies;
augment_platform_block,
julia_compat="1.6",
preferred_gcc_version=v"5")