Skip to content

Commit

Permalink
[PETSc] Upgrades petsc to 3.15.2 and enables multiple precision, scal…
Browse files Browse the repository at this point in the history
…ar, and int types (JuliaPackaging#3249)

* [PETSc] Update PETSc version

* [PETSc] Add `-fno-stack-protector` flag

* [PETSc] Fix MPI library path

* [PETSc] Require GCC 9 for libgfortran5

The linker that comes with GCC 8 emits a warning on `{i686,x86_64}-linux-musl` and that makes configuration script fail.

* [PETSc] Add build with multiple types

 - Real and Complex
 - Int32 and Int64
 - Float64 and Float32

* [PETSc] Delete duplicated PETSc.pc file

Co-authored-by: Mosè Giordano <giordano@users.noreply.github.com>
  • Loading branch information
2 people authored and simeonschaub committed Feb 23, 2022
1 parent c44ca5a commit 468695e
Show file tree
Hide file tree
Showing 2 changed files with 81 additions and 46 deletions.
125 changes: 80 additions & 45 deletions P/PETSc/build_tarballs.jl
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
using BinaryBuilder

name = "PETSc"
version = v"3.13.4"
version = v"3.15.2"

# 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://www.mcs.anl.gov/petsc/mirror/release-snapshots/petsc-3.13.4.tar.gz",
"2cf8abd70ec332510b17bff7dc8a465bf1eb053e17e2a0451a4a0256385657d8"),
ArchiveSource("https://www.mcs.anl.gov/petsc/mirror/release-snapshots/petsc-3.15.2.tar.gz",
"3b10c19c69fc42e01a38132668724a01f1da56f5c353105cd28f1120cc9041d8"),
DirectorySource("./bundled"),
]

# Bash recipe for building across all platforms
script = raw"""
cd $WORKSPACE/srcdir/petsc*
includedir="${prefix}/include"
atomic_patch -p1 $WORKSPACE/srcdir/patches/petsc_name_mangle.patch
BLAS_LAPACK_LIB="${libdir}/libopenblas.${dlext}"
Expand All @@ -23,60 +22,96 @@ if [[ "${target}" == *-mingw* ]]; then
#atomic_patch -p1 $WORKSPACE/srcdir/patches/fix-header-cases.patch
MPI_LIBS="${libdir}/msmpi.${dlext}"
else
MPI_LIBS="[${libdir}/libmpi.${dlext},libmpifort.${dlext}]"
MPI_LIBS="[${libdir}/libmpifort.${dlext},${libdir}/libmpi.${dlext}]"
fi
./configure --prefix=${prefix} \
CC=${CC} \
FC=${FC} \
CXX=${CXX} \
COPTFLAGS='-O3' \
CXXOPTFLAGS='-O3' \
FOPTFLAGS='-O3' \
--with-64-bit-indices=0 \
--with-debugging=0 \
--with-batch \
--PETSC_ARCH=$target \
--with-blaslapack-lib=$BLAS_LAPACK_LIB \
--with-blaslapack-suffix="" \
--known-64-bit-blas-indices=0 \
--with-mpi-lib="${MPI_LIBS}" \
--known-mpi-int64_t=0 \
--with-mpi-include="${includedir}" \
--with-sowing=0
build_petsc()
{
if [[ "${target}" == *-mingw* ]]; then
export CPPFLAGS="-Dpetsc_EXPORTS"
elif [[ "${target}" == powerpc64le-* ]]; then
export CFLAGS="-fPIC"
export FFLAGS="-fPIC"
fi
if [[ "${3}" == "Int64" ]]; then
USE_INT64=1
else
USE_INT64=0
fi
make -j${nproc} \
PETSC_DIR="${PWD}" \
PETSC_ARCH="${target}" \
CPPFLAGS="${CPPFLAGS}" \
CFLAGS="${CFLAGS}" \
FFLAGS="${FFLAGS}" \
DEST_DIR="${prefix}" \
all
./configure --prefix=${prefix} \
CC=${CC} \
FC=${FC} \
CXX=${CXX} \
COPTFLAGS='-O3' \
CXXOPTFLAGS='-O3' \
CFLAGS='-fno-stack-protector' \
FOPTFLAGS='-O3' \
--with-64-bit-indices=${USE_INT64} \
--with-debugging=0 \
--with-batch \
--PETSC_ARCH=${target}_${1}_${2}_${3} \
--with-blaslapack-lib=$BLAS_LAPACK_LIB \
--with-blaslapack-suffix="" \
--known-64-bit-blas-indices=0 \
--with-mpi-lib="${MPI_LIBS}" \
--known-mpi-int64_t=0 \
--with-mpi-include="${includedir}" \
--with-sowing=0 \
--with-precision=${1} \
--with-scalar-type=${2}
make PETSC_DIR=$PWD PETSC_ARCH=$target DEST_DIR=$prefix install
if [[ "${target}" == *-mingw* ]]; then
export CPPFLAGS="-Dpetsc_EXPORTS"
elif [[ "${target}" == powerpc64le-* ]]; then
export CFLAGS="-fPIC"
export FFLAGS="-fPIC"
fi
if [[ "${target}" == *-mingw* ]]; then
# Move library to ${libdir} on Windows,
# changing the extension from so to dll.
mv ${prefix}/lib/libpetsc.so.*.*.* "${libdir}/libpetsc.${dlext}"
make -j${nproc} \
PETSC_DIR="${PWD}" \
PETSC_ARCH="${target}_${1}_${2}_${3}" \
CPPFLAGS="${CPPFLAGS}" \
CFLAGS="${CFLAGS}" \
FFLAGS="${FFLAGS}" \
DEST_DIR="${prefix}" \
all
make PETSC_DIR=$PWD PETSC_ARCH=${target}_${1}_${2}_${3} DEST_DIR=$prefix install
# add suffix to library name
if [[ "${target}" == *-mingw* ]]; then
# changing the extension from so to dll.
mv ${prefix}/lib/libpetsc.so.*.*.* "${libdir}/libpetsc_${1}_${2}_${3}.${dlext}"
elif [[ "${target}" == *-apple* ]]; then
mv ${prefix}/lib/libpetsc.*.*.*.${dlext} "${libdir}/libpetsc_${1}_${2}_${3}.${dlext}"
else
mv ${prefix}/lib/libpetsc.${dlext}.*.*.* "${libdir}/libpetsc_${1}_${2}_${3}.${dlext}"
fi
# Remove useless links
rm ${prefix}/lib/libpetsc.*
fi
# Remove duplicated file
rm ${prefix}/lib/pkgconfig/PETSc.pc
}
build_petsc double real Int32
build_petsc single real Int32
build_petsc double complex Int32
build_petsc single complex Int32
build_petsc double real Int64
build_petsc single real Int64
build_petsc double complex Int64
build_petsc single complex Int64
"""

# We attempt to build for all defined platforms
platforms = expand_gfortran_versions(supported_platforms(exclude=[Platform("i686", "windows")]))

products = [
LibraryProduct("libpetsc", :libpetsc),
LibraryProduct("libpetsc_double_real_Int32", :libpetsc), # Current default build
LibraryProduct("libpetsc_double_real_Int64", :libpetsc_Float64_Real_Int64),
LibraryProduct("libpetsc_single_real_Int64", :libpetsc_Float32_Real_Int64),
LibraryProduct("libpetsc_double_complex_Int64", :libpetsc_Float64_Complex_Int64),
LibraryProduct("libpetsc_single_complex_Int64", :libpetsc_Float32_Complex_Int64),
LibraryProduct("libpetsc_double_real_Int32", :libpetsc_Float64_Real_Int32),
LibraryProduct("libpetsc_single_real_Int32", :libpetsc_Float32_Real_Int32),
LibraryProduct("libpetsc_double_complex_Int32", :libpetsc_Float64_Complex_Int32),
LibraryProduct("libpetsc_single_complex_Int32", :libpetsc_Float32_Complex_Int32),
]

dependencies = [
Expand All @@ -87,4 +122,4 @@ dependencies = [
]

# Build the tarballs.
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies; preferred_gcc_version = v"6")
build_tarballs(ARGS, name, version, sources, script, platforms, products, dependencies; preferred_gcc_version = v"9")
2 changes: 1 addition & 1 deletion P/PETSc/bundled/patches/petsc_name_mangle.patch
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ diff --git a/config/BuildSystem/config/packages/BlasLapack.py b/config/BuildSyst
index bbae50c096..9ad0a994eb 100644
--- a/config/BuildSystem/config/packages/BlasLapack.py
+++ b/config/BuildSystem/config/packages/BlasLapack.py
@@ -118,7 +118,8 @@ class Configure(config.package.Package):
@@ -121,7 +121,8 @@ class Configure(config.package.Package):
foundLapack = 0
self.f2c = 0
# allow a user-specified suffix to be appended to BLAS/LAPACK symbols
Expand Down

0 comments on commit 468695e

Please sign in to comment.