Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PETSc] Attempt to rebuild with good include files (and don't rename libpetsc) #3801

Merged
merged 20 commits into from
Mar 9, 2022
Merged
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 19 additions & 36 deletions P/PETSc/build_tarballs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ 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.15.2.tar.gz",
ArchiveSource("https://www.mcs.anl.gov/petsc/mirror/release-snapshots/petsc-$(version).tar.gz",
"3b10c19c69fc42e01a38132668724a01f1da56f5c353105cd28f1120cc9041d8"),
DirectorySource("./bundled"),
]
Expand All @@ -24,7 +24,7 @@ if [[ "${target}" == *-mingw* ]]; then
else
MPI_LIBS="[${libdir}/libmpifort.${dlext},${libdir}/libmpi.${dlext}]"
fi

mkdir $libdir/petsc
build_petsc()
{

Expand All @@ -33,19 +33,19 @@ build_petsc()
else
USE_INT64=0
fi

./configure --prefix=${prefix} \
mkdir $libdir/petsc/${1}_${2}_${3}
./configure --prefix=${libdir}/petsc/${1}_${2}_${3} \
CC=${CC} \
FC=${FC} \
CXX=${CXX} \
COPTFLAGS='-O3' \
CXXOPTFLAGS='-O3' \
CFLAGS='-fno-stack-protector' \
LDFLAGS="-L${libdir}" \
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 \
Expand All @@ -54,7 +54,8 @@ build_petsc()
--with-mpi-include="${includedir}" \
--with-sowing=0 \
--with-precision=${1} \
--with-scalar-type=${2}
--with-scalar-type=${2} \
--PETSC_ARCH=${target}_${1}_${2}_${3}

if [[ "${target}" == *-mingw* ]]; then
export CPPFLAGS="-Dpetsc_EXPORTS"
Expand All @@ -64,29 +65,10 @@ build_petsc()
fi

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.*
# Remove duplicated file
rm ${prefix}/lib/pkgconfig/PETSc.pc
FFLAGS="${FFLAGS}"
make install
}

build_petsc double real Int32
Expand All @@ -103,15 +85,16 @@ build_petsc single complex Int64
platforms = expand_gfortran_versions(supported_platforms(exclude=[Platform("i686", "windows")]))

products = [
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),
# Current default build, equivalent to Float64_Real_Int32
LibraryProduct("libpetsc", :libpetsc, "\$libdir/petsc/double_real_Int32/lib")
LibraryProduct("libpetsc", :libpetsc_Float64_Real_Int32, "\$libdir/petsc/double_real_Int32/lib")
LibraryProduct("libpetsc", :libpetsc_Float64_Real_Int64, "\$libdir/petsc/double_real_Int64/lib")
LibraryProduct("libpetsc", :libpetsc_Float32_Real_Int64, "\$libdir/petsc/single_real_Int64/lib")
LibraryProduct("libpetsc", :libpetsc_Float64_Complex_Int64, "\$libdir/petsc/double_complex_Int64/lib")
LibraryProduct("libpetsc", :libpetsc_Float32_Complex_Int64, "\$libdir/petsc/single_complex_Int64/lib")
LibraryProduct("libpetsc", :libpetsc_Float32_Real_Int32, "\$libdir/petsc/single_real_Int32/lib")
LibraryProduct("libpetsc", :libpetsc_Float64_Complex_Int32, "\$libdir/petsc/double_complex_Int32/lib")
LibraryProduct("libpetsc", :libpetsc_Float32_Complex_Int32, "\$libdir/petsc/single_complex_Int32/lib")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Now that I think of this, all these libraries are called libpetsc, right? If so, there is no way this is going to work, we can't dlopen multiple libraries with the same name, the first one will win.

Either we don't dlopen the libraries and users will have to take care of that, or I don't know what you want to do.

Copy link
Contributor Author

@rayegun rayegun Oct 27, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't realize PETSC.jl will open multiple at once, that is problematic.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to dlopen all of them at the same time, they must not have all the same name, it can't possibly work because that's how dlopen works (this is in general, not Julia-specific).

If you want to open only one library, we can set dont_dlopen=true for all of them, and the consumer will need to manually dlopen the single desired lib.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to use the package with custom builds of the PETSc library, this can be done by specifying the environment variable JULIA_PETSC_LIBRARY. This is a colon separated list of paths to custom builds of PETSc; the reason for using multiple builds is to enable single, double, and complex numbers in the same julia session. These should be built against the same version of MPI as used with MPI.jl

How is PETSc.jl doing this then? Do they require that you rename libpetsc.so for the custom builds?

]

dependencies = [
Expand Down